Compare commits
8 commits
Author | SHA1 | Date | |
---|---|---|---|
696760659f | |||
5a0df96142 | |||
b00b923d43 | |||
d92a63fd7d | |||
2b5d943116 | |||
9119029419 | |||
9c98735db7 | |||
af9354ff22 |
45 changed files with 4532 additions and 986 deletions
4
.env
4
.env
|
@ -28,3 +28,7 @@ DATABASE_URL="sqlite:///%kernel.project_dir%/var/data.db"
|
|||
# DATABASE_URL="mysql://app:!ChangeMe!@127.0.0.1:3306/app?serverVersion=10.11.2-MariaDB&charset=utf8mb4"
|
||||
# DATABASE_URL="postgresql://app:!ChangeMe!@127.0.0.1:5432/app?serverVersion=16&charset=utf8"
|
||||
###< doctrine/doctrine-bundle ###
|
||||
|
||||
###> nelmio/cors-bundle ###
|
||||
CORS_ALLOW_ORIGIN='^https?://(localhost|127\.0\.0\.1)(:[0-9]+)?$'
|
||||
###< nelmio/cors-bundle ###
|
||||
|
|
|
@ -4,4 +4,3 @@ 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,4 +1,3 @@
|
|||
|
||||
###> symfony/framework-bundle ###
|
||||
/.env.local
|
||||
/.env.local.php
|
||||
|
@ -8,17 +7,13 @@
|
|||
/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
23
bin/phpunit
|
@ -1,23 +0,0 @@
|
|||
#!/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';
|
||||
}
|
|
@ -7,18 +7,29 @@
|
|||
"php": ">=8.4",
|
||||
"ext-ctype": "*",
|
||||
"ext-iconv": "*",
|
||||
"api-platform/doctrine-orm": "^4.0",
|
||||
"api-platform/symfony": "^4.0",
|
||||
"doctrine/dbal": "^4.1",
|
||||
"doctrine/doctrine-bundle": "^2.12",
|
||||
"doctrine/doctrine-migrations-bundle": "^3.3.1",
|
||||
"doctrine/orm": "^3.2.1",
|
||||
"nelmio/cors-bundle": "^2.5",
|
||||
"phpdocumentor/reflection-docblock": "^5.6",
|
||||
"phpstan/phpdoc-parser": "^1.33",
|
||||
"psr/clock": "^1.0",
|
||||
"symfony/asset": "7.2.*",
|
||||
"symfony/console": "7.1.*",
|
||||
"symfony/dotenv": "7.1.*",
|
||||
"symfony/expression-language": "7.2.*",
|
||||
"symfony/flex": "^2.4.6",
|
||||
"symfony/form": "7.1.*",
|
||||
"symfony/framework-bundle": "7.1.*",
|
||||
"symfony/property-access": "7.2.*",
|
||||
"symfony/property-info": "7.2.*",
|
||||
"symfony/runtime": "7.1.*",
|
||||
"symfony/security-bundle": "7.2.*",
|
||||
"symfony/security-csrf": "7.1.*",
|
||||
"symfony/serializer": "7.2.*",
|
||||
"symfony/twig-bundle": "7.1.*",
|
||||
"symfony/uid": "7.1.*",
|
||||
"symfony/validator": "7.1.*",
|
||||
|
@ -26,22 +37,24 @@
|
|||
},
|
||||
"require-dev": {
|
||||
"doctrine/doctrine-fixtures-bundle": "^4.0",
|
||||
"liip/test-fixtures-bundle": "^3.2",
|
||||
"lubiana/code-quality": "^1.7.2",
|
||||
"phpunit/phpunit": "^9.6.20",
|
||||
"pestphp/pest": "^3.6",
|
||||
"symfony/browser-kit": "7.2.*",
|
||||
"symfony/css-selector": "7.2.*",
|
||||
"symfony/http-client": "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,
|
||||
"dealerdirect/phpcodesniffer-composer-installer": true
|
||||
"symfony/runtime": true
|
||||
},
|
||||
"sort-packages": true,
|
||||
"platform": {
|
||||
|
@ -85,7 +98,7 @@
|
|||
"rector",
|
||||
"ecs --fix || ecs --fix"
|
||||
],
|
||||
"test": "bin/phpunit"
|
||||
"test": "pest --parallel"
|
||||
},
|
||||
"conflict": {
|
||||
"symfony/symfony": "*"
|
||||
|
|
4316
composer.lock
generated
4316
composer.lock
generated
File diff suppressed because it is too large
Load diff
|
@ -1,10 +1,14 @@
|
|||
<?php declare(strict_types=1);
|
||||
|
||||
use ApiPlatform\Symfony\Bundle\ApiPlatformBundle;
|
||||
use Doctrine\Bundle\DoctrineBundle\DoctrineBundle;
|
||||
use Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle;
|
||||
use Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle;
|
||||
use Liip\TestFixturesBundle\LiipTestFixturesBundle;
|
||||
use Nelmio\CorsBundle\NelmioCorsBundle;
|
||||
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
|
||||
use Symfony\Bundle\MakerBundle\MakerBundle;
|
||||
use Symfony\Bundle\SecurityBundle\SecurityBundle;
|
||||
use Symfony\Bundle\TwigBundle\TwigBundle;
|
||||
use Symfony\Bundle\WebProfilerBundle\WebProfilerBundle;
|
||||
|
||||
|
@ -32,4 +36,17 @@ return [
|
|||
'dev' => true,
|
||||
'test' => true,
|
||||
],
|
||||
SecurityBundle::class => [
|
||||
'all' => true,
|
||||
],
|
||||
NelmioCorsBundle::class => [
|
||||
'all' => true,
|
||||
],
|
||||
ApiPlatformBundle::class => [
|
||||
'all' => true,
|
||||
],
|
||||
LiipTestFixturesBundle::class => [
|
||||
'dev' => true,
|
||||
'test' => true,
|
||||
],
|
||||
];
|
||||
|
|
22
config/packages/api_platform.php
Normal file
22
config/packages/api_platform.php
Normal file
|
@ -0,0 +1,22 @@
|
|||
<?php declare(strict_types=1);
|
||||
|
||||
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
|
||||
|
||||
return static function (ContainerConfigurator $containerConfigurator): void {
|
||||
$containerConfigurator->extension('api_platform', [
|
||||
'title' => 'Futtern API',
|
||||
'version' => '1.0.0',
|
||||
'show_webby' => false,
|
||||
'enable_swagger' => true,
|
||||
'defaults' => [
|
||||
'stateless' => true,
|
||||
'cache_headers' => [
|
||||
'vary' => [
|
||||
'Content-Type',
|
||||
'Authorization',
|
||||
'Origin',
|
||||
],
|
||||
],
|
||||
],
|
||||
]);
|
||||
};
|
33
config/packages/nelmio_cors.php
Normal file
33
config/packages/nelmio_cors.php
Normal file
|
@ -0,0 +1,33 @@
|
|||
<?php declare(strict_types=1);
|
||||
|
||||
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
|
||||
|
||||
return static function (ContainerConfigurator $containerConfigurator): void {
|
||||
$containerConfigurator->extension('nelmio_cors', [
|
||||
'defaults' => [
|
||||
'origin_regex' => true,
|
||||
'allow_origin' => [
|
||||
'%env(CORS_ALLOW_ORIGIN)%',
|
||||
],
|
||||
'allow_methods' => [
|
||||
'GET',
|
||||
'OPTIONS',
|
||||
'POST',
|
||||
'PUT',
|
||||
'PATCH',
|
||||
'DELETE',
|
||||
],
|
||||
'allow_headers' => [
|
||||
'Content-Type',
|
||||
'Authorization',
|
||||
],
|
||||
'expose_headers' => [
|
||||
'Link',
|
||||
],
|
||||
'max_age' => 3600,
|
||||
],
|
||||
'paths' => [
|
||||
'^/' => null,
|
||||
],
|
||||
]);
|
||||
};
|
40
config/packages/security.php
Normal file
40
config/packages/security.php
Normal file
|
@ -0,0 +1,40 @@
|
|||
<?php declare(strict_types=1);
|
||||
|
||||
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
|
||||
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
|
||||
|
||||
return static function (ContainerConfigurator $containerConfigurator): void {
|
||||
$containerConfigurator->extension('security', [
|
||||
'password_hashers' => [
|
||||
PasswordAuthenticatedUserInterface::class => 'auto',
|
||||
],
|
||||
'providers' => [
|
||||
'users_in_memory' => [
|
||||
'memory' => null,
|
||||
],
|
||||
],
|
||||
'firewalls' => [
|
||||
'dev' => [
|
||||
'pattern' => '^/(_(profiler|wdt)|css|images|js)/',
|
||||
'security' => false,
|
||||
],
|
||||
'main' => [
|
||||
'lazy' => true,
|
||||
'provider' => 'users_in_memory',
|
||||
],
|
||||
],
|
||||
'access_control' => null,
|
||||
]);
|
||||
if ($containerConfigurator->env() === 'test') {
|
||||
$containerConfigurator->extension('security', [
|
||||
'password_hashers' => [
|
||||
PasswordAuthenticatedUserInterface::class => [
|
||||
'algorithm' => 'auto',
|
||||
'cost' => 4,
|
||||
'time_cost' => 3,
|
||||
'memory_cost' => 10,
|
||||
],
|
||||
],
|
||||
]);
|
||||
}
|
||||
};
|
8
config/routes/api_platform.php
Normal file
8
config/routes/api_platform.php
Normal file
|
@ -0,0 +1,8 @@
|
|||
<?php declare(strict_types=1);
|
||||
|
||||
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;
|
||||
|
||||
return static function (RoutingConfigurator $routingConfigurator): void {
|
||||
$routingConfigurator->import('.', 'api_platform')
|
||||
->prefix('/api');
|
||||
};
|
7
config/routes/security.php
Normal file
7
config/routes/security.php
Normal file
|
@ -0,0 +1,7 @@
|
|||
<?php declare(strict_types=1);
|
||||
|
||||
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;
|
||||
|
||||
return static function (RoutingConfigurator $routingConfigurator): void {
|
||||
$routingConfigurator->import('security.route_loader.logout', 'service');
|
||||
};
|
|
@ -15,7 +15,6 @@ do
|
|||
cp -r ../../"$path" ./
|
||||
done
|
||||
|
||||
rm ./bin/phpunit
|
||||
APP_ENV=prod composer install --no-dev -a
|
||||
rm -rf ./var/cache
|
||||
|
||||
|
|
|
@ -26,12 +26,12 @@ ExecStart=/usr/bin/podman run \
|
|||
--replace \
|
||||
-d \
|
||||
--name futtern-php \
|
||||
--volume %h/futtern/etc/php83/php-fpm.d/www.conf:/etc/php83/php-fpm.d/www.conf \
|
||||
--volume %h/futtern/etc/php84/php-fpm.d/www.conf:/etc/php84/php-fpm.d/www.conf \
|
||||
--volume %h/futtern/app:/var/www/html \
|
||||
--volume %h/futtern/app/var:/var/www/html/var \
|
||||
--env APP_ENV=prod \
|
||||
--env APP_SECRET=UwUtHiSisNotSecurePlZcHanGeMe \
|
||||
git.php.fail/lubiana/container/php:8.3-fpm
|
||||
git.php.fail/lubiana/container/php:8.4-fpm
|
||||
ExecStop=/usr/bin/podman stop \
|
||||
--ignore -t 10 \
|
||||
--cidfile=%t/%n.ctr-id
|
||||
|
|
|
@ -1,20 +0,0 @@
|
|||
{
|
||||
"$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
Normal file
38
phpunit.xml
Normal file
|
@ -0,0 +1,38 @@
|
|||
<?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,9 +6,7 @@
|
|||
backupGlobals="false"
|
||||
colors="true"
|
||||
bootstrap="tests/bootstrap.php"
|
||||
convertDeprecationsToExceptions="true"
|
||||
executionOrder="random"
|
||||
resolveDependencies="true"
|
||||
convertDeprecationsToExceptions="false"
|
||||
>
|
||||
<php>
|
||||
<ini name="display_errors" value="1" />
|
||||
|
@ -16,8 +14,7 @@
|
|||
<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.6" />
|
||||
<server name="KERNEL_CLASS" value="App\Kernel" />
|
||||
<server name="SYMFONY_PHPUNIT_VERSION" value="9.5" />
|
||||
</php>
|
||||
|
||||
<testsuites>
|
||||
|
|
0
src/ApiResource/.gitignore
vendored
Normal file
0
src/ApiResource/.gitignore
vendored
Normal file
|
@ -2,8 +2,10 @@
|
|||
|
||||
namespace App\DataFixtures;
|
||||
|
||||
use App\Entity\FoodOrder;
|
||||
use App\Entity\FoodVendor;
|
||||
use App\Entity\MenuItem;
|
||||
use App\Entity\OrderItem;
|
||||
use Doctrine\Bundle\FixturesBundle\Fixture;
|
||||
use Doctrine\Persistence\ObjectManager;
|
||||
use Override;
|
||||
|
@ -39,12 +41,26 @@ final class AppFixtures extends Fixture
|
|||
|
||||
public function addMenuItemsToVendor(FoodVendor $vendor): void
|
||||
{
|
||||
$menuItems = [];
|
||||
foreach (range(1, 10) as $i) {
|
||||
$item = new MenuItem;
|
||||
$item->setName("{$vendor->getName()} Item {$i}");
|
||||
$item->setFoodVendor($vendor);
|
||||
$this->manager->persist($item);
|
||||
$this->manager->flush();
|
||||
$menuItems[] = $item;
|
||||
}
|
||||
|
||||
$order = new FoodOrder;
|
||||
$order->setFoodVendor($vendor);
|
||||
|
||||
$this->manager->persist($order);
|
||||
foreach ($menuItems as $item) {
|
||||
$orderItem = new OrderItem;
|
||||
$orderItem->setMenuItem($item);
|
||||
$orderItem->setCreatedBy('John');
|
||||
$order->addOrderItem($orderItem);
|
||||
$this->manager->persist($orderItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace App\Entity;
|
||||
|
||||
use ApiPlatform\Metadata\ApiResource;
|
||||
use App\Repository\FoodOrderRepository;
|
||||
use DateInterval;
|
||||
use DateTimeImmutable;
|
||||
|
@ -14,6 +15,7 @@ use Symfony\Component\Uid\Ulid;
|
|||
use function iterator_to_array;
|
||||
|
||||
#[ORM\Entity(repositoryClass: FoodOrderRepository::class)]
|
||||
#[ApiResource]
|
||||
class FoodOrder
|
||||
{
|
||||
#[ORM\Column(nullable: true)]
|
||||
|
@ -39,6 +41,7 @@ class FoodOrder
|
|||
#[ORM\Column(type: UlidType::NAME, unique: true)]
|
||||
private Ulid|null $id = new Ulid
|
||||
) {
|
||||
$this->id ??= new Ulid;
|
||||
$this->orderItems = new ArrayCollection;
|
||||
$this->open();
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace App\Entity;
|
||||
|
||||
use ApiPlatform\Metadata\ApiResource;
|
||||
use App\Repository\FoodVendorRepository;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
|
@ -11,6 +12,7 @@ use Symfony\Bridge\Doctrine\Types\UlidType;
|
|||
use Symfony\Component\Uid\Ulid;
|
||||
|
||||
#[ORM\Entity(repositoryClass: FoodVendorRepository::class)]
|
||||
#[ApiResource]
|
||||
class FoodVendor
|
||||
{
|
||||
#[ORM\Column(length: 50)]
|
||||
|
@ -43,6 +45,7 @@ class FoodVendor
|
|||
#[ORM\CustomIdGenerator(class: UlidGenerator::class)]
|
||||
private Ulid|null $id = new Ulid
|
||||
) {
|
||||
$this->id ??= new Ulid;
|
||||
$this->foodOrders = new ArrayCollection;
|
||||
$this->menuItems = new ArrayCollection;
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace App\Entity;
|
||||
|
||||
use ApiPlatform\Metadata\ApiResource;
|
||||
use App\Repository\MenuItemRepository;
|
||||
use DateTimeImmutable;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
|
@ -12,6 +13,7 @@ use Symfony\Bridge\Doctrine\Types\UlidType;
|
|||
use Symfony\Component\Uid\Ulid;
|
||||
|
||||
#[ORM\Entity(repositoryClass: MenuItemRepository::class)]
|
||||
#[ApiResource]
|
||||
class MenuItem
|
||||
{
|
||||
#[ORM\Column(length: 255)]
|
||||
|
@ -40,6 +42,7 @@ class MenuItem
|
|||
#[ORM\CustomIdGenerator(class: UlidGenerator::class)]
|
||||
private Ulid|null $id = new Ulid
|
||||
) {
|
||||
$this->id ??= new Ulid;
|
||||
$this->aliases = new ArrayCollection;
|
||||
}
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace App\Entity;
|
||||
|
||||
use ApiPlatform\Metadata\ApiResource;
|
||||
use App\Repository\OrderItemRepository;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Bridge\Doctrine\IdGenerator\UlidGenerator;
|
||||
|
@ -9,14 +10,9 @@ use Symfony\Bridge\Doctrine\Types\UlidType;
|
|||
use Symfony\Component\Uid\Ulid;
|
||||
|
||||
#[ORM\Entity(repositoryClass: OrderItemRepository::class)]
|
||||
#[ApiResource]
|
||||
class OrderItem
|
||||
{
|
||||
#[ORM\Id]
|
||||
#[ORM\GeneratedValue(strategy: 'CUSTOM')]
|
||||
#[ORM\Column(type: UlidType::NAME, unique: true)]
|
||||
#[ORM\CustomIdGenerator(class: UlidGenerator::class)]
|
||||
private Ulid|null $id = null;
|
||||
|
||||
#[ORM\Column(length: 255)]
|
||||
private string|null $name = null;
|
||||
|
||||
|
@ -36,6 +32,16 @@ class OrderItem
|
|||
])]
|
||||
private string|null $createdBy = 'nobody';
|
||||
|
||||
public function __construct(
|
||||
#[ORM\Id]
|
||||
#[ORM\GeneratedValue(strategy: 'CUSTOM')]
|
||||
#[ORM\Column(type: UlidType::NAME, unique: true)]
|
||||
#[ORM\CustomIdGenerator(class: UlidGenerator::class)]
|
||||
private Ulid|null $id = new Ulid
|
||||
) {
|
||||
$this->id ??= new Ulid;
|
||||
}
|
||||
|
||||
public function getId(): Ulid|null
|
||||
{
|
||||
return $this->id;
|
||||
|
@ -85,6 +91,7 @@ class OrderItem
|
|||
public function setMenuItem(MenuItem|null $menuItem): static
|
||||
{
|
||||
$this->menuItem = $menuItem;
|
||||
$this->name = $menuItem->getName();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
|
|
@ -14,15 +14,12 @@ 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,4 +8,15 @@ 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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
59
symfony.lock
59
symfony.lock
|
@ -1,4 +1,18 @@
|
|||
{
|
||||
"api-platform/symfony": {
|
||||
"version": "4.0",
|
||||
"recipe": {
|
||||
"repo": "github.com/symfony/recipes",
|
||||
"branch": "main",
|
||||
"version": "4.0",
|
||||
"ref": "e9952e9f393c2d048f10a78f272cd35e807d972b"
|
||||
},
|
||||
"files": [
|
||||
"config/packages/api_platform.yaml",
|
||||
"config/routes/api_platform.yaml",
|
||||
"src/ApiResource/.gitignore"
|
||||
]
|
||||
},
|
||||
"doctrine/doctrine-bundle": {
|
||||
"version": "2.12",
|
||||
"recipe": {
|
||||
|
@ -38,6 +52,21 @@
|
|||
"migrations/.gitignore"
|
||||
]
|
||||
},
|
||||
"liip/test-fixtures-bundle": {
|
||||
"version": "3.2.1"
|
||||
},
|
||||
"nelmio/cors-bundle": {
|
||||
"version": "2.5",
|
||||
"recipe": {
|
||||
"repo": "github.com/symfony/recipes",
|
||||
"branch": "main",
|
||||
"version": "1.5",
|
||||
"ref": "6bea22e6c564fba3a1391615cada1437d0bde39c"
|
||||
},
|
||||
"files": [
|
||||
"config/packages/nelmio_cors.yaml"
|
||||
]
|
||||
},
|
||||
"phpstan/phpstan": {
|
||||
"version": "1.11",
|
||||
"recipe": {
|
||||
|
@ -48,7 +77,7 @@
|
|||
}
|
||||
},
|
||||
"phpunit/phpunit": {
|
||||
"version": "9.6",
|
||||
"version": "11.4",
|
||||
"recipe": {
|
||||
"repo": "github.com/symfony/recipes",
|
||||
"branch": "main",
|
||||
|
@ -122,21 +151,6 @@
|
|||
"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": {
|
||||
|
@ -150,6 +164,19 @@
|
|||
"config/routes.yaml"
|
||||
]
|
||||
},
|
||||
"symfony/security-bundle": {
|
||||
"version": "7.2",
|
||||
"recipe": {
|
||||
"repo": "github.com/symfony/recipes",
|
||||
"branch": "main",
|
||||
"version": "6.4",
|
||||
"ref": "2ae08430db28c8eb4476605894296c82a642028f"
|
||||
},
|
||||
"files": [
|
||||
"config/packages/security.yaml",
|
||||
"config/routes/security.yaml"
|
||||
]
|
||||
},
|
||||
"symfony/twig-bundle": {
|
||||
"version": "7.1",
|
||||
"recipe": {
|
||||
|
|
|
@ -34,7 +34,8 @@
|
|||
<a
|
||||
href="https://git.hannover.ccc.de/lubiana/futtern/issues/new"
|
||||
target="_blank"
|
||||
>Create Issue</a>
|
||||
>Create Issue</a> /
|
||||
<a href="/api">API</a>
|
||||
</nav>
|
||||
</header>
|
||||
<main>
|
||||
|
|
|
@ -40,6 +40,7 @@
|
|||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Index</th>
|
||||
<th>username</th>
|
||||
<th>name</th>
|
||||
<th>extras</th>
|
||||
|
@ -49,6 +50,7 @@
|
|||
<tbody>
|
||||
{% for item in food_order.orderItemsSortedByName %}
|
||||
<tr>
|
||||
<td>{{ loop.index }}</td>
|
||||
<td>{{ item.createdBy }}</td>
|
||||
<td>{{ item.name }}</td>
|
||||
<td>{{ item.extras }}</td>
|
||||
|
|
|
@ -1,76 +0,0 @@
|
|||
<?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 '';
|
||||
}
|
||||
}
|
26
tests/DbApiTestCase.php
Normal file
26
tests/DbApiTestCase.php
Normal file
|
@ -0,0 +1,26 @@
|
|||
<?php declare(strict_types=1);
|
||||
|
||||
namespace App\Tests;
|
||||
|
||||
use ApiPlatform\Symfony\Bundle\Test\ApiTestCase;
|
||||
use ApiPlatform\Symfony\Bundle\Test\Client;
|
||||
use App\DataFixtures\AppFixtures;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Liip\TestFixturesBundle\Services\DatabaseToolCollection;
|
||||
use Override;
|
||||
|
||||
abstract class DbApiTestCase extends ApiTestCase
|
||||
{
|
||||
protected EntityManagerInterface $manager;
|
||||
protected Client $client;
|
||||
|
||||
#[Override]
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->client = static::createClient();
|
||||
$this->manager = static::getContainer()->get('doctrine')->getManager();
|
||||
$toolKit = self::getContainer()->get(DatabaseToolCollection::class)->get();
|
||||
$toolKit->loadFixtures([AppFixtures::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,10 +33,6 @@ 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
|
||||
|
@ -56,4 +52,15 @@ 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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,24 +0,0 @@
|
|||
<?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());
|
||||
}
|
||||
}
|
15
tests/Feature/Api/ApiSmokeTest.php
Normal file
15
tests/Feature/Api/ApiSmokeTest.php
Normal file
|
@ -0,0 +1,15 @@
|
|||
<?php declare(strict_types=1);
|
||||
|
||||
test('orders', function (): void {
|
||||
$response = $this->client->request('GET', '/api/food_orders');
|
||||
$this->assertResponseIsSuccessful();
|
||||
$this->assertResponseHeaderSame('content-type', 'application/ld+json; charset=utf-8');
|
||||
$this->assertJsonContains([
|
||||
'@context' => '/api/contexts/FoodOrder',
|
||||
'@id' => '/api/food_orders',
|
||||
'@type' => 'Collection',
|
||||
'totalItems' => 1,
|
||||
]);
|
||||
$array = $response->toArray();
|
||||
expect($array['member'][0]['orderItems'])->toHaveCount(10);
|
||||
});
|
|
@ -1,45 +1,40 @@
|
|||
<?php declare(strict_types=1);
|
||||
|
||||
namespace App\Tests\Controller;
|
||||
namespace App\Tests\Feature\Controller;
|
||||
|
||||
use App\Controller\FoodOrderController;
|
||||
use App\Entity\FoodOrder;
|
||||
use App\Entity\FoodVendor;
|
||||
use App\Entity\MenuItem;
|
||||
use App\Entity\OrderItem;
|
||||
use App\Tests\DbWebTest;
|
||||
use Override;
|
||||
use App\Form\FoodOrderType;
|
||||
use App\Repository\FoodOrderRepository;
|
||||
use App\Repository\FoodVendorRepository;
|
||||
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;
|
||||
|
||||
final class FoodOrderControllerTest extends DbWebTest
|
||||
{
|
||||
private string $path = '/food/order/';
|
||||
private FoodVendor $vendor;
|
||||
|
||||
#[Override]
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
pest()
|
||||
->beforeEach(function (): void {
|
||||
$this->setEntityClass(FoodOrder::class);
|
||||
$this->setPath('/food/order/');
|
||||
$this->repository = $this->manager->getRepository($this->entityClass);
|
||||
$this->vendor = new FoodVendor;
|
||||
$this->vendor->setName('Food Vendor');
|
||||
|
||||
$this->manager->persist($this->vendor);
|
||||
$this->manager->flush();
|
||||
}
|
||||
});
|
||||
|
||||
#[Override]
|
||||
public function getEntityClass(): string
|
||||
{
|
||||
return FoodOrder::class;
|
||||
}
|
||||
|
||||
public function testIndex(): void
|
||||
{
|
||||
describe(FoodOrderController::class, function (): void {
|
||||
test('index', function (): void {
|
||||
$order = new FoodOrder;
|
||||
$order->setFoodVendor($this->vendor);
|
||||
|
||||
|
@ -48,17 +43,16 @@ final class FoodOrderControllerTest extends DbWebTest
|
|||
$this->manager->flush();
|
||||
|
||||
$crawler = $this->client->request('GET', "{$this->path}list");
|
||||
self::assertResponseStatusCodeSame(200);
|
||||
self::assertPageTitleContains('FoodOrder index');
|
||||
$this->assertResponseStatusCodeSame(200);
|
||||
$this->assertPageTitleContains('FoodOrder index');
|
||||
$this->assertCount(
|
||||
1,
|
||||
$crawler->filter('td')
|
||||
->reduce(fn(Crawler $node, $i): bool => $node->text() === $this->vendor->getName()),
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
public function testOrderedItems(): void
|
||||
{
|
||||
test('orderedItems', function (): void {
|
||||
$order = new FoodOrder;
|
||||
$order->setFoodVendor($this->vendor);
|
||||
|
||||
|
@ -104,7 +98,7 @@ final class FoodOrderControllerTest extends DbWebTest
|
|||
$this->manager->flush();
|
||||
|
||||
$crawler = $this->client->request('GET', "{$this->path}{$order->getId()}");
|
||||
self::assertResponseIsSuccessful();
|
||||
$this->assertResponseIsSuccessful();
|
||||
$tdContent = $crawler->filter(
|
||||
'table.table:nth-child(6) > tbody:nth-child(2) > tr:nth-child(1) > td:nth-child(2)'
|
||||
)->text();
|
||||
|
@ -117,14 +111,20 @@ final class FoodOrderControllerTest extends DbWebTest
|
|||
'table.table:nth-child(6) > tbody:nth-child(2) > tr:nth-child(3) > td:nth-child(2)'
|
||||
)->text();
|
||||
$this->assertEquals('C', $tdContent);
|
||||
}
|
||||
});
|
||||
|
||||
public function testPaginatedIndex(): void
|
||||
{
|
||||
$this->generatePaginatedOrders();
|
||||
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();
|
||||
$crawler = $this->client->request('GET', "{$this->path}list");
|
||||
self::assertResponseStatusCodeSame(200);
|
||||
self::assertPageTitleContains('FoodOrder index');
|
||||
$this->assertResponseStatusCodeSame(200);
|
||||
$this->assertPageTitleContains('FoodOrder index');
|
||||
$this->assertElementContainsCount(
|
||||
$crawler,
|
||||
'td',
|
||||
|
@ -137,20 +137,20 @@ final class FoodOrderControllerTest extends DbWebTest
|
|||
0,
|
||||
'next page'
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @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();
|
||||
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();
|
||||
$crawler = $this->client->request('GET', "{$this->path}list/archive/{$page}");
|
||||
self::assertResponseStatusCodeSame(200);
|
||||
self::assertPageTitleContains('FoodOrder index');
|
||||
$this->assertResponseStatusCodeSame(200);
|
||||
$this->assertPageTitleContains('FoodOrder index');
|
||||
$this->assertElementContainsCount(
|
||||
$crawler,
|
||||
'td',
|
||||
|
@ -172,30 +172,36 @@ final class FoodOrderControllerTest extends DbWebTest
|
|||
$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],
|
||||
]
|
||||
);
|
||||
|
||||
public function testNew(): void
|
||||
{
|
||||
test('new', function (): void {
|
||||
$this->client->getCookieJar()
|
||||
->set(new Cookie('username', 'Testing-1'));
|
||||
$this->client->request('GET', sprintf('%snew', $this->path));
|
||||
|
||||
self::assertResponseStatusCodeSame(200);
|
||||
$this->assertResponseStatusCodeSame(200);
|
||||
|
||||
$this->client->submitForm('Save', [
|
||||
'food_order[foodVendor]' => $this->vendor->getId(),
|
||||
]);
|
||||
|
||||
self::assertResponseRedirects("{$this->path}list");
|
||||
self::assertSame(1, $this->repository->count([]));
|
||||
$this->assertResponseRedirects("{$this->path}list");
|
||||
$this->assertSame(1, $this->repository->count([]));
|
||||
$order = $this->repository->findOneBy([
|
||||
'createdBy' => 'Testing-1',
|
||||
]);
|
||||
assert($order instanceof FoodOrder);
|
||||
}
|
||||
});
|
||||
|
||||
public function testOpen(): void
|
||||
{
|
||||
test('open', function (): void {
|
||||
$order = new FoodOrder;
|
||||
$order->setFoodVendor($this->vendor);
|
||||
$order->close();
|
||||
|
@ -205,13 +211,12 @@ final class FoodOrderControllerTest extends DbWebTest
|
|||
$this->manager->flush();
|
||||
|
||||
$this->client->request('GET', sprintf('%s%s/open', $this->path, $order->getId()));
|
||||
self::assertResponseRedirects("{$this->path}{$order->getId()}");
|
||||
$this->assertResponseRedirects("{$this->path}{$order->getId()}");
|
||||
$openOrder = $this->repository->find($order->getId());
|
||||
$this->assertFalse($openOrder->isClosed());
|
||||
}
|
||||
});
|
||||
|
||||
public function testClose(): void
|
||||
{
|
||||
test('close', function (): void {
|
||||
$order = new FoodOrder;
|
||||
$order->setClosedAt();
|
||||
$order->setFoodVendor($this->vendor);
|
||||
|
@ -221,20 +226,19 @@ final class FoodOrderControllerTest extends DbWebTest
|
|||
$this->manager->flush();
|
||||
|
||||
$this->client->request('GET', sprintf('%s%s/close', $this->path, $order->getId()));
|
||||
self::assertResponseRedirects("{$this->path}{$order->getId()}");
|
||||
$this->assertResponseRedirects("{$this->path}{$order->getId()}");
|
||||
$openOrder = $this->repository->find($order->getId());
|
||||
$this->assertTrue($openOrder->isClosed());
|
||||
}
|
||||
});
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
})
|
||||
->covers(
|
||||
FoodOrderController::class,
|
||||
FoodOrder::class,
|
||||
FoodVendor::class,
|
||||
FoodOrderRepository::class,
|
||||
MenuItem::class,
|
||||
OrderItem::class,
|
||||
FoodOrderType::class,
|
||||
FoodVendorRepository::class
|
||||
);
|
|
@ -1,32 +1,42 @@
|
|||
<?php declare(strict_types=1);
|
||||
|
||||
namespace App\Tests\Controller;
|
||||
namespace App\Tests\Feature\Controller;
|
||||
|
||||
use App\Controller\FoodVendorController;
|
||||
use App\Entity\FoodOrder;
|
||||
use App\Entity\FoodVendor;
|
||||
use App\Entity\MenuItem;
|
||||
use App\Tests\DbWebTest;
|
||||
use Override;
|
||||
use App\Entity\OrderItem;
|
||||
use App\Form\FoodOrderType;
|
||||
use App\Form\FoodVendorType;
|
||||
use App\Repository\FoodOrderRepository;
|
||||
use App\Repository\FoodVendorRepository;
|
||||
|
||||
use function describe;
|
||||
use function pest;
|
||||
use function sprintf;
|
||||
use function test;
|
||||
|
||||
final class FoodVendorControllerTest extends DbWebTest
|
||||
{
|
||||
private string $path = '/food/vendor/';
|
||||
pest()
|
||||
->beforeEach(function (): void {
|
||||
$this->setEntityClass(FoodVendor::class);
|
||||
$this->setPath('/food/vendor/');
|
||||
$this->repository = $this->manager->getRepository($this->entityClass);
|
||||
});
|
||||
|
||||
public function testIndex(): void
|
||||
{
|
||||
describe(FoodVendorController::class, function (): void {
|
||||
test('index', function (): void {
|
||||
$this->client->request('GET', $this->path);
|
||||
|
||||
self::assertResponseStatusCodeSame(200);
|
||||
self::assertPageTitleContains('FoodVendor index');
|
||||
}
|
||||
$this->assertResponseStatusCodeSame(200);
|
||||
$this->assertPageTitleContains('FoodVendor index');
|
||||
});
|
||||
|
||||
public function testNew(): void
|
||||
{
|
||||
self::assertSame(0, $this->repository->count([]));
|
||||
test('new', function (): void {
|
||||
$this->assertSame(0, $this->repository->count([]));
|
||||
$this->client->request('GET', sprintf('%snew', $this->path));
|
||||
|
||||
self::assertResponseStatusCodeSame(200);
|
||||
$this->assertResponseStatusCodeSame(200);
|
||||
|
||||
$this->client->submitForm('Save', [
|
||||
'food_vendor[name]' => 'TestingNew',
|
||||
|
@ -36,12 +46,11 @@ final class FoodVendorControllerTest extends DbWebTest
|
|||
'name' => 'TestingNew',
|
||||
]);
|
||||
$this->assertInstanceof(FoodVendor::class, $newVendor);
|
||||
self::assertSame(1, $this->repository->count([]));
|
||||
$this->assertSame(1, $this->repository->count([]));
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
public function testShow(): void
|
||||
{
|
||||
test('show', function (): void {
|
||||
$fixture = new FoodVendor;
|
||||
$fixture->setName('My Title');
|
||||
$fixture->setMenuLink('https://example.com/');
|
||||
|
@ -63,10 +72,9 @@ final class FoodVendorControllerTest extends DbWebTest
|
|||
)->text();
|
||||
$this->assertSame('My Title', $nameNode);
|
||||
$this->assertSame('https://example.com/', $menuLinkNode);
|
||||
}
|
||||
});
|
||||
|
||||
public function testShowMenuItems(): void
|
||||
{
|
||||
test('show with menu items', function (): void {
|
||||
$fixture = new FoodVendor;
|
||||
$fixture->setName('My Title');
|
||||
|
||||
|
@ -114,10 +122,9 @@ final class FoodVendorControllerTest extends DbWebTest
|
|||
$itemNodes = $crawler->filter('li');
|
||||
|
||||
$this->assertCount(4, $itemNodes);
|
||||
}
|
||||
});
|
||||
|
||||
public function testEdit(): void
|
||||
{
|
||||
test('edit', function (): void {
|
||||
$fixture = new FoodVendor;
|
||||
$fixture->setName('Value');
|
||||
$fixture->setMenuLink('Value');
|
||||
|
@ -152,18 +159,26 @@ final class FoodVendorControllerTest extends DbWebTest
|
|||
'food_vendor[phone]' => '1234567890',
|
||||
]);
|
||||
|
||||
self::assertResponseRedirects('/food/vendor/');
|
||||
$this->assertResponseRedirects('/food/vendor/');
|
||||
|
||||
$fixture = $this->repository->findAll();
|
||||
|
||||
self::assertSame('Something New', $fixture[0]->getName());
|
||||
self::assertSame('https://example.com/', $fixture[0]->getMenuLink());
|
||||
self::assertSame('1234567890', $fixture[0]->getPhone());
|
||||
}
|
||||
$this->assertSame('Something New', $fixture[0]->getName());
|
||||
$this->assertSame('https://example.com/', $fixture[0]->getMenuLink());
|
||||
$this->assertSame('1234567890', $fixture[0]->getPhone());
|
||||
});
|
||||
|
||||
#[Override]
|
||||
public function getEntityClass(): string
|
||||
{
|
||||
return FoodVendor::class;
|
||||
}
|
||||
}
|
||||
})
|
||||
->covers(
|
||||
FoodOrder::class,
|
||||
FoodVendor::class,
|
||||
FoodOrderRepository::class,
|
||||
MenuItem::class,
|
||||
OrderItem::class,
|
||||
FoodOrderType::class,
|
||||
FoodVendorRepository::class,
|
||||
FoodVendorController::class,
|
||||
FoodVendorType::class
|
||||
)
|
||||
|
||||
;
|
71
tests/Feature/Controller/HomeControllerTest.php
Normal file
71
tests/Feature/Controller/HomeControllerTest.php
Normal file
|
@ -0,0 +1,71 @@
|
|||
<?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,32 +1,34 @@
|
|||
<?php declare(strict_types=1);
|
||||
|
||||
namespace App\Tests\Controller;
|
||||
namespace App\Tests\Feature\Controller;
|
||||
|
||||
use App\Controller\MenuItemController;
|
||||
use App\Controller\OrderItemController;
|
||||
use App\Entity\FoodOrder;
|
||||
use App\Entity\FoodVendor;
|
||||
use App\Entity\MenuItem;
|
||||
use App\Tests\DbWebTest;
|
||||
use Override;
|
||||
use App\Entity\OrderItem;
|
||||
use App\Form\MenuItemType;
|
||||
use App\Form\OrderItemType;
|
||||
use App\Repository\FoodOrderRepository;
|
||||
use App\Repository\MenuItemRepository;
|
||||
|
||||
use function describe;
|
||||
use function pest;
|
||||
use function sprintf;
|
||||
use function test;
|
||||
|
||||
final class MenuItemControllerTest extends DbWebTest
|
||||
{
|
||||
private string $path = '/menu/item/';
|
||||
private FoodVendor $vendor;
|
||||
private MenuItem $menuItem;
|
||||
private MenuItem $aliasOne;
|
||||
private MenuItem $aliasTwo;
|
||||
pest()
|
||||
->beforeEach(function (): void {
|
||||
$this->setEntityClass(MenuItem::class);
|
||||
$this->setPath('/menu/item/');
|
||||
|
||||
$this->repository = $this->manager->getRepository($this->entityClass);
|
||||
|
||||
#[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');
|
||||
|
||||
|
@ -52,16 +54,10 @@ final class MenuItemControllerTest extends DbWebTest
|
|||
$this->manager->persist($this->menuItem);
|
||||
$this->manager->flush();
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
#[Override]
|
||||
public function getEntityClass(): string
|
||||
{
|
||||
return MenuItem::class;
|
||||
}
|
||||
|
||||
public function testShow(): void
|
||||
{
|
||||
describe(MenuItemController::class, function (): void {
|
||||
test('show', function (): void {
|
||||
|
||||
$crawler = $this->client->request('GET', "{$this->path}{$this->menuItem->getId()}");
|
||||
$idValue = $crawler->filter(
|
||||
|
@ -77,15 +73,14 @@ final class MenuItemControllerTest extends DbWebTest
|
|||
$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();
|
||||
self::assertResponseStatusCodeSame(200);
|
||||
$this->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());
|
||||
}
|
||||
});
|
||||
|
||||
public function testEdit(): void
|
||||
{
|
||||
test('edit', function (): void {
|
||||
$crawler = $this->client->request('GET', sprintf('%s%s/edit', $this->path, $this->menuItem->getId()));
|
||||
$nameElem = $crawler->filter('#menu_item_name');
|
||||
$this->assertEquals(
|
||||
|
@ -100,16 +95,15 @@ final class MenuItemControllerTest extends DbWebTest
|
|||
|
||||
$this->client->submit($form);
|
||||
|
||||
self::assertResponseRedirects(sprintf('/menu/item/%s', $this->menuItem->getId()));
|
||||
$this->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());
|
||||
}
|
||||
});
|
||||
|
||||
public function testEditInvalid(): void
|
||||
{
|
||||
test('edit invalid', function (): void {
|
||||
$crawler = $this->client->request('GET', sprintf('%s%s/edit', $this->path, $this->menuItem->getId()));
|
||||
$nameElem = $crawler->filter('#menu_item_name');
|
||||
$this->assertEquals(
|
||||
|
@ -123,11 +117,10 @@ final class MenuItemControllerTest extends DbWebTest
|
|||
|
||||
$this->client->submit($form);
|
||||
|
||||
self::assertResponseStatusCodeSame(422);
|
||||
}
|
||||
$this->assertResponseStatusCodeSame(422);
|
||||
});
|
||||
|
||||
public function testDelete(): void
|
||||
{
|
||||
test('delete', function (): void {
|
||||
$order = new FoodOrder;
|
||||
$order->setFoodVendor($this->vendor);
|
||||
|
||||
|
@ -150,5 +143,17 @@ final class MenuItemControllerTest extends DbWebTest
|
|||
|
||||
$this->assertResponseIsSuccessful();
|
||||
|
||||
}
|
||||
}
|
||||
});
|
||||
})
|
||||
->covers(
|
||||
MenuItemController::class,
|
||||
OrderItemController::class,
|
||||
OrderItemType::class,
|
||||
MenuItemRepository::class,
|
||||
FoodOrder::class,
|
||||
FoodVendor::class,
|
||||
MenuItem::class,
|
||||
OrderItem::class,
|
||||
FoodOrderRepository::class,
|
||||
MenuItemType::class,
|
||||
);
|
|
@ -1,30 +1,29 @@
|
|||
<?php declare(strict_types=1);
|
||||
|
||||
namespace App\Tests\Controller;
|
||||
namespace App\Tests\Feature\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\Tests\DbWebTest;
|
||||
use App\Repository\OrderItemRepository;
|
||||
use DateTimeImmutable;
|
||||
use Override;
|
||||
|
||||
use function describe;
|
||||
use function pest;
|
||||
use function sprintf;
|
||||
use function test;
|
||||
|
||||
final class OrderItemControllerTest extends DbWebTest
|
||||
{
|
||||
public FoodVendor $vendor;
|
||||
public FoodOrder $order;
|
||||
public Menuitem $menuItem;
|
||||
public MenuItemRepository $menuItemRepository;
|
||||
private string $path = '/order/item/';
|
||||
pest()
|
||||
->beforeEach(function (): void {
|
||||
$this->setEntityClass(OrderItem::class);
|
||||
$this->setPath('/order/item/');
|
||||
$this->repository = $this->manager->getRepository($this->entityClass);
|
||||
|
||||
#[Override]
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->vendor = new FoodVendor;
|
||||
$this->vendor->setName('Food Vendor');
|
||||
|
||||
|
@ -51,11 +50,11 @@ final class OrderItemControllerTest extends DbWebTest
|
|||
$this->manager->persist($this->menuItem);
|
||||
$this->manager->flush();
|
||||
|
||||
$this->menuItemRepository = static::getContainer()->get(MenuItemRepository::class);
|
||||
}
|
||||
$this->menuItemRepository = $this::getContainer()->get(MenuItemRepository::class);
|
||||
});
|
||||
|
||||
public function testNew(): void
|
||||
{
|
||||
describe(OrderItemController::class, function (): void {
|
||||
test('new', function (): void {
|
||||
$crawler = $this->client->request(
|
||||
'GET',
|
||||
sprintf('%snew/%s', $this->path, $this->order->getId())
|
||||
|
@ -66,23 +65,22 @@ final class OrderItemControllerTest extends DbWebTest
|
|||
|
||||
$this->assertCount(1, $children);
|
||||
|
||||
self::assertResponseStatusCodeSame(200);
|
||||
$this->assertResponseStatusCodeSame(200);
|
||||
|
||||
$this->client->submitForm('Save', [
|
||||
'order_item[name]' => 'Testing',
|
||||
'order_item[extras]' => 'Testing',
|
||||
]);
|
||||
|
||||
self::assertResponseRedirects(sprintf('/food/order/%s', $this->order->getId()));
|
||||
$this->assertResponseRedirects(sprintf('/food/order/%s', $this->order->getId()));
|
||||
|
||||
self::assertSame(1, $this->repository->count([]));
|
||||
self::assertSame(1, $this->menuItemRepository->count([
|
||||
$this->assertSame(1, $this->repository->count([]));
|
||||
$this->assertSame(1, $this->menuItemRepository->count([
|
||||
'foodVendor' => $this->vendor->getId(),
|
||||
]));
|
||||
}
|
||||
});
|
||||
|
||||
public function testNewOrderClosed(): void
|
||||
{
|
||||
test('new order closed', function (): void {
|
||||
|
||||
$this->order->setClosedAt(new DateTimeImmutable('-1 Hour'));
|
||||
$this->manager->persist($this->order);
|
||||
|
@ -93,33 +91,31 @@ final class OrderItemControllerTest extends DbWebTest
|
|||
sprintf('%snew/%s', $this->path, $this->order->getId())
|
||||
);
|
||||
|
||||
self::assertResponseRedirects(sprintf('/food/order/%s', $this->order->getId()));
|
||||
$this->assertResponseRedirects(sprintf('/food/order/%s', $this->order->getId()));
|
||||
|
||||
self::assertSame(0, $this->repository->count([]));
|
||||
}
|
||||
$this->assertSame(0, $this->repository->count([]));
|
||||
});
|
||||
|
||||
public function testNewCreateMenuItem(): void
|
||||
{
|
||||
test('new create menu item', function (): void {
|
||||
$this->client->request(
|
||||
'GET',
|
||||
sprintf('%snew/%s', $this->path, $this->order->getId())
|
||||
);
|
||||
|
||||
self::assertResponseStatusCodeSame(200);
|
||||
$this->assertResponseStatusCodeSame(200);
|
||||
|
||||
$this->client->submitForm('Save', [
|
||||
'order_item[name]' => 'Testing-1',
|
||||
'order_item[extras]' => 'Testing-1',
|
||||
]);
|
||||
|
||||
self::assertResponseRedirects(sprintf('/food/order/%s', $this->order->getId()));
|
||||
$this->assertResponseRedirects(sprintf('/food/order/%s', $this->order->getId()));
|
||||
|
||||
self::assertSame(1, $this->repository->count([]));
|
||||
self::assertSame(3, $this->menuItemRepository->count([]));
|
||||
}
|
||||
$this->assertSame(1, $this->repository->count([]));
|
||||
$this->assertSame(3, $this->menuItemRepository->count([]));
|
||||
});
|
||||
|
||||
public function testRemove(): void
|
||||
{
|
||||
test('remove', function (): void {
|
||||
$fixture = new OrderItem;
|
||||
$fixture->setName('Testing');
|
||||
$fixture->setExtras('Value');
|
||||
|
@ -132,12 +128,11 @@ final class OrderItemControllerTest extends DbWebTest
|
|||
|
||||
$this->client->request('GET', sprintf('%sdelete/%s', $this->path, $fixture->getId()));
|
||||
|
||||
self::assertResponseRedirects(sprintf('/food/order/%s', $this->order->getId()));
|
||||
self::assertSame(0, $this->repository->count([]));
|
||||
}
|
||||
$this->assertResponseRedirects(sprintf('/food/order/%s', $this->order->getId()));
|
||||
$this->assertSame(0, $this->repository->count([]));
|
||||
});
|
||||
|
||||
public function testOrderClosed(): void
|
||||
{
|
||||
test('order closed', function (): void {
|
||||
$fixture = new OrderItem;
|
||||
$fixture->setName('Testing');
|
||||
$fixture->setExtras('Value');
|
||||
|
@ -152,12 +147,11 @@ final class OrderItemControllerTest extends DbWebTest
|
|||
|
||||
$this->client->request('GET', sprintf('%sdelete/%s', $this->path, $fixture->getId()));
|
||||
|
||||
self::assertResponseRedirects(sprintf('/food/order/%s', $this->order->getId()));
|
||||
self::assertSame(1, $this->repository->count([]));
|
||||
}
|
||||
$this->assertResponseRedirects(sprintf('/food/order/%s', $this->order->getId()));
|
||||
$this->assertSame(1, $this->repository->count([]));
|
||||
});
|
||||
|
||||
public function testEdit(): void
|
||||
{
|
||||
test('edit', function (): void {
|
||||
$orderItem = new OrderItem;
|
||||
$orderItem->setName('Testing');
|
||||
$orderItem->setExtras('My Extra');
|
||||
|
@ -185,15 +179,14 @@ final class OrderItemControllerTest extends DbWebTest
|
|||
'order_item[extras]' => 'Testing-1',
|
||||
]);
|
||||
|
||||
self::assertResponseRedirects(sprintf('/food/order/%s', $this->order->getId()));
|
||||
$this->assertResponseRedirects(sprintf('/food/order/%s', $this->order->getId()));
|
||||
|
||||
self::assertSame(1, $this->repository->count([]));
|
||||
self::assertSame(3, $this->menuItemRepository->count([]));
|
||||
$this->assertSame(1, $this->repository->count([]));
|
||||
$this->assertSame(3, $this->menuItemRepository->count([]));
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
public function testEditOrderClosed(): void
|
||||
{
|
||||
test('edit order closed', function (): void {
|
||||
$orderItem = new OrderItem;
|
||||
$orderItem->setName('Testing');
|
||||
$orderItem->setExtras('My Extra');
|
||||
|
@ -207,11 +200,10 @@ final class OrderItemControllerTest extends DbWebTest
|
|||
$this->manager->flush();
|
||||
|
||||
$this->client->request('GET', sprintf('%s%s/edit', $this->path, $orderItem->getId()));
|
||||
self::assertResponseRedirects(sprintf('/food/order/%s', $this->order->getId()));
|
||||
}
|
||||
$this->assertResponseRedirects(sprintf('/food/order/%s', $this->order->getId()));
|
||||
});
|
||||
|
||||
public function testCopy(): void
|
||||
{
|
||||
test('copy', function (): void {
|
||||
$orderItem = new OrderItem;
|
||||
$orderItem->setName('My Title');
|
||||
$orderItem->setExtras('My Title');
|
||||
|
@ -222,7 +214,7 @@ final class OrderItemControllerTest extends DbWebTest
|
|||
$this->manager->flush();
|
||||
|
||||
$this->client->request('GET', sprintf('%s%s/copy', $this->path, $orderItem->getId()));
|
||||
self::assertResponseRedirects(sprintf('/food/order/%s', $this->order->getId()));
|
||||
$this->assertResponseRedirects(sprintf('/food/order/%s', $this->order->getId()));
|
||||
|
||||
$result = $this->repository->findBy([
|
||||
'foodOrder' => $this->order->getId(),
|
||||
|
@ -232,10 +224,9 @@ final class OrderItemControllerTest extends DbWebTest
|
|||
$this->assertSame($orderItem->getName(), $item->getName());
|
||||
$this->assertSame($orderItem->getExtras(), $item->getExtras());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
public function testCopyOrderClosed(): void
|
||||
{
|
||||
test('copy order closed', function (): void {
|
||||
$orderItem = new OrderItem;
|
||||
$orderItem->setName('My Title');
|
||||
$orderItem->setExtras('My Title');
|
||||
|
@ -248,17 +239,23 @@ final class OrderItemControllerTest extends DbWebTest
|
|||
$this->manager->flush();
|
||||
|
||||
$this->client->request('GET', sprintf('%s%s/copy', $this->path, $orderItem->getId()));
|
||||
self::assertResponseRedirects(sprintf('/food/order/%s', $this->order->getId()));
|
||||
$this->assertResponseRedirects(sprintf('/food/order/%s', $this->order->getId()));
|
||||
|
||||
$result = $this->repository->findBy([
|
||||
'foodOrder' => $this->order->getId(),
|
||||
]);
|
||||
$this->assertCount(1, $result);
|
||||
}
|
||||
});
|
||||
|
||||
#[Override]
|
||||
public function getEntityClass(): string
|
||||
{
|
||||
return OrderItem::class;
|
||||
}
|
||||
}
|
||||
})
|
||||
->covers(
|
||||
OrderItemController::class,
|
||||
MenuItemRepository::class,
|
||||
OrderItemRepository::class,
|
||||
OrderItemType::class,
|
||||
FoodOrder::class,
|
||||
FoodVendor::class,
|
||||
MenuItem::class,
|
||||
OrderItem::class,
|
||||
FoodOrderRepository::class,
|
||||
);
|
36
tests/Pest.php
Normal file
36
tests/Pest.php
Normal file
|
@ -0,0 +1,36 @@
|
|||
<?php declare(strict_types=1);
|
||||
|
||||
use App\Tests\DbApiTestCase;
|
||||
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');
|
||||
pest()
|
||||
->extends(DbApiTestCase::class)->in('Feature/Api/*.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
|
||||
{
|
||||
// ..
|
||||
}
|
10
tests/TestCase.php
Normal file
10
tests/TestCase.php
Normal file
|
@ -0,0 +1,10 @@
|
|||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase as BaseTestCase;
|
||||
|
||||
abstract class TestCase extends BaseTestCase
|
||||
{
|
||||
//
|
||||
}
|
32
tests/Unit/Entity/FoodOrderTest.php
Normal file
32
tests/Unit/Entity/FoodOrderTest.php
Normal file
|
@ -0,0 +1,32 @@
|
|||
<?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);
|
|
@ -1,17 +1,17 @@
|
|||
<?php declare(strict_types=1);
|
||||
|
||||
namespace App\Tests\Entity;
|
||||
namespace App\Tests\Unit\Entity;
|
||||
|
||||
use App\Entity\FoodOrder;
|
||||
use App\Entity\FoodVendor;
|
||||
use App\Entity\MenuItem;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\Uid\Ulid;
|
||||
|
||||
final class FoodVendorTest extends TestCase
|
||||
{
|
||||
public function testFoodVendor(): void
|
||||
{
|
||||
use function describe;
|
||||
use function test;
|
||||
|
||||
describe(FoodVendor::class, function (): void {
|
||||
test('FoodVendor entity', function (): void {
|
||||
$vendor = new FoodVendor;
|
||||
$vendor->setName('Test');
|
||||
$this->assertEquals('Test', $vendor->getName());
|
||||
|
@ -29,11 +29,9 @@ final class FoodVendorTest extends TestCase
|
|||
$vendor->removeFoodOrder($order1);
|
||||
$this->assertCount(0, $vendor->getFoodOrders());
|
||||
$this->assertNull($order1->getFoodVendor());
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
public function testMenuItem(): void
|
||||
{
|
||||
test('MenutItem entity', function (): void {
|
||||
$vendor = new FoodVendor;
|
||||
$menuItem1 = new MenuItem;
|
||||
$menuItem2 = new MenuItem;
|
||||
|
@ -49,10 +47,9 @@ final class FoodVendorTest extends TestCase
|
|||
$vendor->addMenuItem($menuItem2);
|
||||
$this->assertCount(1, $vendor->getMenuItems());
|
||||
$this->assertCount(2, $vendor->getMenuItems(true));
|
||||
}
|
||||
});
|
||||
|
||||
public function testRemoveForeignMenuItem(): void
|
||||
{
|
||||
test('remove foreign menu item', function (): void {
|
||||
$vendor1 = new FoodVendor;
|
||||
$vendor2 = new FoodVendor;
|
||||
$item1 = new MenuItem;
|
||||
|
@ -62,5 +59,6 @@ final class FoodVendorTest extends TestCase
|
|||
$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\Entity;
|
||||
namespace App\Tests\Unit\Entity;
|
||||
|
||||
use App\Entity\FoodVendor;
|
||||
use App\Entity\MenuItem;
|
||||
use DateTimeImmutable;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
final class MenuItemTest extends TestCase
|
||||
{
|
||||
public function testMenuItem(): void
|
||||
{
|
||||
use function describe;
|
||||
use function test;
|
||||
|
||||
describe(MenuItem::class, function (): void {
|
||||
test('MenuItem entity', function (): void {
|
||||
$item = new MenuItem;
|
||||
$item->setName('Test');
|
||||
$this->assertEquals('Test', $item->getName());
|
||||
|
@ -26,10 +26,8 @@ final class MenuItemTest extends TestCase
|
|||
$item->delete();
|
||||
$this->assertTrue($item->isDeleted());
|
||||
$this->assertInstanceOf(DateTimeImmutable::class, $item->getDeletedAt());
|
||||
}
|
||||
|
||||
public function testMenuItemAlias(): void
|
||||
{
|
||||
});
|
||||
test('MenuItem alias', function (): void {
|
||||
$item = new MenuItem;
|
||||
$item->setName('Test');
|
||||
$this->assertEquals('Test', $item->getName());
|
||||
|
@ -51,6 +49,5 @@ final class MenuItemTest extends TestCase
|
|||
$item->removeAlias($item2);
|
||||
$this->assertCount(0, $item->getAliases());
|
||||
$this->assertNull($item2->getAliasOf());
|
||||
|
||||
}
|
||||
}
|
||||
});
|
||||
})->covers(MenuItem::class, FoodVendor::class);
|
|
@ -6,6 +6,8 @@ require dirname(__DIR__) . '/vendor/autoload.php';
|
|||
|
||||
if (method_exists(Dotenv::class, 'bootEnv')) {
|
||||
(new Dotenv)->bootEnv(dirname(__DIR__) . '/.env');
|
||||
$token = $_SERVER['TEST_TOKEN'] ?? '';
|
||||
$_ENV['DATABASE_URL'] .= $token;
|
||||
}
|
||||
|
||||
if ($_SERVER['APP_DEBUG']) {
|
||||
|
|
Loading…
Add table
Reference in a new issue