Compare commits
No commits in common. "9c98735db7dbcade8cf6b1d60d1a3a70eee0e73e" and "2273c91f2bc6905c837705663b368dbcbada8cb8" have entirely different histories.
9c98735db7
...
2273c91f2b
24 changed files with 924 additions and 1991 deletions
|
@ -4,3 +4,4 @@ APP_SECRET='$ecretf0rt3st'
|
|||
SYMFONY_DEPRECATIONS_HELPER=999999
|
||||
PANTHER_APP_ENV=panther
|
||||
PANTHER_ERROR_SCREENSHOT_DIR=./var/error-screenshots
|
||||
DATABASE_URL="sqlite:///%kernel.project_dir%/var/test-data.db"
|
||||
|
|
19
.gitignore
vendored
19
.gitignore
vendored
|
@ -1,3 +1,4 @@
|
|||
|
||||
###> symfony/framework-bundle ###
|
||||
/.env.local
|
||||
/.env.local.php
|
||||
|
@ -7,13 +8,17 @@
|
|||
/var/
|
||||
/vendor/
|
||||
###< symfony/framework-bundle ###
|
||||
|
||||
###> symfony/phpunit-bridge ###
|
||||
.phpunit.result.cache
|
||||
/phpunit.xml
|
||||
###< symfony/phpunit-bridge ###
|
||||
|
||||
###> phpunit/phpunit ###
|
||||
/phpunit.xml
|
||||
.phpunit.result.cache
|
||||
###< phpunit/phpunit ###
|
||||
|
||||
.idea/
|
||||
/deploy/var/
|
||||
/deploy/app/
|
||||
|
||||
###> phpunit/phpunit ###
|
||||
.phpunit.result.cache
|
||||
.phpunit.cache
|
||||
###< phpunit/phpunit ###
|
||||
|
||||
.DS_Store
|
||||
|
|
23
bin/phpunit
Executable file
23
bin/phpunit
Executable file
|
@ -0,0 +1,23 @@
|
|||
#!/usr/bin/env php
|
||||
<?php
|
||||
|
||||
if (!ini_get('date.timezone')) {
|
||||
ini_set('date.timezone', 'UTC');
|
||||
}
|
||||
|
||||
if (is_file(dirname(__DIR__).'/vendor/phpunit/phpunit/phpunit')) {
|
||||
if (PHP_VERSION_ID >= 80000) {
|
||||
require dirname(__DIR__).'/vendor/phpunit/phpunit/phpunit';
|
||||
} else {
|
||||
define('PHPUNIT_COMPOSER_INSTALL', dirname(__DIR__).'/vendor/autoload.php');
|
||||
require PHPUNIT_COMPOSER_INSTALL;
|
||||
PHPUnit\TextUI\Command::main();
|
||||
}
|
||||
} else {
|
||||
if (!is_file(dirname(__DIR__).'/vendor/symfony/phpunit-bridge/bin/simple-phpunit.php')) {
|
||||
echo "Unable to find the `simple-phpunit.php` script in `vendor/symfony/phpunit-bridge/bin/`.\n";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
require dirname(__DIR__).'/vendor/symfony/phpunit-bridge/bin/simple-phpunit.php';
|
||||
}
|
|
@ -27,21 +27,21 @@
|
|||
"require-dev": {
|
||||
"doctrine/doctrine-fixtures-bundle": "^4.0",
|
||||
"lubiana/code-quality": "^1.7.2",
|
||||
"pestphp/pest": "^3.6",
|
||||
"phpunit/phpunit": "^9.6.20",
|
||||
"symfony/browser-kit": "7.2.*",
|
||||
"symfony/css-selector": "7.2.*",
|
||||
"symfony/maker-bundle": "^1.60",
|
||||
"symfony/phpunit-bridge": "7.2.*",
|
||||
"symfony/stopwatch": "7.2.*",
|
||||
"symfony/web-profiler-bundle": "7.2.*",
|
||||
"symplify/config-transformer": "^12.3.4"
|
||||
},
|
||||
"config": {
|
||||
"allow-plugins": {
|
||||
"dealerdirect/phpcodesniffer-composer-installer": true,
|
||||
"pestphp/pest-plugin": true,
|
||||
"php-http/discovery": true,
|
||||
"symfony/flex": true,
|
||||
"symfony/runtime": true
|
||||
"symfony/runtime": true,
|
||||
"dealerdirect/phpcodesniffer-composer-installer": true
|
||||
},
|
||||
"sort-packages": true,
|
||||
"platform": {
|
||||
|
@ -85,7 +85,7 @@
|
|||
"rector",
|
||||
"ecs --fix || ecs --fix"
|
||||
],
|
||||
"test": "pest"
|
||||
"test": "bin/phpunit"
|
||||
},
|
||||
"conflict": {
|
||||
"symfony/symfony": "*"
|
||||
|
|
1999
composer.lock
generated
1999
composer.lock
generated
File diff suppressed because it is too large
Load diff
20
infection.json5
Normal file
20
infection.json5
Normal file
|
@ -0,0 +1,20 @@
|
|||
{
|
||||
"$schema": "vendor/infection/infection/resources/schema.json",
|
||||
"source": {
|
||||
"directories": [
|
||||
"src"
|
||||
]
|
||||
},
|
||||
"timeout": 30,
|
||||
"logs": {
|
||||
"text": "var/log/infection.txt",
|
||||
"summary": "var/log/summary.log",
|
||||
},
|
||||
"mutators": {
|
||||
"@default": true,
|
||||
"global-ignore": [
|
||||
"App\\Service\\Favicon::__toString",
|
||||
"ORM\\Column.*"
|
||||
]
|
||||
}
|
||||
}
|
38
phpunit.xml
38
phpunit.xml
|
@ -1,38 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
|
||||
bootstrap="tests/bootstrap.php"
|
||||
cacheDirectory=".phpunit.cache"
|
||||
executionOrder="depends,defects"
|
||||
shortenArraysForExportThreshold="10"
|
||||
requireCoverageMetadata="false"
|
||||
beStrictAboutCoverageMetadata="true"
|
||||
beStrictAboutOutputDuringTests="true"
|
||||
displayDetailsOnPhpunitDeprecations="true"
|
||||
failOnPhpunitDeprecation="true"
|
||||
failOnRisky="true"
|
||||
failOnWarning="true">
|
||||
<testsuites>
|
||||
<testsuite name="default">
|
||||
<directory>tests/Feature</directory>
|
||||
<directory>tests/Unit</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
|
||||
<source ignoreIndirectDeprecations="true" restrictNotices="true" restrictWarnings="true">
|
||||
<include>
|
||||
<directory>src</directory>
|
||||
</include>
|
||||
<exclude>
|
||||
<file>src/Kernel.php</file>
|
||||
<file>src/Service/Favicon.php</file>
|
||||
</exclude>
|
||||
</source>
|
||||
<php>
|
||||
<ini name="display_errors" value="1" />
|
||||
<ini name="error_reporting" value="-1" />
|
||||
<server name="KERNEL_CLASS" value="App\Kernel" />
|
||||
<server name="APP_ENV" value="test" force="true" />
|
||||
<server name="SHELL_VERBOSITY" value="-1" />
|
||||
</php>
|
||||
</phpunit>
|
|
@ -6,7 +6,9 @@
|
|||
backupGlobals="false"
|
||||
colors="true"
|
||||
bootstrap="tests/bootstrap.php"
|
||||
convertDeprecationsToExceptions="false"
|
||||
convertDeprecationsToExceptions="true"
|
||||
executionOrder="random"
|
||||
resolveDependencies="true"
|
||||
>
|
||||
<php>
|
||||
<ini name="display_errors" value="1" />
|
||||
|
@ -14,7 +16,8 @@
|
|||
<server name="APP_ENV" value="test" force="true" />
|
||||
<server name="SHELL_VERBOSITY" value="-1" />
|
||||
<server name="SYMFONY_PHPUNIT_REMOVE" value="" />
|
||||
<server name="SYMFONY_PHPUNIT_VERSION" value="9.5" />
|
||||
<server name="SYMFONY_PHPUNIT_VERSION" value="9.6" />
|
||||
<server name="KERNEL_CLASS" value="App\Kernel" />
|
||||
</php>
|
||||
|
||||
<testsuites>
|
||||
|
|
|
@ -14,12 +14,15 @@ use Symfony\Component\OptionsResolver\OptionsResolver;
|
|||
use Symfony\Component\Validator\Constraints\Length;
|
||||
use Symfony\Component\Validator\Constraints\NotBlank;
|
||||
|
||||
use function assert;
|
||||
|
||||
final class MenuItemType extends AbstractType
|
||||
{
|
||||
#[Override]
|
||||
public function buildForm(FormBuilderInterface $builder, array $options): void
|
||||
{
|
||||
$item = $options['data'];
|
||||
assert($item instanceof MenuItem);
|
||||
|
||||
$builder->add('name', TextType::class, [
|
||||
'constraints' => [
|
||||
|
|
|
@ -8,15 +8,4 @@ use Symfony\Component\HttpKernel\Kernel as BaseKernel;
|
|||
final class Kernel extends BaseKernel
|
||||
{
|
||||
use MicroKernelTrait;
|
||||
|
||||
public function __construct(
|
||||
protected string $environment,
|
||||
protected bool $debug,
|
||||
) {
|
||||
parent::__construct($environment, $debug);
|
||||
if ($environment === 'test') {
|
||||
$this->debug = false;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
17
symfony.lock
17
symfony.lock
|
@ -48,7 +48,7 @@
|
|||
}
|
||||
},
|
||||
"phpunit/phpunit": {
|
||||
"version": "11.4",
|
||||
"version": "9.6",
|
||||
"recipe": {
|
||||
"repo": "github.com/symfony/recipes",
|
||||
"branch": "main",
|
||||
|
@ -122,6 +122,21 @@
|
|||
"ref": "fadbfe33303a76e25cb63401050439aa9b1a9c7f"
|
||||
}
|
||||
},
|
||||
"symfony/phpunit-bridge": {
|
||||
"version": "7.1",
|
||||
"recipe": {
|
||||
"repo": "github.com/symfony/recipes",
|
||||
"branch": "main",
|
||||
"version": "6.3",
|
||||
"ref": "a411a0480041243d97382cac7984f7dce7813c08"
|
||||
},
|
||||
"files": [
|
||||
".env.test",
|
||||
"bin/phpunit",
|
||||
"phpunit.xml.dist",
|
||||
"tests/bootstrap.php"
|
||||
]
|
||||
},
|
||||
"symfony/routing": {
|
||||
"version": "7.1",
|
||||
"recipe": {
|
||||
|
|
|
@ -1,40 +1,45 @@
|
|||
<?php declare(strict_types=1);
|
||||
|
||||
namespace App\Tests\Feature\Controller;
|
||||
namespace App\Tests\Controller;
|
||||
|
||||
use App\Controller\FoodOrderController;
|
||||
use App\Entity\FoodOrder;
|
||||
use App\Entity\FoodVendor;
|
||||
use App\Entity\MenuItem;
|
||||
use App\Entity\OrderItem;
|
||||
use App\Form\FoodOrderType;
|
||||
use App\Repository\FoodOrderRepository;
|
||||
use App\Repository\FoodVendorRepository;
|
||||
use App\Tests\DbWebTest;
|
||||
use Override;
|
||||
use Symfony\Component\BrowserKit\Cookie;
|
||||
use Symfony\Component\DomCrawler\Crawler;
|
||||
|
||||
use function assert;
|
||||
use function describe;
|
||||
use function pest;
|
||||
use function range;
|
||||
use function sprintf;
|
||||
use function str_ends_with;
|
||||
use function test;
|
||||
|
||||
pest()
|
||||
->beforeEach(function (): void {
|
||||
$this->setEntityClass(FoodOrder::class);
|
||||
$this->setPath('/food/order/');
|
||||
$this->repository = $this->manager->getRepository($this->entityClass);
|
||||
final class FoodOrderControllerTest extends DbWebTest
|
||||
{
|
||||
private string $path = '/food/order/';
|
||||
private FoodVendor $vendor;
|
||||
|
||||
#[Override]
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->vendor = new FoodVendor;
|
||||
$this->vendor->setName('Food Vendor');
|
||||
|
||||
$this->manager->persist($this->vendor);
|
||||
$this->manager->flush();
|
||||
});
|
||||
}
|
||||
|
||||
describe(FoodOrderController::class, function (): void {
|
||||
test('index', function (): void {
|
||||
#[Override]
|
||||
public function getEntityClass(): string
|
||||
{
|
||||
return FoodOrder::class;
|
||||
}
|
||||
|
||||
public function testIndex(): void
|
||||
{
|
||||
$order = new FoodOrder;
|
||||
$order->setFoodVendor($this->vendor);
|
||||
|
||||
|
@ -43,16 +48,17 @@ describe(FoodOrderController::class, function (): void {
|
|||
$this->manager->flush();
|
||||
|
||||
$crawler = $this->client->request('GET', "{$this->path}list");
|
||||
$this->assertResponseStatusCodeSame(200);
|
||||
$this->assertPageTitleContains('FoodOrder index');
|
||||
self::assertResponseStatusCodeSame(200);
|
||||
self::assertPageTitleContains('FoodOrder index');
|
||||
$this->assertCount(
|
||||
1,
|
||||
$crawler->filter('td')
|
||||
->reduce(fn(Crawler $node, $i): bool => $node->text() === $this->vendor->getName()),
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
test('orderedItems', function (): void {
|
||||
public function testOrderedItems(): void
|
||||
{
|
||||
$order = new FoodOrder;
|
||||
$order->setFoodVendor($this->vendor);
|
||||
|
||||
|
@ -98,7 +104,7 @@ describe(FoodOrderController::class, function (): void {
|
|||
$this->manager->flush();
|
||||
|
||||
$crawler = $this->client->request('GET', "{$this->path}{$order->getId()}");
|
||||
$this->assertResponseIsSuccessful();
|
||||
self::assertResponseIsSuccessful();
|
||||
$tdContent = $crawler->filter(
|
||||
'table.table:nth-child(6) > tbody:nth-child(2) > tr:nth-child(1) > td:nth-child(2)'
|
||||
)->text();
|
||||
|
@ -111,20 +117,14 @@ describe(FoodOrderController::class, function (): void {
|
|||
'table.table:nth-child(6) > tbody:nth-child(2) > tr:nth-child(3) > td:nth-child(2)'
|
||||
)->text();
|
||||
$this->assertEquals('C', $tdContent);
|
||||
});
|
||||
|
||||
test('paginatedIndex', function (): void {
|
||||
foreach (range(1, 35) as $i) {
|
||||
$order = new FoodOrder($this->generateOldUlid());
|
||||
$order->setFoodVendor($this->vendor);
|
||||
$order->close();
|
||||
$this->manager->persist($order);
|
||||
|
||||
}
|
||||
$this->manager->flush();
|
||||
|
||||
public function testPaginatedIndex(): void
|
||||
{
|
||||
$this->generatePaginatedOrders();
|
||||
$crawler = $this->client->request('GET', "{$this->path}list");
|
||||
$this->assertResponseStatusCodeSame(200);
|
||||
$this->assertPageTitleContains('FoodOrder index');
|
||||
self::assertResponseStatusCodeSame(200);
|
||||
self::assertPageTitleContains('FoodOrder index');
|
||||
$this->assertElementContainsCount(
|
||||
$crawler,
|
||||
'td',
|
||||
|
@ -137,20 +137,20 @@ describe(FoodOrderController::class, function (): void {
|
|||
0,
|
||||
'next page'
|
||||
);
|
||||
});
|
||||
|
||||
test('paginatedFirstPage', function (int $page, int $prevPage, int $nextPage, int $items = 10): void {
|
||||
foreach (range(1, 35) as $i) {
|
||||
$order = new FoodOrder($this->generateOldUlid());
|
||||
$order->setFoodVendor($this->vendor);
|
||||
$order->close();
|
||||
$this->manager->persist($order);
|
||||
|
||||
}
|
||||
$this->manager->flush();
|
||||
|
||||
/**
|
||||
* @testWith [1, 0, 2]
|
||||
* [2, 1, 3]
|
||||
* [3, 2, 4]
|
||||
* [4, 3, 0, 5]
|
||||
*/
|
||||
public function testPaginatedFirstPage(int $page, int $prevPage, int $nextPage, int $items = 10): void
|
||||
{
|
||||
$this->generatePaginatedOrders();
|
||||
$crawler = $this->client->request('GET', "{$this->path}list/archive/{$page}");
|
||||
$this->assertResponseStatusCodeSame(200);
|
||||
$this->assertPageTitleContains('FoodOrder index');
|
||||
self::assertResponseStatusCodeSame(200);
|
||||
self::assertPageTitleContains('FoodOrder index');
|
||||
$this->assertElementContainsCount(
|
||||
$crawler,
|
||||
'td',
|
||||
|
@ -172,36 +172,30 @@ describe(FoodOrderController::class, function (): void {
|
|||
$target = $node->attr('href');
|
||||
$this->assertTrue(str_ends_with((string) $target, "/{$nextPage}"));
|
||||
}
|
||||
})
|
||||
->with(
|
||||
[
|
||||
[1, 0, 2],
|
||||
[2, 1, 3],
|
||||
[3, 2, 4],
|
||||
[4, 3, 0, 5],
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
test('new', function (): void {
|
||||
public function testNew(): void
|
||||
{
|
||||
$this->client->getCookieJar()
|
||||
->set(new Cookie('username', 'Testing-1'));
|
||||
$this->client->request('GET', sprintf('%snew', $this->path));
|
||||
|
||||
$this->assertResponseStatusCodeSame(200);
|
||||
self::assertResponseStatusCodeSame(200);
|
||||
|
||||
$this->client->submitForm('Save', [
|
||||
'food_order[foodVendor]' => $this->vendor->getId(),
|
||||
]);
|
||||
|
||||
$this->assertResponseRedirects("{$this->path}list");
|
||||
$this->assertSame(1, $this->repository->count([]));
|
||||
self::assertResponseRedirects("{$this->path}list");
|
||||
self::assertSame(1, $this->repository->count([]));
|
||||
$order = $this->repository->findOneBy([
|
||||
'createdBy' => 'Testing-1',
|
||||
]);
|
||||
assert($order instanceof FoodOrder);
|
||||
});
|
||||
}
|
||||
|
||||
test('open', function (): void {
|
||||
public function testOpen(): void
|
||||
{
|
||||
$order = new FoodOrder;
|
||||
$order->setFoodVendor($this->vendor);
|
||||
$order->close();
|
||||
|
@ -211,12 +205,13 @@ describe(FoodOrderController::class, function (): void {
|
|||
$this->manager->flush();
|
||||
|
||||
$this->client->request('GET', sprintf('%s%s/open', $this->path, $order->getId()));
|
||||
$this->assertResponseRedirects("{$this->path}{$order->getId()}");
|
||||
self::assertResponseRedirects("{$this->path}{$order->getId()}");
|
||||
$openOrder = $this->repository->find($order->getId());
|
||||
$this->assertFalse($openOrder->isClosed());
|
||||
});
|
||||
}
|
||||
|
||||
test('close', function (): void {
|
||||
public function testClose(): void
|
||||
{
|
||||
$order = new FoodOrder;
|
||||
$order->setClosedAt();
|
||||
$order->setFoodVendor($this->vendor);
|
||||
|
@ -226,19 +221,20 @@ describe(FoodOrderController::class, function (): void {
|
|||
$this->manager->flush();
|
||||
|
||||
$this->client->request('GET', sprintf('%s%s/close', $this->path, $order->getId()));
|
||||
$this->assertResponseRedirects("{$this->path}{$order->getId()}");
|
||||
self::assertResponseRedirects("{$this->path}{$order->getId()}");
|
||||
$openOrder = $this->repository->find($order->getId());
|
||||
$this->assertTrue($openOrder->isClosed());
|
||||
});
|
||||
}
|
||||
|
||||
})
|
||||
->covers(
|
||||
FoodOrderController::class,
|
||||
FoodOrder::class,
|
||||
FoodVendor::class,
|
||||
FoodOrderRepository::class,
|
||||
MenuItem::class,
|
||||
OrderItem::class,
|
||||
FoodOrderType::class,
|
||||
FoodVendorRepository::class
|
||||
);
|
||||
private function generatePaginatedOrders(): void
|
||||
{
|
||||
foreach (range(1, 35) as $i) {
|
||||
$order = new FoodOrder($this->generateOldUlid());
|
||||
$order->setFoodVendor($this->vendor);
|
||||
$order->close();
|
||||
$this->manager->persist($order);
|
||||
|
||||
}
|
||||
$this->manager->flush();
|
||||
}
|
||||
}
|
|
@ -1,42 +1,32 @@
|
|||
<?php declare(strict_types=1);
|
||||
|
||||
namespace App\Tests\Feature\Controller;
|
||||
namespace App\Tests\Controller;
|
||||
|
||||
use App\Controller\FoodVendorController;
|
||||
use App\Entity\FoodOrder;
|
||||
use App\Entity\FoodVendor;
|
||||
use App\Entity\MenuItem;
|
||||
use App\Entity\OrderItem;
|
||||
use App\Form\FoodOrderType;
|
||||
use App\Form\FoodVendorType;
|
||||
use App\Repository\FoodOrderRepository;
|
||||
use App\Repository\FoodVendorRepository;
|
||||
use App\Tests\DbWebTest;
|
||||
use Override;
|
||||
|
||||
use function describe;
|
||||
use function pest;
|
||||
use function sprintf;
|
||||
use function test;
|
||||
|
||||
pest()
|
||||
->beforeEach(function (): void {
|
||||
$this->setEntityClass(FoodVendor::class);
|
||||
$this->setPath('/food/vendor/');
|
||||
$this->repository = $this->manager->getRepository($this->entityClass);
|
||||
});
|
||||
final class FoodVendorControllerTest extends DbWebTest
|
||||
{
|
||||
private string $path = '/food/vendor/';
|
||||
|
||||
describe(FoodVendorController::class, function (): void {
|
||||
test('index', function (): void {
|
||||
public function testIndex(): void
|
||||
{
|
||||
$this->client->request('GET', $this->path);
|
||||
|
||||
$this->assertResponseStatusCodeSame(200);
|
||||
$this->assertPageTitleContains('FoodVendor index');
|
||||
});
|
||||
self::assertResponseStatusCodeSame(200);
|
||||
self::assertPageTitleContains('FoodVendor index');
|
||||
}
|
||||
|
||||
test('new', function (): void {
|
||||
$this->assertSame(0, $this->repository->count([]));
|
||||
public function testNew(): void
|
||||
{
|
||||
self::assertSame(0, $this->repository->count([]));
|
||||
$this->client->request('GET', sprintf('%snew', $this->path));
|
||||
|
||||
$this->assertResponseStatusCodeSame(200);
|
||||
self::assertResponseStatusCodeSame(200);
|
||||
|
||||
$this->client->submitForm('Save', [
|
||||
'food_vendor[name]' => 'TestingNew',
|
||||
|
@ -46,11 +36,12 @@ describe(FoodVendorController::class, function (): void {
|
|||
'name' => 'TestingNew',
|
||||
]);
|
||||
$this->assertInstanceof(FoodVendor::class, $newVendor);
|
||||
$this->assertSame(1, $this->repository->count([]));
|
||||
self::assertSame(1, $this->repository->count([]));
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
test('show', function (): void {
|
||||
public function testShow(): void
|
||||
{
|
||||
$fixture = new FoodVendor;
|
||||
$fixture->setName('My Title');
|
||||
$fixture->setMenuLink('https://example.com/');
|
||||
|
@ -72,9 +63,10 @@ describe(FoodVendorController::class, function (): void {
|
|||
)->text();
|
||||
$this->assertSame('My Title', $nameNode);
|
||||
$this->assertSame('https://example.com/', $menuLinkNode);
|
||||
});
|
||||
}
|
||||
|
||||
test('show with menu items', function (): void {
|
||||
public function testShowMenuItems(): void
|
||||
{
|
||||
$fixture = new FoodVendor;
|
||||
$fixture->setName('My Title');
|
||||
|
||||
|
@ -122,9 +114,10 @@ describe(FoodVendorController::class, function (): void {
|
|||
$itemNodes = $crawler->filter('li');
|
||||
|
||||
$this->assertCount(4, $itemNodes);
|
||||
});
|
||||
}
|
||||
|
||||
test('edit', function (): void {
|
||||
public function testEdit(): void
|
||||
{
|
||||
$fixture = new FoodVendor;
|
||||
$fixture->setName('Value');
|
||||
$fixture->setMenuLink('Value');
|
||||
|
@ -159,26 +152,18 @@ describe(FoodVendorController::class, function (): void {
|
|||
'food_vendor[phone]' => '1234567890',
|
||||
]);
|
||||
|
||||
$this->assertResponseRedirects('/food/vendor/');
|
||||
self::assertResponseRedirects('/food/vendor/');
|
||||
|
||||
$fixture = $this->repository->findAll();
|
||||
|
||||
$this->assertSame('Something New', $fixture[0]->getName());
|
||||
$this->assertSame('https://example.com/', $fixture[0]->getMenuLink());
|
||||
$this->assertSame('1234567890', $fixture[0]->getPhone());
|
||||
});
|
||||
self::assertSame('Something New', $fixture[0]->getName());
|
||||
self::assertSame('https://example.com/', $fixture[0]->getMenuLink());
|
||||
self::assertSame('1234567890', $fixture[0]->getPhone());
|
||||
}
|
||||
|
||||
})
|
||||
->covers(
|
||||
FoodOrder::class,
|
||||
FoodVendor::class,
|
||||
FoodOrderRepository::class,
|
||||
MenuItem::class,
|
||||
OrderItem::class,
|
||||
FoodOrderType::class,
|
||||
FoodVendorRepository::class,
|
||||
FoodVendorController::class,
|
||||
FoodVendorType::class
|
||||
)
|
||||
|
||||
;
|
||||
#[Override]
|
||||
public function getEntityClass(): string
|
||||
{
|
||||
return FoodVendor::class;
|
||||
}
|
||||
}
|
76
tests/Controller/HomeControllerTest.php
Normal file
76
tests/Controller/HomeControllerTest.php
Normal file
|
@ -0,0 +1,76 @@
|
|||
<?php declare(strict_types=1);
|
||||
|
||||
namespace App\Tests\Controller;
|
||||
|
||||
use App\Tests\DbWebTest;
|
||||
use Override;
|
||||
|
||||
final class HomeControllerTest extends DbWebTest
|
||||
{
|
||||
public function testIndex(): void
|
||||
{
|
||||
$this->client->request(
|
||||
'GET',
|
||||
'/'
|
||||
);
|
||||
|
||||
self::assertResponseStatusCodeSame(302);
|
||||
self::assertResponseHeaderSame('Location', '/food/order/list');
|
||||
|
||||
}
|
||||
|
||||
public function testSetUsername(): void
|
||||
{
|
||||
$this->client->request(
|
||||
'GET',
|
||||
'/username',
|
||||
);
|
||||
|
||||
self::assertResponseStatusCodeSame(200);
|
||||
|
||||
$this->client->submitForm('Save', [
|
||||
'user_name_form[username]' => 'Testing-1',
|
||||
]);
|
||||
self::assertResponseStatusCodeSame(302);
|
||||
self::assertResponseHeaderSame('Location', '/food/order/list');
|
||||
self::assertResponseCookieValueSame('username', 'Testing-1');
|
||||
|
||||
$crawler = $this->client->request(
|
||||
'GET',
|
||||
'/username',
|
||||
);
|
||||
|
||||
self::assertResponseStatusCodeSame(200);
|
||||
|
||||
$this->assertSame(
|
||||
$crawler->filter('#user_name_form_username')
|
||||
->last()
|
||||
->attr('value', ''),
|
||||
'Testing-1'
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
public function testRemoveUsername(): void
|
||||
{
|
||||
$this->client->request(
|
||||
'GET',
|
||||
'/username',
|
||||
);
|
||||
|
||||
self::assertResponseStatusCodeSame(200);
|
||||
|
||||
$this->client->submitForm('Save', [
|
||||
'user_name_form[username]' => '',
|
||||
]);
|
||||
self::assertResponseStatusCodeSame(302);
|
||||
self::assertResponseHeaderSame('Location', '/food/order/list');
|
||||
self::assertResponseCookieValueSame('username', '');
|
||||
}
|
||||
|
||||
#[Override]
|
||||
public function getEntityClass(): string
|
||||
{
|
||||
return '';
|
||||
}
|
||||
}
|
|
@ -1,34 +1,32 @@
|
|||
<?php declare(strict_types=1);
|
||||
|
||||
namespace App\Tests\Feature\Controller;
|
||||
namespace App\Tests\Controller;
|
||||
|
||||
use App\Controller\MenuItemController;
|
||||
use App\Controller\OrderItemController;
|
||||
use App\Entity\FoodOrder;
|
||||
use App\Entity\FoodVendor;
|
||||
use App\Entity\MenuItem;
|
||||
use App\Entity\OrderItem;
|
||||
use App\Form\MenuItemType;
|
||||
use App\Form\OrderItemType;
|
||||
use App\Repository\FoodOrderRepository;
|
||||
use App\Repository\MenuItemRepository;
|
||||
use App\Tests\DbWebTest;
|
||||
use Override;
|
||||
|
||||
use function describe;
|
||||
use function pest;
|
||||
use function sprintf;
|
||||
use function test;
|
||||
|
||||
pest()
|
||||
->beforeEach(function (): void {
|
||||
$this->setEntityClass(MenuItem::class);
|
||||
$this->setPath('/menu/item/');
|
||||
|
||||
$this->repository = $this->manager->getRepository($this->entityClass);
|
||||
final class MenuItemControllerTest extends DbWebTest
|
||||
{
|
||||
private string $path = '/menu/item/';
|
||||
private FoodVendor $vendor;
|
||||
private MenuItem $menuItem;
|
||||
private MenuItem $aliasOne;
|
||||
private MenuItem $aliasTwo;
|
||||
|
||||
#[Override]
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->vendor = new FoodVendor;
|
||||
$this->vendor->setName('Food Vendor');
|
||||
|
||||
$this->manager->persist($this->vendor);
|
||||
|
||||
$this->menuItem = new MenuItem;
|
||||
$this->menuItem->setName('Testing 1 2');
|
||||
|
||||
|
@ -54,10 +52,16 @@ pest()
|
|||
$this->manager->persist($this->menuItem);
|
||||
$this->manager->flush();
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
describe(MenuItemController::class, function (): void {
|
||||
test('show', function (): void {
|
||||
#[Override]
|
||||
public function getEntityClass(): string
|
||||
{
|
||||
return MenuItem::class;
|
||||
}
|
||||
|
||||
public function testShow(): void
|
||||
{
|
||||
|
||||
$crawler = $this->client->request('GET', "{$this->path}{$this->menuItem->getId()}");
|
||||
$idValue = $crawler->filter(
|
||||
|
@ -73,14 +77,15 @@ describe(MenuItemController::class, function (): void {
|
|||
$aliasOneNameValue = $crawler->filter(
|
||||
'.table > tbody:nth-child(1) > tr:nth-child(3) > td:nth-child(2) > ul:nth-child(1) > li:nth-child(2)'
|
||||
)->text();
|
||||
$this->assertResponseStatusCodeSame(200);
|
||||
self::assertResponseStatusCodeSame(200);
|
||||
$this->assertEquals($idValue, $this->menuItem->getId());
|
||||
$this->assertEquals($nameValue, $this->menuItem->getName());
|
||||
$this->assertEquals($aliasTwoNameValue, $this->aliasOne->getName());
|
||||
$this->assertEquals($aliasOneNameValue, $this->aliasTwo->getName());
|
||||
});
|
||||
}
|
||||
|
||||
test('edit', function (): void {
|
||||
public function testEdit(): void
|
||||
{
|
||||
$crawler = $this->client->request('GET', sprintf('%s%s/edit', $this->path, $this->menuItem->getId()));
|
||||
$nameElem = $crawler->filter('#menu_item_name');
|
||||
$this->assertEquals(
|
||||
|
@ -95,15 +100,16 @@ describe(MenuItemController::class, function (): void {
|
|||
|
||||
$this->client->submit($form);
|
||||
|
||||
$this->assertResponseRedirects(sprintf('/menu/item/%s', $this->menuItem->getId()));
|
||||
self::assertResponseRedirects(sprintf('/menu/item/%s', $this->menuItem->getId()));
|
||||
$menuItem = $this->repository->find($this->menuItem->getId());
|
||||
$this->assertEquals('Testing-1', $menuItem->getName());
|
||||
$this->assertEquals(1, $menuItem->getAliases()->count());
|
||||
$aliasOne = $this->repository->find($this->aliasOne->getId());
|
||||
$this->assertNull($aliasOne->getAliasOf());
|
||||
});
|
||||
}
|
||||
|
||||
test('edit invalid', function (): void {
|
||||
public function testEditInvalid(): void
|
||||
{
|
||||
$crawler = $this->client->request('GET', sprintf('%s%s/edit', $this->path, $this->menuItem->getId()));
|
||||
$nameElem = $crawler->filter('#menu_item_name');
|
||||
$this->assertEquals(
|
||||
|
@ -117,10 +123,11 @@ describe(MenuItemController::class, function (): void {
|
|||
|
||||
$this->client->submit($form);
|
||||
|
||||
$this->assertResponseStatusCodeSame(422);
|
||||
});
|
||||
self::assertResponseStatusCodeSame(422);
|
||||
}
|
||||
|
||||
test('delete', function (): void {
|
||||
public function testDelete(): void
|
||||
{
|
||||
$order = new FoodOrder;
|
||||
$order->setFoodVendor($this->vendor);
|
||||
|
||||
|
@ -143,17 +150,5 @@ describe(MenuItemController::class, function (): void {
|
|||
|
||||
$this->assertResponseIsSuccessful();
|
||||
|
||||
});
|
||||
})
|
||||
->covers(
|
||||
MenuItemController::class,
|
||||
OrderItemController::class,
|
||||
OrderItemType::class,
|
||||
MenuItemRepository::class,
|
||||
FoodOrder::class,
|
||||
FoodVendor::class,
|
||||
MenuItem::class,
|
||||
OrderItem::class,
|
||||
FoodOrderRepository::class,
|
||||
MenuItemType::class,
|
||||
);
|
||||
}
|
||||
}
|
|
@ -1,29 +1,30 @@
|
|||
<?php declare(strict_types=1);
|
||||
|
||||
namespace App\Tests\Feature\Controller;
|
||||
namespace App\Tests\Controller;
|
||||
|
||||
use App\Controller\OrderItemController;
|
||||
use App\Entity\FoodOrder;
|
||||
use App\Entity\FoodVendor;
|
||||
use App\Entity\MenuItem;
|
||||
use App\Entity\OrderItem;
|
||||
use App\Form\OrderItemType;
|
||||
use App\Repository\FoodOrderRepository;
|
||||
use App\Repository\MenuItemRepository;
|
||||
use App\Repository\OrderItemRepository;
|
||||
use App\Tests\DbWebTest;
|
||||
use DateTimeImmutable;
|
||||
use Override;
|
||||
|
||||
use function describe;
|
||||
use function pest;
|
||||
use function sprintf;
|
||||
use function test;
|
||||
|
||||
pest()
|
||||
->beforeEach(function (): void {
|
||||
$this->setEntityClass(OrderItem::class);
|
||||
$this->setPath('/order/item/');
|
||||
$this->repository = $this->manager->getRepository($this->entityClass);
|
||||
final class OrderItemControllerTest extends DbWebTest
|
||||
{
|
||||
public FoodVendor $vendor;
|
||||
public FoodOrder $order;
|
||||
public Menuitem $menuItem;
|
||||
public MenuItemRepository $menuItemRepository;
|
||||
private string $path = '/order/item/';
|
||||
|
||||
#[Override]
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->vendor = new FoodVendor;
|
||||
$this->vendor->setName('Food Vendor');
|
||||
|
||||
|
@ -50,11 +51,11 @@ pest()
|
|||
$this->manager->persist($this->menuItem);
|
||||
$this->manager->flush();
|
||||
|
||||
$this->menuItemRepository = $this::getContainer()->get(MenuItemRepository::class);
|
||||
});
|
||||
$this->menuItemRepository = static::getContainer()->get(MenuItemRepository::class);
|
||||
}
|
||||
|
||||
describe(OrderItemController::class, function (): void {
|
||||
test('new', function (): void {
|
||||
public function testNew(): void
|
||||
{
|
||||
$crawler = $this->client->request(
|
||||
'GET',
|
||||
sprintf('%snew/%s', $this->path, $this->order->getId())
|
||||
|
@ -65,22 +66,23 @@ describe(OrderItemController::class, function (): void {
|
|||
|
||||
$this->assertCount(1, $children);
|
||||
|
||||
$this->assertResponseStatusCodeSame(200);
|
||||
self::assertResponseStatusCodeSame(200);
|
||||
|
||||
$this->client->submitForm('Save', [
|
||||
'order_item[name]' => 'Testing',
|
||||
'order_item[extras]' => 'Testing',
|
||||
]);
|
||||
|
||||
$this->assertResponseRedirects(sprintf('/food/order/%s', $this->order->getId()));
|
||||
self::assertResponseRedirects(sprintf('/food/order/%s', $this->order->getId()));
|
||||
|
||||
$this->assertSame(1, $this->repository->count([]));
|
||||
$this->assertSame(1, $this->menuItemRepository->count([
|
||||
self::assertSame(1, $this->repository->count([]));
|
||||
self::assertSame(1, $this->menuItemRepository->count([
|
||||
'foodVendor' => $this->vendor->getId(),
|
||||
]));
|
||||
});
|
||||
}
|
||||
|
||||
test('new order closed', function (): void {
|
||||
public function testNewOrderClosed(): void
|
||||
{
|
||||
|
||||
$this->order->setClosedAt(new DateTimeImmutable('-1 Hour'));
|
||||
$this->manager->persist($this->order);
|
||||
|
@ -91,31 +93,33 @@ describe(OrderItemController::class, function (): void {
|
|||
sprintf('%snew/%s', $this->path, $this->order->getId())
|
||||
);
|
||||
|
||||
$this->assertResponseRedirects(sprintf('/food/order/%s', $this->order->getId()));
|
||||
self::assertResponseRedirects(sprintf('/food/order/%s', $this->order->getId()));
|
||||
|
||||
$this->assertSame(0, $this->repository->count([]));
|
||||
});
|
||||
self::assertSame(0, $this->repository->count([]));
|
||||
}
|
||||
|
||||
test('new create menu item', function (): void {
|
||||
public function testNewCreateMenuItem(): void
|
||||
{
|
||||
$this->client->request(
|
||||
'GET',
|
||||
sprintf('%snew/%s', $this->path, $this->order->getId())
|
||||
);
|
||||
|
||||
$this->assertResponseStatusCodeSame(200);
|
||||
self::assertResponseStatusCodeSame(200);
|
||||
|
||||
$this->client->submitForm('Save', [
|
||||
'order_item[name]' => 'Testing-1',
|
||||
'order_item[extras]' => 'Testing-1',
|
||||
]);
|
||||
|
||||
$this->assertResponseRedirects(sprintf('/food/order/%s', $this->order->getId()));
|
||||
self::assertResponseRedirects(sprintf('/food/order/%s', $this->order->getId()));
|
||||
|
||||
$this->assertSame(1, $this->repository->count([]));
|
||||
$this->assertSame(3, $this->menuItemRepository->count([]));
|
||||
});
|
||||
self::assertSame(1, $this->repository->count([]));
|
||||
self::assertSame(3, $this->menuItemRepository->count([]));
|
||||
}
|
||||
|
||||
test('remove', function (): void {
|
||||
public function testRemove(): void
|
||||
{
|
||||
$fixture = new OrderItem;
|
||||
$fixture->setName('Testing');
|
||||
$fixture->setExtras('Value');
|
||||
|
@ -128,11 +132,12 @@ describe(OrderItemController::class, function (): void {
|
|||
|
||||
$this->client->request('GET', sprintf('%sdelete/%s', $this->path, $fixture->getId()));
|
||||
|
||||
$this->assertResponseRedirects(sprintf('/food/order/%s', $this->order->getId()));
|
||||
$this->assertSame(0, $this->repository->count([]));
|
||||
});
|
||||
self::assertResponseRedirects(sprintf('/food/order/%s', $this->order->getId()));
|
||||
self::assertSame(0, $this->repository->count([]));
|
||||
}
|
||||
|
||||
test('order closed', function (): void {
|
||||
public function testOrderClosed(): void
|
||||
{
|
||||
$fixture = new OrderItem;
|
||||
$fixture->setName('Testing');
|
||||
$fixture->setExtras('Value');
|
||||
|
@ -147,11 +152,12 @@ describe(OrderItemController::class, function (): void {
|
|||
|
||||
$this->client->request('GET', sprintf('%sdelete/%s', $this->path, $fixture->getId()));
|
||||
|
||||
$this->assertResponseRedirects(sprintf('/food/order/%s', $this->order->getId()));
|
||||
$this->assertSame(1, $this->repository->count([]));
|
||||
});
|
||||
self::assertResponseRedirects(sprintf('/food/order/%s', $this->order->getId()));
|
||||
self::assertSame(1, $this->repository->count([]));
|
||||
}
|
||||
|
||||
test('edit', function (): void {
|
||||
public function testEdit(): void
|
||||
{
|
||||
$orderItem = new OrderItem;
|
||||
$orderItem->setName('Testing');
|
||||
$orderItem->setExtras('My Extra');
|
||||
|
@ -179,14 +185,15 @@ describe(OrderItemController::class, function (): void {
|
|||
'order_item[extras]' => 'Testing-1',
|
||||
]);
|
||||
|
||||
$this->assertResponseRedirects(sprintf('/food/order/%s', $this->order->getId()));
|
||||
self::assertResponseRedirects(sprintf('/food/order/%s', $this->order->getId()));
|
||||
|
||||
$this->assertSame(1, $this->repository->count([]));
|
||||
$this->assertSame(3, $this->menuItemRepository->count([]));
|
||||
self::assertSame(1, $this->repository->count([]));
|
||||
self::assertSame(3, $this->menuItemRepository->count([]));
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
test('edit order closed', function (): void {
|
||||
public function testEditOrderClosed(): void
|
||||
{
|
||||
$orderItem = new OrderItem;
|
||||
$orderItem->setName('Testing');
|
||||
$orderItem->setExtras('My Extra');
|
||||
|
@ -200,10 +207,11 @@ describe(OrderItemController::class, function (): void {
|
|||
$this->manager->flush();
|
||||
|
||||
$this->client->request('GET', sprintf('%s%s/edit', $this->path, $orderItem->getId()));
|
||||
$this->assertResponseRedirects(sprintf('/food/order/%s', $this->order->getId()));
|
||||
});
|
||||
self::assertResponseRedirects(sprintf('/food/order/%s', $this->order->getId()));
|
||||
}
|
||||
|
||||
test('copy', function (): void {
|
||||
public function testCopy(): void
|
||||
{
|
||||
$orderItem = new OrderItem;
|
||||
$orderItem->setName('My Title');
|
||||
$orderItem->setExtras('My Title');
|
||||
|
@ -214,7 +222,7 @@ describe(OrderItemController::class, function (): void {
|
|||
$this->manager->flush();
|
||||
|
||||
$this->client->request('GET', sprintf('%s%s/copy', $this->path, $orderItem->getId()));
|
||||
$this->assertResponseRedirects(sprintf('/food/order/%s', $this->order->getId()));
|
||||
self::assertResponseRedirects(sprintf('/food/order/%s', $this->order->getId()));
|
||||
|
||||
$result = $this->repository->findBy([
|
||||
'foodOrder' => $this->order->getId(),
|
||||
|
@ -224,9 +232,10 @@ describe(OrderItemController::class, function (): void {
|
|||
$this->assertSame($orderItem->getName(), $item->getName());
|
||||
$this->assertSame($orderItem->getExtras(), $item->getExtras());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
test('copy order closed', function (): void {
|
||||
public function testCopyOrderClosed(): void
|
||||
{
|
||||
$orderItem = new OrderItem;
|
||||
$orderItem->setName('My Title');
|
||||
$orderItem->setExtras('My Title');
|
||||
|
@ -239,23 +248,17 @@ describe(OrderItemController::class, function (): void {
|
|||
$this->manager->flush();
|
||||
|
||||
$this->client->request('GET', sprintf('%s%s/copy', $this->path, $orderItem->getId()));
|
||||
$this->assertResponseRedirects(sprintf('/food/order/%s', $this->order->getId()));
|
||||
self::assertResponseRedirects(sprintf('/food/order/%s', $this->order->getId()));
|
||||
|
||||
$result = $this->repository->findBy([
|
||||
'foodOrder' => $this->order->getId(),
|
||||
]);
|
||||
$this->assertCount(1, $result);
|
||||
});
|
||||
}
|
||||
|
||||
})
|
||||
->covers(
|
||||
OrderItemController::class,
|
||||
MenuItemRepository::class,
|
||||
OrderItemRepository::class,
|
||||
OrderItemType::class,
|
||||
FoodOrder::class,
|
||||
FoodVendor::class,
|
||||
MenuItem::class,
|
||||
OrderItem::class,
|
||||
FoodOrderRepository::class,
|
||||
);
|
||||
#[Override]
|
||||
public function getEntityClass(): string
|
||||
{
|
||||
return OrderItem::class;
|
||||
}
|
||||
}
|
|
@ -17,11 +17,11 @@ use function str_contains;
|
|||
|
||||
abstract class DbWebTest extends WebTestCase
|
||||
{
|
||||
abstract public function getEntityClass(): string;
|
||||
|
||||
protected KernelBrowser $client;
|
||||
protected EntityManagerInterface $manager;
|
||||
protected EntityRepository $repository;
|
||||
protected string $entityClass = '';
|
||||
protected string $path = '';
|
||||
|
||||
#[Override]
|
||||
protected function setUp(): void
|
||||
|
@ -33,6 +33,10 @@ abstract class DbWebTest extends WebTestCase
|
|||
->getAllMetadata();
|
||||
$schemaTool->dropDatabase();
|
||||
$schemaTool->updateSchema($metadata);
|
||||
|
||||
if ($this->getEntityClass() !== '') {
|
||||
$this->repository = $this->manager->getRepository($this->getEntityClass());
|
||||
}
|
||||
}
|
||||
|
||||
protected function generateOldUlid(int $daysToSubtract = 10): Ulid
|
||||
|
@ -52,15 +56,4 @@ abstract class DbWebTest extends WebTestCase
|
|||
)
|
||||
);
|
||||
}
|
||||
|
||||
protected function setEntityClass(string $entityClass): void
|
||||
{
|
||||
$this->entityClass = $entityClass;
|
||||
$this->repository = $this->manager->getRepository($this->entityClass);
|
||||
}
|
||||
|
||||
protected function setPath(string $path): void
|
||||
{
|
||||
$this->path = $path;
|
||||
}
|
||||
}
|
||||
|
|
24
tests/Entity/FoodOrderTest.php
Normal file
24
tests/Entity/FoodOrderTest.php
Normal file
|
@ -0,0 +1,24 @@
|
|||
<?php declare(strict_types=1);
|
||||
|
||||
namespace App\Tests\Entity;
|
||||
|
||||
use App\Entity\FoodOrder;
|
||||
use App\Entity\OrderItem;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
final class FoodOrderTest extends TestCase
|
||||
{
|
||||
public function testFoodOrder(): void
|
||||
{
|
||||
$order = new FoodOrder;
|
||||
$orderItem = new OrderItem;
|
||||
$this->assertCount(0, $order->getOrderItems());
|
||||
$order->addOrderItem($orderItem);
|
||||
$order->addOrderItem($orderItem);
|
||||
$this->assertCount(1, $order->getOrderItems());
|
||||
$this->assertSame($order, $orderItem->getFoodOrder());
|
||||
$order->removeOrderItem($orderItem);
|
||||
$this->assertCount(0, $order->getOrderItems());
|
||||
$this->assertNull($orderItem->getFoodOrder());
|
||||
}
|
||||
}
|
|
@ -1,17 +1,17 @@
|
|||
<?php declare(strict_types=1);
|
||||
|
||||
namespace App\Tests\Unit\Entity;
|
||||
namespace App\Tests\Entity;
|
||||
|
||||
use App\Entity\FoodOrder;
|
||||
use App\Entity\FoodVendor;
|
||||
use App\Entity\MenuItem;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\Uid\Ulid;
|
||||
|
||||
use function describe;
|
||||
use function test;
|
||||
|
||||
describe(FoodVendor::class, function (): void {
|
||||
test('FoodVendor entity', function (): void {
|
||||
final class FoodVendorTest extends TestCase
|
||||
{
|
||||
public function testFoodVendor(): void
|
||||
{
|
||||
$vendor = new FoodVendor;
|
||||
$vendor->setName('Test');
|
||||
$this->assertEquals('Test', $vendor->getName());
|
||||
|
@ -29,9 +29,11 @@ describe(FoodVendor::class, function (): void {
|
|||
$vendor->removeFoodOrder($order1);
|
||||
$this->assertCount(0, $vendor->getFoodOrders());
|
||||
$this->assertNull($order1->getFoodVendor());
|
||||
});
|
||||
|
||||
test('MenutItem entity', function (): void {
|
||||
}
|
||||
|
||||
public function testMenuItem(): void
|
||||
{
|
||||
$vendor = new FoodVendor;
|
||||
$menuItem1 = new MenuItem;
|
||||
$menuItem2 = new MenuItem;
|
||||
|
@ -47,9 +49,10 @@ describe(FoodVendor::class, function (): void {
|
|||
$vendor->addMenuItem($menuItem2);
|
||||
$this->assertCount(1, $vendor->getMenuItems());
|
||||
$this->assertCount(2, $vendor->getMenuItems(true));
|
||||
});
|
||||
}
|
||||
|
||||
test('remove foreign menu item', function (): void {
|
||||
public function testRemoveForeignMenuItem(): void
|
||||
{
|
||||
$vendor1 = new FoodVendor;
|
||||
$vendor2 = new FoodVendor;
|
||||
$item1 = new MenuItem;
|
||||
|
@ -59,6 +62,5 @@ describe(FoodVendor::class, function (): void {
|
|||
$vendor2->removeMenuItem($item1);
|
||||
$this->assertCount(1, $vendor1->getMenuItems());
|
||||
$this->assertSame($vendor1, $item1->getFoodVendor());
|
||||
});
|
||||
|
||||
})->covers(FoodVendor::class, FoodOrder::class, MenuItem::class);
|
||||
}
|
||||
}
|
|
@ -1,16 +1,16 @@
|
|||
<?php declare(strict_types=1);
|
||||
|
||||
namespace App\Tests\Unit\Entity;
|
||||
namespace App\Tests\Entity;
|
||||
|
||||
use App\Entity\FoodVendor;
|
||||
use App\Entity\MenuItem;
|
||||
use DateTimeImmutable;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
use function describe;
|
||||
use function test;
|
||||
|
||||
describe(MenuItem::class, function (): void {
|
||||
test('MenuItem entity', function (): void {
|
||||
final class MenuItemTest extends TestCase
|
||||
{
|
||||
public function testMenuItem(): void
|
||||
{
|
||||
$item = new MenuItem;
|
||||
$item->setName('Test');
|
||||
$this->assertEquals('Test', $item->getName());
|
||||
|
@ -26,8 +26,10 @@ describe(MenuItem::class, function (): void {
|
|||
$item->delete();
|
||||
$this->assertTrue($item->isDeleted());
|
||||
$this->assertInstanceOf(DateTimeImmutable::class, $item->getDeletedAt());
|
||||
});
|
||||
test('MenuItem alias', function (): void {
|
||||
}
|
||||
|
||||
public function testMenuItemAlias(): void
|
||||
{
|
||||
$item = new MenuItem;
|
||||
$item->setName('Test');
|
||||
$this->assertEquals('Test', $item->getName());
|
||||
|
@ -49,5 +51,6 @@ describe(MenuItem::class, function (): void {
|
|||
$item->removeAlias($item2);
|
||||
$this->assertCount(0, $item->getAliases());
|
||||
$this->assertNull($item2->getAliasOf());
|
||||
});
|
||||
})->covers(MenuItem::class, FoodVendor::class);
|
||||
|
||||
}
|
||||
}
|
|
@ -1,71 +0,0 @@
|
|||
<?php declare(strict_types=1);
|
||||
|
||||
namespace App\Tests\Feature\Controller;
|
||||
|
||||
use App\Controller\HomeController;
|
||||
use App\Form\UserNameFormType;
|
||||
|
||||
use function describe;
|
||||
use function test;
|
||||
|
||||
describe(HomeController::class, function (): void {
|
||||
|
||||
test('index', function (): void {
|
||||
$this->client->request(
|
||||
'GET',
|
||||
'/'
|
||||
);
|
||||
|
||||
$this->assertResponseStatusCodeSame(302);
|
||||
$this->assertResponseHeaderSame('Location', '/food/order/list');
|
||||
|
||||
});
|
||||
|
||||
test('username', function (): void {
|
||||
$this->client->request(
|
||||
'GET',
|
||||
'/username',
|
||||
);
|
||||
|
||||
$this->assertResponseStatusCodeSame(200);
|
||||
|
||||
$this->client->submitForm('Save', [
|
||||
'user_name_form[username]' => 'Testing-1',
|
||||
]);
|
||||
$this->assertResponseStatusCodeSame(302);
|
||||
$this->assertResponseHeaderSame('Location', '/food/order/list');
|
||||
$this->assertResponseCookieValueSame('username', 'Testing-1');
|
||||
|
||||
$crawler = $this->client->request(
|
||||
'GET',
|
||||
'/username',
|
||||
);
|
||||
|
||||
$this->assertResponseStatusCodeSame(200);
|
||||
|
||||
$this->assertSame(
|
||||
$crawler->filter('#user_name_form_username')
|
||||
->last()
|
||||
->attr('value', ''),
|
||||
'Testing-1'
|
||||
);
|
||||
|
||||
});
|
||||
|
||||
test('username empty', function (): void {
|
||||
$this->client->request(
|
||||
'GET',
|
||||
'/username',
|
||||
);
|
||||
|
||||
$this->assertResponseStatusCodeSame(200);
|
||||
|
||||
$this->client->submitForm('Save', [
|
||||
'user_name_form[username]' => '',
|
||||
]);
|
||||
$this->assertResponseStatusCodeSame(302);
|
||||
$this->assertResponseHeaderSame('Location', '/food/order/list');
|
||||
$this->assertResponseCookieValueSame('username', '');
|
||||
});
|
||||
})
|
||||
->covers(HomeController::class, UserNameFormType::class);
|
|
@ -1,33 +0,0 @@
|
|||
<?php declare(strict_types=1);
|
||||
|
||||
use App\Tests\DbWebTest;
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Test Case
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| The closure you provide to your test functions is always bound to a specific PHPUnit test
|
||||
| case class. By default, that class is "PHPUnit\Framework\TestCase". Of course, you may
|
||||
| need to change it using the "pest()" function to bind a different classes or traits.
|
||||
|
|
||||
*/
|
||||
|
||||
pest()
|
||||
->extends(DbWebTest::class)->in('Feature/Controller/*.php');
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Functions
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| While Pest is very powerful out-of-the-box, you may have some testing code specific to your
|
||||
| project that you don't want to repeat in every file. Here you can also expose helpers as
|
||||
| global functions to help you to reduce the number of lines of code in your test files.
|
||||
|
|
||||
*/
|
||||
|
||||
function something(): void
|
||||
{
|
||||
// ..
|
||||
}
|
|
@ -1,10 +0,0 @@
|
|||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase as BaseTestCase;
|
||||
|
||||
abstract class TestCase extends BaseTestCase
|
||||
{
|
||||
//
|
||||
}
|
|
@ -1,32 +0,0 @@
|
|||
<?php declare(strict_types=1);
|
||||
|
||||
namespace App\Tests\Unit\Entity;
|
||||
|
||||
use App\Entity\FoodOrder;
|
||||
use App\Entity\OrderItem;
|
||||
|
||||
use function expect;
|
||||
use function test;
|
||||
|
||||
test('FoodOrder Entity', function (): void {
|
||||
$order = new FoodOrder;
|
||||
$orderItem = new OrderItem;
|
||||
expect($order->getOrderItems())
|
||||
->toBeEmpty();
|
||||
$order->addOrderItem($orderItem);
|
||||
$order->addOrderItem($orderItem);
|
||||
|
||||
expect($order->getOrderItems())
|
||||
->toHaveCount(1)
|
||||
->and($orderItem->getFoodOrder())
|
||||
->toBe($order);
|
||||
|
||||
$order->removeOrderItem($orderItem);
|
||||
|
||||
expect($order->getOrderItems())
|
||||
->toBeEmpty()
|
||||
->and($orderItem->getFoodOrder())
|
||||
->toBeNull();
|
||||
|
||||
})
|
||||
->covers(FoodOrder::class, OrderItem::class);
|
Loading…
Add table
Reference in a new issue