Compare commits
No commits in common. "main" and "0.0.6" have entirely different histories.
81 changed files with 1693 additions and 7841 deletions
4
.env
4
.env
|
@ -28,7 +28,3 @@ 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,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"
|
||||
|
|
|
@ -3,13 +3,13 @@ jobs:
|
|||
ls:
|
||||
runs-on: docker
|
||||
container:
|
||||
image: git.php.fail/lubiana/container/php:8.4.1-ci
|
||||
image: git.php.fail/lubiana/container/php:ci
|
||||
steps:
|
||||
- name: Manually checkout
|
||||
env:
|
||||
REPO: '${{ github.repository }}'
|
||||
TOKEN: '${{ secrets.GITHUB_TOKEN }}'
|
||||
GIT_SERVER: 'git.hannover.ccc.de'
|
||||
GIT_SERVER: 'hannover.ccc.de/gitlab'
|
||||
run: |
|
||||
git clone --branch $GITHUB_HEAD_REF https://${TOKEN}@${GIT_SERVER}/${REPO}.git .
|
||||
git fetch
|
||||
|
|
|
@ -6,14 +6,14 @@ jobs:
|
|||
ls:
|
||||
runs-on: docker
|
||||
container:
|
||||
image: git.php.fail/lubiana/container/php:8.4.1-ci
|
||||
image: git.php.fail/lubiana/container/php:ci
|
||||
steps:
|
||||
- name: Manually checkout
|
||||
env:
|
||||
REPO: '${{ github.repository }}'
|
||||
TOKEN: '${{ secrets.GITHUB_TOKEN }}'
|
||||
BRANCH: '${{ env.GITHUB_REF_NAME }}'
|
||||
GIT_SERVER: 'git.hannover.ccc.de'
|
||||
GIT_SERVER: 'hannover.ccc.de/gitlab'
|
||||
run: |
|
||||
git clone --branch $GITHUB_REF_NAME https://${TOKEN}@${GIT_SERVER}/${REPO}.git .
|
||||
git fetch
|
||||
|
|
|
@ -4,7 +4,7 @@ jobs:
|
|||
ls:
|
||||
runs-on: docker
|
||||
container:
|
||||
image: git.php.fail/lubiana/container/php:8.4.1-ci
|
||||
image: git.php.fail/lubiana/container/php:ci
|
||||
steps:
|
||||
- name: Manually checkout
|
||||
env:
|
||||
|
|
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';
|
||||
}
|
|
@ -4,61 +4,44 @@
|
|||
"minimum-stability": "stable",
|
||||
"prefer-stable": true,
|
||||
"require": {
|
||||
"php": ">=8.4",
|
||||
"php": ">=8.3",
|
||||
"ext-ctype": "*",
|
||||
"ext-iconv": "*",
|
||||
"api-platform/doctrine-orm": "^4.0",
|
||||
"api-platform/symfony": "^4.0",
|
||||
"doctrine/dbal": "^4.1",
|
||||
"doctrine/dbal": "^4",
|
||||
"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.*",
|
||||
"doctrine/doctrine-migrations-bundle": "^3.3",
|
||||
"doctrine/orm": "^3.2",
|
||||
"symfony/console": "7.1.*",
|
||||
"symfony/dotenv": "7.1.*",
|
||||
"symfony/expression-language": "7.2.*",
|
||||
"symfony/flex": "^2.4.6",
|
||||
"symfony/flex": "^2",
|
||||
"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.*",
|
||||
"symfony/yaml": "7.1.*"
|
||||
},
|
||||
"require-dev": {
|
||||
"doctrine/doctrine-fixtures-bundle": "^4.0",
|
||||
"liip/test-fixtures-bundle": "^3.2",
|
||||
"lubiana/code-quality": "^1.7.2",
|
||||
"pestphp/pest": "^3.6",
|
||||
"symfony/browser-kit": "7.2.*",
|
||||
"symfony/css-selector": "7.2.*",
|
||||
"symfony/http-client": "7.2.*",
|
||||
"lubiana/code-quality": "^1.7",
|
||||
"phpunit/phpunit": "^9.5",
|
||||
"symfony/browser-kit": "7.1.*",
|
||||
"symfony/css-selector": "7.1.*",
|
||||
"symfony/maker-bundle": "^1.60",
|
||||
"symfony/stopwatch": "7.2.*",
|
||||
"symfony/web-profiler-bundle": "7.2.*",
|
||||
"symplify/config-transformer": "^12.3.4"
|
||||
"symfony/phpunit-bridge": "^7.1",
|
||||
"symplify/config-transformer": "^12.3"
|
||||
},
|
||||
"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": {
|
||||
"php": "8.4"
|
||||
"php": "8.3"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
|
@ -79,8 +62,7 @@
|
|||
"symfony/polyfill-php74": "*",
|
||||
"symfony/polyfill-php80": "*",
|
||||
"symfony/polyfill-php81": "*",
|
||||
"symfony/polyfill-php82": "*",
|
||||
"symfony/polyfill-php83": "*"
|
||||
"symfony/polyfill-php82": "*"
|
||||
},
|
||||
"scripts": {
|
||||
"auto-scripts": {
|
||||
|
@ -92,13 +74,13 @@
|
|||
],
|
||||
"post-update-cmd": [
|
||||
"@auto-scripts",
|
||||
"config-transformer config"
|
||||
"config-transformer switch-format config"
|
||||
],
|
||||
"lint": [
|
||||
"rector",
|
||||
"ecs --fix || ecs --fix"
|
||||
],
|
||||
"test": "pest --parallel"
|
||||
"test": "bin/phpunit"
|
||||
},
|
||||
"conflict": {
|
||||
"symfony/symfony": "*"
|
||||
|
@ -106,7 +88,7 @@
|
|||
"extra": {
|
||||
"symfony": {
|
||||
"allow-contrib": false,
|
||||
"require": "7.2.*"
|
||||
"require": "7.1.*"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
5469
composer.lock
generated
5469
composer.lock
generated
File diff suppressed because it is too large
Load diff
|
@ -1,16 +1,10 @@
|
|||
<?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;
|
||||
|
||||
return [
|
||||
FrameworkBundle::class => [
|
||||
|
@ -28,25 +22,4 @@ return [
|
|||
TwigBundle::class => [
|
||||
'all' => true,
|
||||
],
|
||||
DoctrineFixturesBundle::class => [
|
||||
'dev' => true,
|
||||
'test' => true,
|
||||
],
|
||||
WebProfilerBundle::class => [
|
||||
'dev' => true,
|
||||
'test' => true,
|
||||
],
|
||||
SecurityBundle::class => [
|
||||
'all' => true,
|
||||
],
|
||||
NelmioCorsBundle::class => [
|
||||
'all' => true,
|
||||
],
|
||||
ApiPlatformBundle::class => [
|
||||
'all' => true,
|
||||
],
|
||||
LiipTestFixturesBundle::class => [
|
||||
'dev' => true,
|
||||
'test' => true,
|
||||
],
|
||||
];
|
||||
|
|
|
@ -1,22 +0,0 @@
|
|||
<?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',
|
||||
],
|
||||
],
|
||||
],
|
||||
]);
|
||||
};
|
|
@ -1,33 +0,0 @@
|
|||
<?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,
|
||||
],
|
||||
]);
|
||||
};
|
|
@ -1,40 +0,0 @@
|
|||
<?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,
|
||||
],
|
||||
],
|
||||
]);
|
||||
}
|
||||
};
|
|
@ -5,9 +5,6 @@ use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigura
|
|||
return static function (ContainerConfigurator $containerConfigurator): void {
|
||||
$containerConfigurator->extension('twig', [
|
||||
'file_name_pattern' => '*.twig',
|
||||
'globals' => [
|
||||
'favicon' => '@App\Service\Favicon',
|
||||
],
|
||||
]);
|
||||
if ($containerConfigurator->env() === 'test') {
|
||||
$containerConfigurator->extension('twig', [
|
||||
|
|
|
@ -1,29 +0,0 @@
|
|||
<?php declare(strict_types=1);
|
||||
|
||||
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
|
||||
|
||||
return static function (ContainerConfigurator $containerConfigurator): void {
|
||||
if ($containerConfigurator->env() === 'dev') {
|
||||
$containerConfigurator->extension('web_profiler', [
|
||||
'toolbar' => true,
|
||||
'intercept_redirects' => false,
|
||||
]);
|
||||
$containerConfigurator->extension('framework', [
|
||||
'profiler' => [
|
||||
'only_exceptions' => false,
|
||||
'collect_serializer_data' => true,
|
||||
],
|
||||
]);
|
||||
}
|
||||
if ($containerConfigurator->env() === 'test') {
|
||||
$containerConfigurator->extension('web_profiler', [
|
||||
'toolbar' => false,
|
||||
'intercept_redirects' => false,
|
||||
]);
|
||||
$containerConfigurator->extension('framework', [
|
||||
'profiler' => [
|
||||
'collect' => false,
|
||||
],
|
||||
]);
|
||||
}
|
||||
};
|
|
@ -1,8 +0,0 @@
|
|||
<?php declare(strict_types=1);
|
||||
|
||||
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;
|
||||
|
||||
return static function (RoutingConfigurator $routingConfigurator): void {
|
||||
$routingConfigurator->import('.', 'api_platform')
|
||||
->prefix('/api');
|
||||
};
|
|
@ -1,7 +0,0 @@
|
|||
<?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');
|
||||
};
|
|
@ -1,12 +0,0 @@
|
|||
<?php declare(strict_types=1);
|
||||
|
||||
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;
|
||||
|
||||
return static function (RoutingConfigurator $routingConfigurator): void {
|
||||
if ($routingConfigurator->env() === 'dev') {
|
||||
$routingConfigurator->import('@WebProfilerBundle/Resources/config/routing/wdt.xml')
|
||||
->prefix('/_wdt');
|
||||
$routingConfigurator->import('@WebProfilerBundle/Resources/config/routing/profiler.xml')
|
||||
->prefix('/_profiler');
|
||||
}
|
||||
};
|
|
@ -15,6 +15,7 @@ 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/php84/php-fpm.d/www.conf:/etc/php84/php-fpm.d/www.conf \
|
||||
--volume %h/futtern/etc/php83/php-fpm.d/www.conf:/etc/php83/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.4-fpm
|
||||
git.php.fail/lubiana/container/php:8.3-fpm
|
||||
ExecStop=/usr/bin/podman stop \
|
||||
--ignore -t 10 \
|
||||
--cidfile=%t/%n.ctr-id
|
||||
|
|
|
@ -1,36 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace DoctrineMigrations;
|
||||
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\Migrations\AbstractMigration;
|
||||
|
||||
/**
|
||||
* Auto-generated Migration: Please modify to your needs!
|
||||
*/
|
||||
final class Version20240815151510 extends AbstractMigration
|
||||
{
|
||||
public function getDescription(): string
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
public function up(Schema $schema): void
|
||||
{
|
||||
// this up() migration is auto-generated, please modify it to your needs
|
||||
$this->addSql('ALTER TABLE menu_item ADD COLUMN deleted_at DATETIME DEFAULT NULL');
|
||||
}
|
||||
|
||||
public function down(Schema $schema): void
|
||||
{
|
||||
// this down() migration is auto-generated, please modify it to your needs
|
||||
$this->addSql('CREATE TEMPORARY TABLE __temp__menu_item AS SELECT id, name, food_vendor_id FROM menu_item');
|
||||
$this->addSql('DROP TABLE menu_item');
|
||||
$this->addSql('CREATE TABLE menu_item (id BLOB NOT NULL, name VARCHAR(255) NOT NULL, food_vendor_id BLOB NOT NULL, PRIMARY KEY(id), CONSTRAINT FK_D754D5506EF983E8 FOREIGN KEY (food_vendor_id) REFERENCES food_vendor (id) NOT DEFERRABLE INITIALLY IMMEDIATE)');
|
||||
$this->addSql('INSERT INTO menu_item (id, name, food_vendor_id) SELECT id, name, food_vendor_id FROM __temp__menu_item');
|
||||
$this->addSql('DROP TABLE __temp__menu_item');
|
||||
$this->addSql('CREATE INDEX IDX_D754D5506EF983E8 ON menu_item (food_vendor_id)');
|
||||
}
|
||||
}
|
|
@ -1,35 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace DoctrineMigrations;
|
||||
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\Migrations\AbstractMigration;
|
||||
|
||||
/**
|
||||
* Auto-generated Migration: Please modify to your needs!
|
||||
*/
|
||||
final class Version20240816193410 extends AbstractMigration
|
||||
{
|
||||
public function getDescription(): string
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
public function up(Schema $schema): void
|
||||
{
|
||||
// this up() migration is auto-generated, please modify it to your needs
|
||||
$this->addSql('ALTER TABLE food_vendor ADD COLUMN menu_link VARCHAR(255) DEFAULT NULL');
|
||||
}
|
||||
|
||||
public function down(Schema $schema): void
|
||||
{
|
||||
// this down() migration is auto-generated, please modify it to your needs
|
||||
$this->addSql('CREATE TEMPORARY TABLE __temp__food_vendor AS SELECT name, id FROM food_vendor');
|
||||
$this->addSql('DROP TABLE food_vendor');
|
||||
$this->addSql('CREATE TABLE food_vendor (name VARCHAR(50) NOT NULL, id BLOB NOT NULL, PRIMARY KEY(id))');
|
||||
$this->addSql('INSERT INTO food_vendor (name, id) SELECT name, id FROM __temp__food_vendor');
|
||||
$this->addSql('DROP TABLE __temp__food_vendor');
|
||||
}
|
||||
}
|
|
@ -1,35 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace DoctrineMigrations;
|
||||
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\Migrations\AbstractMigration;
|
||||
|
||||
/**
|
||||
* Auto-generated Migration: Please modify to your needs!
|
||||
*/
|
||||
final class Version20241218235101 extends AbstractMigration
|
||||
{
|
||||
public function getDescription(): string
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
public function up(Schema $schema): void
|
||||
{
|
||||
// this up() migration is auto-generated, please modify it to your needs
|
||||
$this->addSql('ALTER TABLE food_vendor ADD COLUMN phone VARCHAR(50) DEFAULT \'\'');
|
||||
}
|
||||
|
||||
public function down(Schema $schema): void
|
||||
{
|
||||
// this down() migration is auto-generated, please modify it to your needs
|
||||
$this->addSql('CREATE TEMPORARY TABLE __temp__food_vendor AS SELECT name, menu_link, id FROM food_vendor');
|
||||
$this->addSql('DROP TABLE food_vendor');
|
||||
$this->addSql('CREATE TABLE food_vendor (name VARCHAR(50) NOT NULL, menu_link VARCHAR(255) DEFAULT NULL, id BLOB NOT NULL, PRIMARY KEY(id))');
|
||||
$this->addSql('INSERT INTO food_vendor (name, menu_link, id) SELECT name, menu_link, id FROM __temp__food_vendor');
|
||||
$this->addSql('DROP TABLE __temp__food_vendor');
|
||||
}
|
||||
}
|
|
@ -1,42 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace DoctrineMigrations;
|
||||
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\Migrations\AbstractMigration;
|
||||
|
||||
/**
|
||||
* Auto-generated Migration: Please modify to your needs!
|
||||
*/
|
||||
final class Version20250124234947 extends AbstractMigration
|
||||
{
|
||||
public function getDescription(): string
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
public function up(Schema $schema): void
|
||||
{
|
||||
// this up() migration is auto-generated, please modify it to your needs
|
||||
$this->addSql('CREATE TEMPORARY TABLE __temp__menu_item AS SELECT id, name, food_vendor_id, deleted_at FROM menu_item');
|
||||
$this->addSql('DROP TABLE menu_item');
|
||||
$this->addSql('CREATE TABLE menu_item (id BLOB NOT NULL, name VARCHAR(255) NOT NULL, food_vendor_id BLOB NOT NULL, deleted_at DATETIME DEFAULT NULL, alias_of_id BLOB DEFAULT NULL, PRIMARY KEY(id), CONSTRAINT FK_D754D5506EF983E8 FOREIGN KEY (food_vendor_id) REFERENCES food_vendor (id) ON UPDATE NO ACTION ON DELETE NO ACTION NOT DEFERRABLE INITIALLY IMMEDIATE, CONSTRAINT FK_D754D55061F0AFC5 FOREIGN KEY (alias_of_id) REFERENCES menu_item (id) NOT DEFERRABLE INITIALLY IMMEDIATE)');
|
||||
$this->addSql('INSERT INTO menu_item (id, name, food_vendor_id, deleted_at) SELECT id, name, food_vendor_id, deleted_at FROM __temp__menu_item');
|
||||
$this->addSql('DROP TABLE __temp__menu_item');
|
||||
$this->addSql('CREATE INDEX IDX_D754D5506EF983E8 ON menu_item (food_vendor_id)');
|
||||
$this->addSql('CREATE INDEX IDX_D754D55061F0AFC5 ON menu_item (alias_of_id)');
|
||||
}
|
||||
|
||||
public function down(Schema $schema): void
|
||||
{
|
||||
// this down() migration is auto-generated, please modify it to your needs
|
||||
$this->addSql('CREATE TEMPORARY TABLE __temp__menu_item AS SELECT name, deleted_at, id, food_vendor_id FROM menu_item');
|
||||
$this->addSql('DROP TABLE menu_item');
|
||||
$this->addSql('CREATE TABLE menu_item (name VARCHAR(255) NOT NULL, deleted_at DATETIME DEFAULT NULL, id BLOB NOT NULL, food_vendor_id BLOB NOT NULL, PRIMARY KEY(id), CONSTRAINT FK_D754D5506EF983E8 FOREIGN KEY (food_vendor_id) REFERENCES food_vendor (id) NOT DEFERRABLE INITIALLY IMMEDIATE)');
|
||||
$this->addSql('INSERT INTO menu_item (name, deleted_at, id, food_vendor_id) SELECT name, deleted_at, id, food_vendor_id FROM __temp__menu_item');
|
||||
$this->addSql('DROP TABLE __temp__menu_item');
|
||||
$this->addSql('CREATE INDEX IDX_D754D5506EF983E8 ON menu_item (food_vendor_id)');
|
||||
}
|
||||
}
|
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>
|
|
@ -14,7 +14,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>
|
||||
|
|
|
@ -1,965 +0,0 @@
|
|||
/* SPDX-License-Identifier: MIT
|
||||
SPDX-FileCopyrightText: Copyright (c) 2022-2025 zichy
|
||||
*/
|
||||
|
||||
/* Custom properties
|
||||
========================================
|
||||
*/
|
||||
|
||||
:root {
|
||||
--f-sans: ui-sans-serif, sans-serif;
|
||||
|
||||
--f-body: ui-serif;
|
||||
--f-heading: var(--f-sans);
|
||||
--f-form: var(--f-sans);
|
||||
--f-code: ui-monospace;
|
||||
|
||||
--f-size: clamp(1.6rem, 1.75vw, 2rem);
|
||||
--f-size-small: 0.85em;
|
||||
--f-size-large: 1.25em;
|
||||
--f-line: 1.5;
|
||||
|
||||
--c-gray: #666;
|
||||
--c-red: #b30;
|
||||
--c-yellow: #fe9;
|
||||
|
||||
--i-triangle: url('data:image/svg+xml,%3Csvg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 10 10"%3E%3Cpolygon fill="black" points="5 10 10 0 0 0"/%3E%3C/svg%3E');
|
||||
|
||||
--w-body: 80ch;
|
||||
}
|
||||
|
||||
/* Dark theme */
|
||||
|
||||
@media (prefers-color-scheme: dark) {
|
||||
:root {
|
||||
--c-gray: #999;
|
||||
--c-red: #f99;
|
||||
--c-yellow: #ff9;
|
||||
|
||||
--i-triangle: url('data:image/svg+xml,%3Csvg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 10 10"%3E%3Cpolygon fill="white" points="5 10 10 0 0 0"/%3E%3C/svg%3E');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Globals
|
||||
========================================
|
||||
*/
|
||||
|
||||
/* Box sizing */
|
||||
|
||||
*,
|
||||
*::before,
|
||||
*::after {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
/* Text rendering */
|
||||
|
||||
* {
|
||||
-webkit-font-smoothing: antialiased;
|
||||
text-rendering: optimizeLegibility;
|
||||
}
|
||||
|
||||
/* Interaction */
|
||||
|
||||
::selection {
|
||||
background: Highlight;
|
||||
color: HighlightText;
|
||||
text-shadow: none;
|
||||
}
|
||||
|
||||
*:focus {
|
||||
outline: 2px solid LinkText;
|
||||
outline-offset: 0.25rem;
|
||||
}
|
||||
|
||||
/* Font size & Scrolling */
|
||||
|
||||
html {
|
||||
font-size: 62.5%;
|
||||
scroll-behavior: smooth;
|
||||
scroll-padding-top: 2rem;
|
||||
}
|
||||
|
||||
/* Backdrop */
|
||||
|
||||
::backdrop {
|
||||
background-color: rgba(255, 255, 255, 0.6);
|
||||
}
|
||||
|
||||
@media (prefers-color-scheme: dark) {
|
||||
::backdrop {
|
||||
background-color: rgba(0, 0, 0, 0.6);
|
||||
}
|
||||
}
|
||||
|
||||
/* Hidden elements */
|
||||
|
||||
[hidden] {
|
||||
display: none;
|
||||
}
|
||||
|
||||
/* Print spacing */
|
||||
|
||||
@page {
|
||||
margin: 15mm 20mm;
|
||||
}
|
||||
|
||||
|
||||
/* Body
|
||||
========================================
|
||||
*/
|
||||
|
||||
/* Colors & Typography */
|
||||
|
||||
body {
|
||||
background-color: Canvas;
|
||||
color: CanvasText;
|
||||
font-size: var(--f-size);
|
||||
font-family: var(--f-body);
|
||||
line-height: var(--f-line);
|
||||
}
|
||||
|
||||
/* Body sizing */
|
||||
|
||||
@media screen {
|
||||
body {
|
||||
max-width: var(--w-body, 100%);
|
||||
min-width: 320px;
|
||||
padding: 2rem;
|
||||
margin: 0 auto;
|
||||
overflow-x: hidden;
|
||||
overflow-y: scroll;
|
||||
}
|
||||
}
|
||||
|
||||
/* Print colors */
|
||||
|
||||
@media print {
|
||||
body {
|
||||
background-color: white;
|
||||
color: black;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Links
|
||||
========================================
|
||||
*/
|
||||
|
||||
a:any-link {
|
||||
color: LinkText;
|
||||
text-decoration: underline;
|
||||
text-decoration-thickness: 0.125em;
|
||||
}
|
||||
|
||||
a:any-link:hover {
|
||||
background-color: LinkText;
|
||||
color: Canvas;
|
||||
text-decoration-line: none;
|
||||
}
|
||||
|
||||
@media print {
|
||||
a[href^="http"]::after {
|
||||
content: ' ('attr(href)')';
|
||||
font-size: var(--f-size-small);
|
||||
word-break: break-all;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Media
|
||||
========================================
|
||||
*/
|
||||
|
||||
/* Reset */
|
||||
|
||||
:where(iframe, img, svg, canvas, audio, video) {
|
||||
display: block;
|
||||
max-width: 100%;
|
||||
}
|
||||
|
||||
@media print {
|
||||
:where(audio, video) {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
|
||||
figure {
|
||||
margin-inline: 0;
|
||||
break-inside: avoid;
|
||||
}
|
||||
|
||||
/* Image */
|
||||
|
||||
img {
|
||||
height: auto;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
img::before {
|
||||
content: '';
|
||||
background-color: Highlight;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
}
|
||||
|
||||
@media screen {
|
||||
picture img {
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
|
||||
/* Video */
|
||||
|
||||
video {
|
||||
width: 100%;
|
||||
height: auto;
|
||||
}
|
||||
|
||||
/* Iframe */
|
||||
|
||||
iframe {
|
||||
border-style: none;
|
||||
}
|
||||
|
||||
|
||||
/* Headings
|
||||
========================================
|
||||
*/
|
||||
|
||||
:where(h1, h2, h3, h4, h5, h6) {
|
||||
font-family: var(--f-heading);
|
||||
line-height: calc(var(--f-line) / 1.25);
|
||||
hyphens: auto;
|
||||
}
|
||||
|
||||
:where(h3, h5) {
|
||||
color: var(--c-gray);
|
||||
}
|
||||
|
||||
:where(h4, h5, h6) {
|
||||
text-transform: uppercase;
|
||||
}
|
||||
|
||||
:where(h2, h3, h4, h5, h6):target {
|
||||
background-color: var(--c-yellow);
|
||||
color: MarkText;
|
||||
}
|
||||
|
||||
|
||||
/* Lists
|
||||
========================================
|
||||
*/
|
||||
|
||||
:where(ul, ol) {
|
||||
padding-inline-start: 1em;
|
||||
}
|
||||
|
||||
ul {
|
||||
list-style-type: disc;
|
||||
}
|
||||
|
||||
li::marker {
|
||||
color: var(--c-gray);
|
||||
}
|
||||
|
||||
li p {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
/* Description */
|
||||
|
||||
dt {
|
||||
font-style: italic;
|
||||
}
|
||||
|
||||
/* Navigation */
|
||||
|
||||
nav ul {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 0.5rem 2rem;
|
||||
list-style-type: none;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
@media print {
|
||||
nav {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Inline elements
|
||||
========================================
|
||||
*/
|
||||
|
||||
/* Bold text */
|
||||
|
||||
:where(b, strong) {
|
||||
font-weight: bolder;
|
||||
}
|
||||
|
||||
/* Small text */
|
||||
|
||||
small {
|
||||
font-size: var(--f-size-small);
|
||||
}
|
||||
|
||||
/* Mark */
|
||||
|
||||
mark {
|
||||
background-color: var(--c-yellow);
|
||||
}
|
||||
|
||||
/* Abbreviation */
|
||||
|
||||
abbr[title] {
|
||||
text-decoration-line: underline;
|
||||
text-decoration-style: dotted;
|
||||
cursor: help;
|
||||
}
|
||||
|
||||
a abbr[title] {
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
/* Subscript & Superscript */
|
||||
|
||||
:where(sub, sup) {
|
||||
line-height: 0;
|
||||
}
|
||||
|
||||
/* Quote */
|
||||
|
||||
q {
|
||||
font-style: italic;
|
||||
quotes: none;
|
||||
}
|
||||
|
||||
/* Keyboard input */
|
||||
|
||||
kbd {
|
||||
background: linear-gradient(0deg, Canvas 0%, ButtonFace 100%);
|
||||
font-size: var(--f-size-small);
|
||||
font-family: var(--f-sans);
|
||||
font-weight: bold;
|
||||
padding: 0.2em 0.4em;
|
||||
border-radius: 0.5rem;
|
||||
box-shadow: 1px 1px 1px 0px var(--c-gray);
|
||||
}
|
||||
|
||||
|
||||
/* Ruby annotation
|
||||
========================================
|
||||
*/
|
||||
|
||||
rt {
|
||||
color: var(--c-gray);
|
||||
font-family: var(--f-sans);
|
||||
letter-spacing: -0.05em;
|
||||
padding: 0 0.25em;
|
||||
}
|
||||
|
||||
|
||||
/* Horizontal rule
|
||||
========================================
|
||||
*/
|
||||
|
||||
hr {
|
||||
height: 0;
|
||||
margin: 2em 0;
|
||||
border: 0;
|
||||
border-top: 2px solid var(--c-gray);
|
||||
}
|
||||
|
||||
|
||||
/* Blockquote
|
||||
========================================
|
||||
*/
|
||||
|
||||
blockquote {
|
||||
font-size: var(--f-size-large);
|
||||
font-style: italic;
|
||||
line-height: calc(var(--f-line) / 1.25);
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
blockquote > *:first-child {
|
||||
margin-block-start: 0;
|
||||
}
|
||||
|
||||
blockquote > *:last-child {
|
||||
margin-block-end: 0;
|
||||
}
|
||||
|
||||
|
||||
/* Captions
|
||||
========================================
|
||||
*/
|
||||
|
||||
:where(caption, figcaption) {
|
||||
color: var(--c-gray);
|
||||
font-family: var(--f-heading);
|
||||
font-size: var(--f-size-small);
|
||||
font-style: italic;
|
||||
margin-block-start: 0.5rem;
|
||||
}
|
||||
|
||||
caption {
|
||||
text-align: left;
|
||||
caption-side: bottom;
|
||||
}
|
||||
|
||||
[dir='rtl' i] caption {
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
|
||||
/* Code
|
||||
========================================
|
||||
*/
|
||||
|
||||
:where(pre, code, samp, var) {
|
||||
background-color: ButtonFace;
|
||||
}
|
||||
|
||||
:where(code, samp, var) {
|
||||
font-size: var(--f-size-small);
|
||||
font-family: var(--f-code);
|
||||
padding: 0.2em 0.4em;
|
||||
}
|
||||
|
||||
pre {
|
||||
font-size: var(--f-size-small);
|
||||
padding: 2rem;
|
||||
}
|
||||
|
||||
@media screen {
|
||||
pre {
|
||||
overflow-x: scroll;
|
||||
}
|
||||
}
|
||||
|
||||
pre code {
|
||||
background-color: transparent;
|
||||
display: block;
|
||||
white-space: pre-wrap;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
|
||||
/* Details
|
||||
========================================
|
||||
*/
|
||||
|
||||
details {
|
||||
background-color: ButtonFace;
|
||||
padding: 2rem;
|
||||
margin: 1em 0;
|
||||
border-radius: 0.5rem;
|
||||
}
|
||||
|
||||
details > *:nth-child(2) {
|
||||
margin-block-start: 0;
|
||||
}
|
||||
|
||||
details > *:last-child {
|
||||
margin-block-end: 0;
|
||||
}
|
||||
|
||||
summary {
|
||||
color: LinkText;
|
||||
font-family: var(--f-heading);
|
||||
font-weight: bold;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
summary:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
details[open] summary {
|
||||
margin-block-end: 2rem;
|
||||
}
|
||||
|
||||
|
||||
/* Aside
|
||||
========================================
|
||||
*/
|
||||
|
||||
aside {
|
||||
color: var(--c-gray);
|
||||
}
|
||||
|
||||
@media (min-width: 769px) {
|
||||
aside {
|
||||
font-size: var(--f-size-small);
|
||||
float: right;
|
||||
width: calc(var(--w-body) / 2.5);
|
||||
padding-block-end: 2rem;
|
||||
padding-inline-start: 4rem;
|
||||
}
|
||||
|
||||
aside > *:first-child {
|
||||
margin-block-start: 0;
|
||||
}
|
||||
|
||||
aside > *:last-child {
|
||||
margin-block-end: 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Table
|
||||
========================================
|
||||
*/
|
||||
|
||||
table {
|
||||
width: 100%;
|
||||
margin: 1em 0;
|
||||
border-collapse: collapse;
|
||||
border-spacing: 0;
|
||||
break-inside: avoid;
|
||||
}
|
||||
|
||||
@media screen and (max-width: 768px) {
|
||||
table {
|
||||
display: block;
|
||||
overflow-x: auto;
|
||||
overflow-y: hidden;
|
||||
}
|
||||
}
|
||||
|
||||
thead {
|
||||
border-bottom: 2px solid var(--c-gray);
|
||||
}
|
||||
|
||||
tbody tr:nth-child(odd) {
|
||||
background-color: ButtonFace;
|
||||
}
|
||||
|
||||
tfoot {
|
||||
border-top: 2px solid var(--c-gray);
|
||||
}
|
||||
|
||||
:where(th, td) {
|
||||
padding: 0.5rem 1rem;
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
:where(th, td) {
|
||||
min-width: 10rem;
|
||||
}
|
||||
}
|
||||
|
||||
th {
|
||||
font-family: var(--f-heading);
|
||||
text-align: left;
|
||||
vertical-align: bottom;
|
||||
}
|
||||
|
||||
[dir='rtl' i] th {
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
|
||||
/* Forms & Inputs
|
||||
========================================
|
||||
*/
|
||||
|
||||
/* Reset */
|
||||
|
||||
:where(input, textarea, select, button, progress) {
|
||||
-webkit-appearance: none;
|
||||
background-color: transparent;
|
||||
break-inside: avoid;
|
||||
}
|
||||
|
||||
:where(input, textarea, select, button) {
|
||||
font-family: var(--f-form);
|
||||
font-size: 1em;
|
||||
border-radius: 0.5rem;
|
||||
}
|
||||
|
||||
:where(input:not([type='button' i]):not([type='submit' i]):not([type='reset' i]):not([type='checkbox' i]):not([type='radio' i]):not([type='image' i]), textarea, select) {
|
||||
color: CanvasText;
|
||||
font-size: var(--f-size-small);
|
||||
display: block;
|
||||
width: 100%;
|
||||
padding: 0.75rem 1rem;
|
||||
border: 2px solid LinkText;
|
||||
}
|
||||
|
||||
/* Placeholder */
|
||||
|
||||
::placeholder {
|
||||
color: var(--c-gray);
|
||||
}
|
||||
|
||||
/* Fieldset */
|
||||
|
||||
fieldset {
|
||||
padding: 2rem;
|
||||
border: 2px solid LinkText;
|
||||
border-radius: 0.5rem;
|
||||
break-inside: avoid;
|
||||
}
|
||||
|
||||
/* Label & Legend */
|
||||
|
||||
:where(legend, label) {
|
||||
font-family: var(--f-form);
|
||||
font-weight: bold;
|
||||
display: block;
|
||||
}
|
||||
|
||||
legend {
|
||||
padding: 0 1rem;
|
||||
}
|
||||
|
||||
:where(legend, label) small {
|
||||
color: var(--c-gray);
|
||||
font-weight: normal;
|
||||
}
|
||||
|
||||
/* Textarea */
|
||||
|
||||
textarea {
|
||||
resize: vertical;
|
||||
}
|
||||
|
||||
/* Checkbox & Radio input */
|
||||
|
||||
label:has([type='checkbox' i], [type='radio' i]) {
|
||||
font-family: var(--f-form);
|
||||
font-size: var(--f-size-small);
|
||||
font-weight: normal;
|
||||
display: grid;
|
||||
grid-template-columns: 1.25em 1fr;
|
||||
column-gap: 0.5em;
|
||||
padding-block-end: 0;
|
||||
}
|
||||
|
||||
label:has([type='checkbox' i][disabled], [type='radio' i][disabled]) {
|
||||
color: var(--c-gray);
|
||||
}
|
||||
|
||||
:where([type='checkbox' i], [type='radio' i]) {
|
||||
width: 1.25em;
|
||||
height: 1.25em;
|
||||
position: relative;
|
||||
margin: 0.2rem 0 0;
|
||||
border: 2px solid LinkText;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
[type='radio' i] {
|
||||
border-radius: 50%;
|
||||
}
|
||||
|
||||
:where([type='checkbox' i], [type='radio' i]):checked {
|
||||
background-color: LinkText;
|
||||
}
|
||||
|
||||
[type='checkbox' i]:checked::after {
|
||||
content: '\2713';
|
||||
color: Canvas;
|
||||
font-family: var(--f-form);
|
||||
font-weight: bold;
|
||||
line-height: 1;
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
}
|
||||
|
||||
/* Color input */
|
||||
|
||||
[type='color' i] {
|
||||
height: 4rem;
|
||||
padding: 0.5rem;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
::-webkit-color-swatch-wrapper {
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
::-webkit-color-swatch {
|
||||
border: 0;
|
||||
}
|
||||
|
||||
::-moz-color-swatch {
|
||||
border: 0;
|
||||
}
|
||||
|
||||
/* Range input */
|
||||
|
||||
[type='range' i] {
|
||||
margin: 1.25rem 0 0;
|
||||
padding: 0;
|
||||
border: 0;
|
||||
}
|
||||
|
||||
[type='range' i]:focus {
|
||||
outline: none;
|
||||
}
|
||||
|
||||
::-webkit-slider-runnable-track {
|
||||
background-color: LinkText;
|
||||
height: 4px;
|
||||
border-radius: 0.5rem;
|
||||
}
|
||||
|
||||
[disabled]::-webkit-slider-runnable-track {
|
||||
background-color: var(--c-gray);
|
||||
}
|
||||
|
||||
::-moz-range-track {
|
||||
background-color: LinkText;
|
||||
height: 4px;
|
||||
border-radius: 0.5rem;
|
||||
}
|
||||
|
||||
[disabled]::-moz-range-track {
|
||||
background-color: var(--c-gray);
|
||||
}
|
||||
|
||||
::-webkit-slider-thumb {
|
||||
-webkit-appearance: none;
|
||||
appearance: none;
|
||||
background-color: Canvas;
|
||||
height: 2rem;
|
||||
width: 2rem;
|
||||
margin-block-start: calc(-1rem + 2px);
|
||||
border: 2px solid LinkText;
|
||||
border-radius: 50%;
|
||||
cursor: ew-resize;
|
||||
}
|
||||
|
||||
[disabled]::-webkit-slider-thumb {
|
||||
border-color: var(--c-gray);
|
||||
}
|
||||
|
||||
[type='range' i]:focus::-webkit-slider-thumb {
|
||||
outline: 2px solid LinkText;
|
||||
outline-offset: 0.25rem;
|
||||
}
|
||||
|
||||
::-moz-range-thumb {
|
||||
appearance: none;
|
||||
background-color: Canvas;
|
||||
height: 2rem;
|
||||
width: 2rem;
|
||||
margin-block-start: calc(-1rem + 2px);
|
||||
border: 2px solid LinkText;
|
||||
border-radius: 50%;
|
||||
cursor: ew-resize;
|
||||
}
|
||||
|
||||
[disabled]::-moz-range-thumb {
|
||||
border-color: var(--c-gray);
|
||||
}
|
||||
|
||||
[type='range' i]:focus::-moz-range-thumb {
|
||||
outline: 2px solid LinkText;
|
||||
outline-offset: 0.25rem;
|
||||
}
|
||||
|
||||
/* Select */
|
||||
|
||||
select {
|
||||
background: Canvas var(--i-triangle) no-repeat calc(100% - 1rem) center / 1.5rem;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
padding-inline-end: 3.5rem;
|
||||
overflow: hidden;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
[dir='rtl' i] select {
|
||||
background-position: 1rem center;
|
||||
padding-inline: 3.5rem 1rem;
|
||||
}
|
||||
|
||||
select[multiple] {
|
||||
background-image: none;
|
||||
padding-inline-end: 1rem;
|
||||
}
|
||||
|
||||
/* Buttons */
|
||||
|
||||
:where(button, [type='button' i], [type='submit' i], [type='reset' i]) {
|
||||
font-size: var(--f-size-small);
|
||||
font-weight: bold;
|
||||
text-align: center;
|
||||
text-decoration: none;
|
||||
line-height: 1;
|
||||
display: inline-block;
|
||||
min-width: 5rem;
|
||||
padding: 0.2em 0.4em;
|
||||
border: 2px solid LinkText;
|
||||
-webkit-user-select: text;
|
||||
user-select: text;
|
||||
cursor: pointer;
|
||||
touch-action: manipulation;
|
||||
}
|
||||
|
||||
:where(button:not([disabled]), [type='button' i]:not([disabled]), [type='submit' i]:not([disabled]), [type='reset' i]:not([disabled])):hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
@media screen {
|
||||
:where(button, [type='button' i], [type='submit' i], [type='reset' i]) {
|
||||
background-color: LinkText;
|
||||
color: Canvas;
|
||||
}
|
||||
|
||||
:where(button[disabled], [type='button' i][disabled], [type='submit' i][disabled], [type='reset' i][disabled]) {
|
||||
background-color: var(--c-gray);
|
||||
color: currentColor;
|
||||
}
|
||||
}
|
||||
|
||||
form :where(button, [type='button' i], [type='submit' i], [type='reset' i]) {
|
||||
padding: 1rem 1.5rem;
|
||||
}
|
||||
|
||||
/* Meter & Progress */
|
||||
|
||||
:where(meter, progress) {
|
||||
width: 100%;
|
||||
height: 3rem;
|
||||
border: 2px solid var(--c-gray);
|
||||
}
|
||||
|
||||
label + :where(meter, progress) {
|
||||
margin-block-start: 0.5rem;
|
||||
}
|
||||
|
||||
meter {
|
||||
background: transparent;
|
||||
display: block;
|
||||
margin-block-end: 1em;
|
||||
border: 2px solid var(--c-gray);
|
||||
}
|
||||
|
||||
::-webkit-meter-bar {
|
||||
background: Canvas;
|
||||
height: 3rem;
|
||||
border: 2px solid var(--c-gray);
|
||||
border-radius: 0;
|
||||
}
|
||||
|
||||
::-webkit-progress-bar {
|
||||
background-color: Canvas;
|
||||
}
|
||||
|
||||
::-moz-progress-bar {
|
||||
background-color: var(--c-gray);
|
||||
}
|
||||
|
||||
::-webkit-progress-value {
|
||||
background-color: var(--c-gray);
|
||||
}
|
||||
|
||||
/* Disabled state */
|
||||
|
||||
[disabled] {
|
||||
border-color: var(--c-gray);
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
/* Error state */
|
||||
|
||||
[aria-invalid] {
|
||||
border-color: var(--c-red) !important;
|
||||
}
|
||||
|
||||
[aria-invalid]:focus {
|
||||
outline-color: var(--c-red);
|
||||
}
|
||||
|
||||
[aria-invalid] + p[id] {
|
||||
color: var(--c-red);
|
||||
}
|
||||
|
||||
/* Form spacing */
|
||||
|
||||
form label:not(:first-of-type) {
|
||||
margin-block-start: 3rem;
|
||||
}
|
||||
|
||||
form label + :where(input, textarea, select) {
|
||||
margin-block-start: 0.5rem;
|
||||
}
|
||||
|
||||
form fieldset {
|
||||
margin: 3rem 0;
|
||||
}
|
||||
|
||||
fieldset label:not(:first-of-type) {
|
||||
margin-block-start: 2rem;
|
||||
}
|
||||
|
||||
form p[id] {
|
||||
margin-block-start: 0.5rem;
|
||||
}
|
||||
|
||||
|
||||
/* Dialog
|
||||
========================================
|
||||
*/
|
||||
|
||||
dialog[open] {
|
||||
background-color: Canvas;
|
||||
color: currentColor;
|
||||
display: block;
|
||||
max-width: var(--w-body, 100%);
|
||||
min-width: calc(var(--w-body) / 2);
|
||||
padding: 2rem;
|
||||
border: 2px solid var(--c-gray);
|
||||
border-radius: 0.5rem;
|
||||
}
|
||||
|
||||
body:has(dialog[open]) {
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
dialog:not([open]) {
|
||||
display: none;
|
||||
}
|
||||
|
||||
dialog > *:first-child {
|
||||
margin-block-start: 0;
|
||||
}
|
||||
|
||||
dialog > *:last-child {
|
||||
margin-block-end: 0;
|
||||
}
|
||||
|
||||
|
||||
/* Opinionated layout
|
||||
========================================
|
||||
*/
|
||||
|
||||
@media screen {
|
||||
body > header {
|
||||
margin-block-end: 4em;
|
||||
}
|
||||
|
||||
main > :where(section, article),
|
||||
body > footer {
|
||||
margin-block-start: 4em;
|
||||
clear: both;
|
||||
}
|
||||
|
||||
body > footer {
|
||||
margin-block-start: 4em;
|
||||
}
|
||||
}
|
|
@ -1,13 +0,0 @@
|
|||
<svg
|
||||
enable-background="new 0 0 512 512"
|
||||
viewBox="0 0 512 512"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
>
|
||||
<g
|
||||
transform="rotate(30, 256, 256)"
|
||||
>
|
||||
<path d="m51.6 72.608 199.566-34.825 213.114 34.825c19.867 0 32.553 21.19 23.171 38.701l-206.224 384.92c-9.908 18.492-36.421 18.499-46.337.011l-206.455-384.92c-9.393-17.512 3.293-38.712 23.165-38.712z" fill="#fecb21"/>
|
||||
<path d="m270.254 307.902c0 28.665-23.238 51.902-51.902 51.902s-51.902-23.237-51.902-51.902 23.237-51.902 51.902-51.902 51.902 23.237 51.902 51.902zm65.862 81.954c-25.323-13.433-56.74-3.794-70.173 21.528-13.433 25.323-3.794 56.74 21.528 70.173m48.645-342.08c-28.665 0-51.902 23.237-51.902 51.902s23.237 51.902 51.902 51.902 51.902-23.237 51.902-51.902-23.237-51.902-51.902-51.902zm-182.102-33.763c-28.665 0-51.902 23.237-51.902 51.902s23.237 51.902 51.902 51.902 51.902-23.237 51.902-51.902-23.237-51.902-51.902-51.902z" fill="#f43b22"/>
|
||||
<path d="m41.204 130.519c-13.328.001-26.256-7.039-33.184-19.518-10.167-18.308-3.566-41.391 14.743-51.557 34.605-19.215 72.08-34.048 111.383-44.088 39.334-10.047 80.138-15.214 121.279-15.356 40.982-.14 81.845 4.711 121.369 14.423 40.306 9.904 78.8 24.757 114.412 44.147 18.393 10.014 25.184 33.041 15.17 51.433-10.014 18.391-33.043 25.185-51.433 15.169-29.887-16.273-62.269-28.757-96.246-37.105-33.046-8.12-67.199-12.236-101.53-12.236-.496 0-.986.001-1.481.002-34.903.121-69.481 4.494-102.772 12.998-33.009 8.432-64.412 20.851-93.338 36.912-5.829 3.239-12.145 4.776-18.372 4.776z" fill="#c4790c"/>
|
||||
</g>
|
||||
</svg>
|
Before Width: | Height: | Size: 1.5 KiB |
0
src/ApiResource/.gitignore
vendored
0
src/ApiResource/.gitignore
vendored
35
src/Command/FakeDataCommand.php
Normal file
35
src/Command/FakeDataCommand.php
Normal file
|
@ -0,0 +1,35 @@
|
|||
<?php declare(strict_types=1);
|
||||
|
||||
namespace App\Command;
|
||||
|
||||
use App\Service\FakeData;
|
||||
use Override;
|
||||
use Symfony\Component\Console\Attribute\AsCommand;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
|
||||
#[AsCommand(
|
||||
name: 'app:fake-data',
|
||||
description: 'add some fake data to database',
|
||||
)]
|
||||
final class FakeDataCommand extends Command
|
||||
{
|
||||
public function __construct(
|
||||
private readonly FakeData $fakeData,
|
||||
) {
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
#[Override]
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
$io = new SymfonyStyle($input, $output);
|
||||
$this->fakeData->resetDb();
|
||||
$this->fakeData->generate();
|
||||
|
||||
$io->success('Added some fake data to database');
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
}
|
66
src/Command/MigrateOrderitemsMenuitemsCommand.php
Normal file
66
src/Command/MigrateOrderitemsMenuitemsCommand.php
Normal file
|
@ -0,0 +1,66 @@
|
|||
<?php declare(strict_types=1);
|
||||
|
||||
namespace App\Command;
|
||||
|
||||
use App\Entity\MenuItem;
|
||||
use App\Repository\MenuItemRepository;
|
||||
use App\Repository\OrderItemRepository;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Override;
|
||||
use Symfony\Component\Console\Attribute\AsCommand;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
|
||||
use function sprintf;
|
||||
|
||||
#[AsCommand(
|
||||
name: 'app:migrate-orderitems-menuitems',
|
||||
description: 'Migrate orderitems to menu items',
|
||||
)]
|
||||
final class MigrateOrderitemsMenuitemsCommand extends Command
|
||||
{
|
||||
public function __construct(
|
||||
private readonly EntityManagerInterface $entityManager,
|
||||
private readonly OrderItemRepository $orderItemRepository,
|
||||
private readonly MenuItemRepository $menuItemRepository,
|
||||
) {
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
#[Override]
|
||||
protected function configure(): void {}
|
||||
|
||||
#[Override]
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
$io = new SymfonyStyle($input, $output);
|
||||
$orderItems = $this->orderItemRepository->findAll();
|
||||
|
||||
foreach ($orderItems as $orderItem) {
|
||||
|
||||
$menuItem = $this->menuItemRepository->findOneBy([
|
||||
'name' => $orderItem->getName(),
|
||||
'foodVendor' => $orderItem->getFoodOrder()
|
||||
->getFoodVendor(),
|
||||
]);
|
||||
|
||||
if ($menuItem === null) {
|
||||
$menuItem = new MenuItem;
|
||||
$menuItem->setName($orderItem->getName());
|
||||
$menuItem->setFoodVendor($orderItem->getFoodOrder()->getFoodVendor());
|
||||
$this->entityManager->persist($menuItem);
|
||||
$this->entityManager->flush();
|
||||
$output->writeln(sprintf('Menu item %s added', $menuItem->getName()));
|
||||
}
|
||||
$orderItem->setMenuItem($menuItem);
|
||||
$this->entityManager->persist($orderItem);
|
||||
}
|
||||
|
||||
$this->entityManager->flush();
|
||||
$io->success('You have a new command! Now make it your own! Pass --help to see your options.');
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
}
|
|
@ -14,49 +14,11 @@ use Symfony\Component\Routing\Attribute\Route;
|
|||
#[Route('/food/order')]
|
||||
final class FoodOrderController extends AbstractController
|
||||
{
|
||||
#[Route(
|
||||
path: '/list',
|
||||
name: 'app_food_order_index',
|
||||
methods: ['GET']
|
||||
)]
|
||||
#[Route('/', name: 'app_food_order_index', methods: ['GET'])]
|
||||
public function index(FoodOrderRepository $foodOrderRepository): Response
|
||||
{
|
||||
|
||||
return $this->render('food_order/index.html.twig', [
|
||||
'food_orders' => $foodOrderRepository->findLatestEntries(days: 3),
|
||||
'current_page' => 0,
|
||||
'next_page' => 0,
|
||||
'prev_page' => 0,
|
||||
]);
|
||||
}
|
||||
|
||||
#[Route(
|
||||
path: '/list/archive/{page}',
|
||||
name: 'app_food_order_archive',
|
||||
requirements: [
|
||||
'page' => '\d+',
|
||||
],
|
||||
methods: ['GET']
|
||||
)]
|
||||
public function archive(FoodOrderRepository $foodOrderRepository, int $page = 1): Response
|
||||
{
|
||||
$nextPage = $page + 1;
|
||||
$prevPage = $page - 1;
|
||||
$itemsPerPage = 10;
|
||||
$count = $foodOrderRepository->count();
|
||||
if ($count < $page * $itemsPerPage) {
|
||||
$nextPage = $page;
|
||||
}
|
||||
|
||||
return $this->render('food_order/index.html.twig', [
|
||||
'food_orders' => $foodOrderRepository->findLatestEntries(
|
||||
page: $page,
|
||||
pagesize: $itemsPerPage,
|
||||
days: 0
|
||||
),
|
||||
'current_page' => $page,
|
||||
'next_page' => $nextPage,
|
||||
'prev_page' => $prevPage,
|
||||
'food_orders' => $foodOrderRepository->findLatestEntries(),
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -95,8 +57,7 @@ final class FoodOrderController extends AbstractController
|
|||
#[Route('/{id}/close', name: 'app_food_order_close', methods: ['GET'])]
|
||||
public function close(FoodOrder $foodOrder, FoodOrderRepository $repository): Response
|
||||
{
|
||||
$foodOrder->close();
|
||||
$repository->save();
|
||||
$repository->save($foodOrder->close());
|
||||
return $this->redirectToRoute('app_food_order_show', [
|
||||
'id' => $foodOrder->getId(),
|
||||
], Response::HTTP_SEE_OTHER);
|
||||
|
@ -105,8 +66,7 @@ final class FoodOrderController extends AbstractController
|
|||
#[Route('/{id}/open', name: 'app_food_order_open', methods: ['GET'])]
|
||||
public function open(FoodOrder $foodOrder, FoodOrderRepository $repository): Response
|
||||
{
|
||||
$foodOrder->open();
|
||||
$repository->save();
|
||||
$repository->save($foodOrder->open());
|
||||
return $this->redirectToRoute('app_food_order_show', [
|
||||
'id' => $foodOrder->getId(),
|
||||
], Response::HTTP_SEE_OTHER);
|
||||
|
|
|
@ -23,10 +23,8 @@ final class FoodVendorController extends AbstractController
|
|||
}
|
||||
|
||||
#[Route('/new', name: 'app_food_vendor_new', methods: ['GET', 'POST'])]
|
||||
public function new(
|
||||
Request $request,
|
||||
EntityManagerInterface $entityManager
|
||||
): Response {
|
||||
public function new(Request $request, EntityManagerInterface $entityManager): Response
|
||||
{
|
||||
$foodVendor = new FoodVendor;
|
||||
$form = $this->createForm(FoodVendorType::class, $foodVendor);
|
||||
$form->handleRequest($request);
|
||||
|
@ -65,6 +63,7 @@ final class FoodVendorController extends AbstractController
|
|||
}
|
||||
|
||||
return $this->render('food_vendor/edit.html.twig', [
|
||||
'food_vendor' => $foodVendor,
|
||||
'form' => $form,
|
||||
]);
|
||||
}
|
||||
|
|
|
@ -1,68 +0,0 @@
|
|||
<?php declare(strict_types=1);
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Entity\MenuItem;
|
||||
use App\Form\MenuItemType;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
|
||||
#[Route('/menu/item')]
|
||||
final class MenuItemController extends AbstractController
|
||||
{
|
||||
#[Route('/{id}', name: 'app_menu_item_show', methods: ['GET'])]
|
||||
public function show(MenuItem $menuItem): Response
|
||||
{
|
||||
return $this->render('menu_item/show.html.twig', [
|
||||
'menu_item' => $menuItem,
|
||||
]);
|
||||
}
|
||||
|
||||
#[Route('/{id}/edit', name: 'app_menu_item_edit', methods: ['GET', 'POST'])]
|
||||
public function edit(Request $request, MenuItem $menuItem, EntityManagerInterface $entityManager): Response
|
||||
{
|
||||
$form = $this->createForm(MenuItemType::class, $menuItem);
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
foreach ($menuItem->getFoodVendor()->getMenuItems() as $vendorItem) {
|
||||
if ($menuItem->getAliases()->contains($vendorItem)) {
|
||||
$vendorItem->setAliasOf($menuItem);
|
||||
} elseif ($vendorItem->getAliasOf() === $menuItem) {
|
||||
$vendorItem->setAliasOf(null);
|
||||
|
||||
}
|
||||
$entityManager->persist($vendorItem);
|
||||
}
|
||||
$entityManager->persist($menuItem);
|
||||
|
||||
$entityManager->flush();
|
||||
|
||||
return $this->redirectToRoute('app_menu_item_show', [
|
||||
'id' => $menuItem->getId(),
|
||||
], Response::HTTP_SEE_OTHER);
|
||||
}
|
||||
|
||||
return $this->render('menu_item/edit.html.twig', [
|
||||
'menu_item' => $menuItem,
|
||||
'form' => $form,
|
||||
]);
|
||||
}
|
||||
|
||||
#[Route('/{id}', name: 'app_menu_item_delete', methods: ['POST'])]
|
||||
public function delete(Request $request, MenuItem $menuItem, EntityManagerInterface $entityManager): Response
|
||||
{
|
||||
if ($this->isCsrfTokenValid('delete' . $menuItem->getId(), $request->getPayload()->getString('_token'))) {
|
||||
$menuItem->delete();
|
||||
$entityManager->flush();
|
||||
}
|
||||
|
||||
return $this->redirectToRoute('app_food_vendor_show', [
|
||||
'id' => $menuItem->getFoodVendor()
|
||||
->getId(),
|
||||
], Response::HTTP_SEE_OTHER);
|
||||
}
|
||||
}
|
|
@ -45,11 +45,6 @@ final class OrderItemController extends AbstractController
|
|||
$entityManager->persist($menuItem);
|
||||
}
|
||||
|
||||
if ($menuItem->getAliasOf() !== null) {
|
||||
$menuItem = $menuItem->getAliasOf();
|
||||
$orderItem->setName($menuItem->getName());
|
||||
}
|
||||
|
||||
$orderItem->setMenuItem($menuItem);
|
||||
$orderItem->setFoodOrder($foodOrder);
|
||||
$entityManager->persist($orderItem);
|
||||
|
@ -61,7 +56,6 @@ final class OrderItemController extends AbstractController
|
|||
}
|
||||
$menuItems = $menuItemRepository->findBy([
|
||||
'foodVendor' => $foodOrder->getFoodVendor(),
|
||||
'deletedAt' => null,
|
||||
]);
|
||||
|
||||
return $this->render('order_item/new.html.twig', [
|
||||
|
@ -96,39 +90,18 @@ final class OrderItemController extends AbstractController
|
|||
}
|
||||
|
||||
#[Route('/{id}/edit', name: 'app_order_item_edit', methods: ['GET', 'POST'])]
|
||||
public function edit(
|
||||
Request $request,
|
||||
OrderItem $orderItem,
|
||||
EntityManagerInterface $entityManager,
|
||||
MenuItemRepository $menuItemRepository,
|
||||
): Response {
|
||||
public function edit(Request $request, OrderItem $orderItem, EntityManagerInterface $entityManager): Response
|
||||
{
|
||||
$foodOrder = $orderItem->getFoodOrder();
|
||||
if ($foodOrder->isClosed()) {
|
||||
return $this->redirectToRoute('app_food_order_show', [
|
||||
'id' => $foodOrder->getId(),
|
||||
], Response::HTTP_SEE_OTHER);
|
||||
}
|
||||
$orderItem->setName($orderItem->getMenuItem()->getName());
|
||||
$form = $this->createForm(OrderItemType::class, $orderItem);
|
||||
$form->setData($orderItem);
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
$menuItem = $menuItemRepository->findOneBy([
|
||||
'name' => $orderItem->getName(),
|
||||
'foodVendor' => $foodOrder->getFoodVendor(),
|
||||
]);
|
||||
|
||||
if ($menuItem === null) {
|
||||
$menuItem = new MenuItem;
|
||||
$menuItem->setName($orderItem->getName());
|
||||
$menuItem->setFoodVendor($foodOrder->getFoodVendor());
|
||||
$entityManager->persist($menuItem);
|
||||
}
|
||||
|
||||
$orderItem->setMenuItem($menuItem);
|
||||
$orderItem->setFoodOrder($foodOrder);
|
||||
$entityManager->persist($orderItem);
|
||||
$entityManager->flush();
|
||||
|
||||
return $this->redirectToRoute('app_food_order_show', [
|
||||
|
|
|
@ -1,66 +0,0 @@
|
|||
<?php declare(strict_types=1);
|
||||
|
||||
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;
|
||||
|
||||
use function range;
|
||||
|
||||
final class AppFixtures extends Fixture
|
||||
{
|
||||
private ObjectManager $manager;
|
||||
|
||||
#[Override]
|
||||
public function load(ObjectManager $manager): void
|
||||
{
|
||||
$this->manager = $manager;
|
||||
$vendorA = $this->createVendor('Vendor A');
|
||||
$this->addMenuItemsToVendor($vendorA);
|
||||
|
||||
$vendorB = $this->createVendor('Vendor B');
|
||||
$this->addMenuItemsToVendor($vendorB);
|
||||
}
|
||||
|
||||
public function createVendor(string $name): FoodVendor
|
||||
{
|
||||
$vendorA = new FoodVendor;
|
||||
$vendorA->setName($name);
|
||||
$vendorA->setMenuLink('https://vendora.com');
|
||||
$vendorA->setPhone('1234567890');
|
||||
|
||||
$this->manager->persist($vendorA);
|
||||
$this->manager->flush();
|
||||
return $vendorA;
|
||||
}
|
||||
|
||||
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,22 +2,25 @@
|
|||
|
||||
namespace App\Entity;
|
||||
|
||||
use ApiPlatform\Metadata\ApiResource;
|
||||
use App\Repository\FoodOrderRepository;
|
||||
use DateInterval;
|
||||
use DateTimeImmutable;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Bridge\Doctrine\IdGenerator\UlidGenerator;
|
||||
use Symfony\Bridge\Doctrine\Types\UlidType;
|
||||
use Symfony\Component\Uid\Ulid;
|
||||
|
||||
use function iterator_to_array;
|
||||
|
||||
#[ORM\Entity(repositoryClass: FoodOrderRepository::class)]
|
||||
#[ApiResource]
|
||||
class FoodOrder
|
||||
{
|
||||
#[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(nullable: true)]
|
||||
private DateTimeImmutable|null $closedAt = null;
|
||||
|
||||
|
@ -36,12 +39,8 @@ class FoodOrder
|
|||
])]
|
||||
private string|null $createdBy = 'nobody';
|
||||
|
||||
public function __construct(
|
||||
#[ORM\Id]
|
||||
#[ORM\Column(type: UlidType::NAME, unique: true)]
|
||||
private Ulid|null $id = new Ulid
|
||||
) {
|
||||
$this->id ??= new Ulid;
|
||||
public function __construct()
|
||||
{
|
||||
$this->orderItems = new ArrayCollection;
|
||||
$this->open();
|
||||
}
|
||||
|
@ -61,7 +60,7 @@ class FoodOrder
|
|||
return $this->closedAt;
|
||||
}
|
||||
|
||||
public function setClosedAt(DateTimeImmutable|null $closedAt = null): static
|
||||
public function setClosedAt(DateTimeImmutable|null $closedAt): static
|
||||
{
|
||||
$this->closedAt = $closedAt;
|
||||
|
||||
|
@ -70,10 +69,7 @@ class FoodOrder
|
|||
|
||||
public function isClosed(): bool
|
||||
{
|
||||
if (! $this->closedAt instanceof DateTimeImmutable) {
|
||||
return false;
|
||||
}
|
||||
return $this->closedAt < new DateTimeImmutable;
|
||||
return $this->closedAt instanceof DateTimeImmutable && $this->closedAt->getTimestamp() <= (new DateTimeImmutable)->getTimestamp();
|
||||
}
|
||||
|
||||
public function close(): static
|
||||
|
@ -107,23 +103,6 @@ class FoodOrder
|
|||
return $this->orderItems;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection<int, OrderItem>
|
||||
*/
|
||||
public function getOrderItemsSortedByName(): Collection
|
||||
{
|
||||
$iterator = $this->getOrderItems()
|
||||
->getIterator();
|
||||
$iterator->uasort(
|
||||
static fn(OrderItem $a, OrderItem $b): int => $a->getName() <=> $b->getName()
|
||||
);
|
||||
return new ArrayCollection(
|
||||
iterator_to_array(
|
||||
$iterator
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function addOrderItem(OrderItem $orderItem): static
|
||||
{
|
||||
if (! $this->orderItems->contains($orderItem)) {
|
||||
|
@ -137,7 +116,7 @@ class FoodOrder
|
|||
public function removeOrderItem(OrderItem $orderItem): static
|
||||
{
|
||||
// set the owning side to null (unless already changed)
|
||||
if ($this->orderItems->removeElement($orderItem)) {
|
||||
if ($this->orderItems->removeElement($orderItem) && $orderItem->getFoodOrder() === $this) {
|
||||
$orderItem->setFoodOrder(null);
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
namespace App\Entity;
|
||||
|
||||
use ApiPlatform\Metadata\ApiResource;
|
||||
use App\Repository\FoodVendorRepository;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
|
@ -12,17 +11,17 @@ use Symfony\Bridge\Doctrine\Types\UlidType;
|
|||
use Symfony\Component\Uid\Ulid;
|
||||
|
||||
#[ORM\Entity(repositoryClass: FoodVendorRepository::class)]
|
||||
#[ApiResource]
|
||||
class FoodVendor
|
||||
{
|
||||
#[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: 50)]
|
||||
private string|null $name = null;
|
||||
|
||||
#[ORM\Column(length: 50, nullable: true, options: [
|
||||
'default' => '',
|
||||
])]
|
||||
private string|null $phone = null;
|
||||
|
||||
/**
|
||||
* @var Collection<int, FoodOrder>
|
||||
*/
|
||||
|
@ -35,17 +34,8 @@ class FoodVendor
|
|||
#[ORM\OneToMany(targetEntity: MenuItem::class, mappedBy: 'foodVendor', orphanRemoval: true)]
|
||||
private Collection $menuItems;
|
||||
|
||||
#[ORM\Column(length: 255, nullable: true)]
|
||||
private string|null $menuLink = null;
|
||||
|
||||
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 __construct()
|
||||
{
|
||||
$this->foodOrders = new ArrayCollection;
|
||||
$this->menuItems = new ArrayCollection;
|
||||
}
|
||||
|
@ -88,7 +78,7 @@ class FoodVendor
|
|||
public function removeFoodOrder(FoodOrder $foodOrder): static
|
||||
{
|
||||
// set the owning side to null (unless already changed)
|
||||
if ($this->foodOrders->removeElement($foodOrder)) {
|
||||
if ($this->foodOrders->removeElement($foodOrder) && $foodOrder->getFoodVendor() === $this) {
|
||||
$foodOrder->setFoodVendor(null);
|
||||
}
|
||||
|
||||
|
@ -98,14 +88,9 @@ class FoodVendor
|
|||
/**
|
||||
* @return Collection<int, MenuItem>
|
||||
*/
|
||||
public function getMenuItems(bool $withDeleted = false): Collection
|
||||
public function getMenuItems(): Collection
|
||||
{
|
||||
if ($withDeleted) {
|
||||
return $this->menuItems;
|
||||
}
|
||||
return $this->menuItems->filter(
|
||||
static fn(MenuItem $item): bool => $item->isDeleted() === false
|
||||
);
|
||||
return $this->menuItems;
|
||||
}
|
||||
|
||||
public function addMenuItem(MenuItem $menuItem): static
|
||||
|
@ -121,33 +106,10 @@ class FoodVendor
|
|||
public function removeMenuItem(MenuItem $menuItem): static
|
||||
{
|
||||
// set the owning side to null (unless already changed)
|
||||
if ($this->menuItems->removeElement($menuItem)) {
|
||||
if ($this->menuItems->removeElement($menuItem) && $menuItem->getFoodVendor() === $this) {
|
||||
$menuItem->setFoodVendor(null);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getMenuLink(): string|null
|
||||
{
|
||||
return $this->menuLink;
|
||||
}
|
||||
|
||||
public function setMenuLink(string|null $menuLink): static
|
||||
{
|
||||
$this->menuLink = $menuLink;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getPhone(): string|null
|
||||
{
|
||||
return $this->phone;
|
||||
}
|
||||
|
||||
public function setPhone(string|null $phone): static
|
||||
{
|
||||
$this->phone = $phone;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,20 +2,21 @@
|
|||
|
||||
namespace App\Entity;
|
||||
|
||||
use ApiPlatform\Metadata\ApiResource;
|
||||
use App\Repository\MenuItemRepository;
|
||||
use DateTimeImmutable;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Bridge\Doctrine\IdGenerator\UlidGenerator;
|
||||
use Symfony\Bridge\Doctrine\Types\UlidType;
|
||||
use Symfony\Component\Uid\Ulid;
|
||||
|
||||
#[ORM\Entity(repositoryClass: MenuItemRepository::class)]
|
||||
#[ApiResource]
|
||||
class MenuItem
|
||||
{
|
||||
#[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;
|
||||
|
||||
|
@ -23,29 +24,6 @@ class MenuItem
|
|||
#[ORM\JoinColumn(nullable: false)]
|
||||
private FoodVendor|null $foodVendor = null;
|
||||
|
||||
#[ORM\Column(nullable: true)]
|
||||
private DateTimeImmutable|null $deletedAt = null;
|
||||
|
||||
#[ORM\ManyToOne(targetEntity: self::class, inversedBy: 'aliases')]
|
||||
private self|null $aliasOf = null;
|
||||
|
||||
/**
|
||||
* @var Collection<int, self>
|
||||
*/
|
||||
#[ORM\OneToMany(targetEntity: self::class, mappedBy: 'aliasOf')]
|
||||
private Collection $aliases;
|
||||
|
||||
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;
|
||||
$this->aliases = new ArrayCollection;
|
||||
}
|
||||
|
||||
public function getId(): Ulid|null
|
||||
{
|
||||
return $this->id;
|
||||
|
@ -74,67 +52,4 @@ class MenuItem
|
|||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function isDeleted(): bool
|
||||
{
|
||||
return $this->getDeletedAt() instanceof DateTimeImmutable;
|
||||
}
|
||||
|
||||
public function delete(): static
|
||||
{
|
||||
$this->setDeletedAt(new DateTimeImmutable);
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getDeletedAt(): DateTimeImmutable|null
|
||||
{
|
||||
return $this->deletedAt;
|
||||
}
|
||||
|
||||
public function setDeletedAt(DateTimeImmutable|null $deletedAt = new DateTimeImmutable): static
|
||||
{
|
||||
$this->deletedAt = $deletedAt;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getAliasOf(): self|null
|
||||
{
|
||||
return $this->aliasOf;
|
||||
}
|
||||
|
||||
public function setAliasOf(self|null $aliasOf): static
|
||||
{
|
||||
$this->aliasOf = $aliasOf;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection<int, self>
|
||||
*/
|
||||
public function getAliases(): Collection
|
||||
{
|
||||
return $this->aliases;
|
||||
}
|
||||
|
||||
public function addAlias(self $alias): static
|
||||
{
|
||||
if (! $this->aliases->contains($alias)) {
|
||||
$this->aliases->add($alias);
|
||||
$alias->setAliasOf($this);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function removeAlias(self $alias): static
|
||||
{
|
||||
// set the owning side to null (unless already changed)
|
||||
if ($this->aliases->removeElement($alias) && $alias->getAliasOf() === $this) {
|
||||
$alias->setAliasOf(null);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
namespace App\Entity;
|
||||
|
||||
use ApiPlatform\Metadata\ApiResource;
|
||||
use App\Repository\OrderItemRepository;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Bridge\Doctrine\IdGenerator\UlidGenerator;
|
||||
|
@ -10,9 +9,14 @@ 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;
|
||||
|
||||
|
@ -32,16 +36,6 @@ 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;
|
||||
|
@ -91,7 +85,6 @@ class OrderItem
|
|||
public function setMenuItem(MenuItem|null $menuItem): static
|
||||
{
|
||||
$this->menuItem = $menuItem;
|
||||
$this->name = $menuItem->getName();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
|
|
@ -2,11 +2,13 @@
|
|||
|
||||
namespace App\Form;
|
||||
|
||||
use App\Entity\FoodOrder;
|
||||
use App\Entity\FoodVendor;
|
||||
use Override;
|
||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
final class FoodOrderType extends AbstractType
|
||||
{
|
||||
|
@ -21,7 +23,6 @@ final class FoodOrderType extends AbstractType
|
|||
])
|
||||
->add(child: 'closedAt', options: [
|
||||
'label' => 'closes at',
|
||||
'view_timezone' => 'Europe/Berlin',
|
||||
])
|
||||
->add(child: 'createdBy')
|
||||
;
|
||||
|
@ -29,4 +30,12 @@ final class FoodOrderType extends AbstractType
|
|||
$builder->setAction($action);
|
||||
}
|
||||
}
|
||||
|
||||
#[Override]
|
||||
public function configureOptions(OptionsResolver $resolver): void
|
||||
{
|
||||
$resolver->setDefaults([
|
||||
'data_class' => FoodOrder::class,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,8 +15,6 @@ final class FoodVendorType extends AbstractType
|
|||
{
|
||||
$builder
|
||||
->add('name')
|
||||
->add('menuLink')
|
||||
->add('phone')
|
||||
;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,49 +0,0 @@
|
|||
<?php declare(strict_types=1);
|
||||
|
||||
namespace App\Form;
|
||||
|
||||
use App\Entity\MenuItem;
|
||||
use App\Repository\MenuItemRepository;
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
use Override;
|
||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
use Symfony\Component\Validator\Constraints\Length;
|
||||
use Symfony\Component\Validator\Constraints\NotBlank;
|
||||
|
||||
final class MenuItemType extends AbstractType
|
||||
{
|
||||
#[Override]
|
||||
public function buildForm(FormBuilderInterface $builder, array $options): void
|
||||
{
|
||||
$item = $options['data'];
|
||||
|
||||
$builder->add('name', TextType::class, [
|
||||
'constraints' => [
|
||||
new NotBlank,
|
||||
new Length([
|
||||
'min' => 3,
|
||||
]),
|
||||
],
|
||||
]);
|
||||
$builder->add('aliases', EntityType::class, [
|
||||
'class' => MenuItem::class,
|
||||
'choice_label' => 'name',
|
||||
'multiple' => true,
|
||||
'expanded' => true,
|
||||
'query_builder' => static fn(MenuItemRepository $repository): QueryBuilder
|
||||
=> $repository->getSuitableAliasQueryBuilder($item),
|
||||
]);
|
||||
}
|
||||
|
||||
#[Override]
|
||||
public function configureOptions(OptionsResolver $resolver): void
|
||||
{
|
||||
$resolver->setDefaults([
|
||||
'data_class' => MenuItem::class,
|
||||
]);
|
||||
}
|
||||
}
|
|
@ -15,12 +15,10 @@ final class OrderItemType extends AbstractType
|
|||
{
|
||||
$builder
|
||||
->add(child: 'name', options: [
|
||||
'label' => 'order item',
|
||||
])
|
||||
->add(child: 'extras')
|
||||
->add(child: 'createdBy', options: [
|
||||
'label' => 'your name',
|
||||
'data' => $options['name'] ?? '',
|
||||
])
|
||||
->add('extras')
|
||||
->add('createdBy')
|
||||
;
|
||||
}
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ namespace App\Form;
|
|||
use Override;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
final class UserNameFormType extends AbstractType
|
||||
{
|
||||
|
@ -12,7 +13,17 @@ final class UserNameFormType extends AbstractType
|
|||
public function buildForm(FormBuilderInterface $builder, array $options): void
|
||||
{
|
||||
$builder
|
||||
->add(child: 'username')
|
||||
->add(child: 'username', options: [
|
||||
'required' => false,
|
||||
])
|
||||
;
|
||||
}
|
||||
|
||||
#[Override]
|
||||
public function configureOptions(OptionsResolver $resolver): void
|
||||
{
|
||||
$resolver->setDefaults([
|
||||
// Configure your form options here
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,10 +3,7 @@
|
|||
namespace App\Repository;
|
||||
|
||||
use App\Entity\FoodOrder;
|
||||
use DateInterval;
|
||||
use DateTimeImmutable;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
|
||||
/**
|
||||
|
@ -19,8 +16,10 @@ final class FoodOrderRepository extends ServiceEntityRepository
|
|||
parent::__construct($registry, FoodOrder::class);
|
||||
}
|
||||
|
||||
public function save(): void
|
||||
public function save(FoodOrder $order): void
|
||||
{
|
||||
$this->getEntityManager()
|
||||
->persist($order);
|
||||
$this->getEntityManager()
|
||||
->flush();
|
||||
}
|
||||
|
@ -28,23 +27,15 @@ final class FoodOrderRepository extends ServiceEntityRepository
|
|||
/**
|
||||
* @return FoodOrder[]
|
||||
*/
|
||||
public function findLatestEntries(int $page = 1, int $pagesize = 10, int $days = 4): array
|
||||
public function findLatestEntries(int $limit = 5): array
|
||||
{
|
||||
$qb = $this->createQueryBuilder('alias');
|
||||
|
||||
$result = $this->createQueryBuilder('alias')
|
||||
->orderBy('alias.id', 'DESC')
|
||||
->setFirstResult(($page - 1) * $pagesize)
|
||||
->setMaxResults($pagesize)
|
||||
->getQuery()
|
||||
->getResult();
|
||||
$qb->orderBy('alias.id', 'DESC');
|
||||
$qb->setMaxResults($limit);
|
||||
|
||||
if ($days < 1) {
|
||||
return $result;
|
||||
}
|
||||
$query = $qb->getQuery();
|
||||
|
||||
$date = (new DateTimeImmutable)->sub(new DateInterval('P' . $days . 'D'));
|
||||
return (new ArrayCollection($result))
|
||||
->filter(static fn(FoodOrder $order): bool => $order->getCreatedAt() >= $date)
|
||||
->getValues();
|
||||
return $query->getResult();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,12 +4,7 @@ namespace App\Repository;
|
|||
|
||||
use App\Entity\MenuItem;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
use Symfony\Bridge\Doctrine\Types\UlidType;
|
||||
use Symfony\Component\Uid\Ulid;
|
||||
|
||||
use function array_map;
|
||||
|
||||
/**
|
||||
* @extends ServiceEntityRepository<MenuItem>
|
||||
|
@ -21,29 +16,28 @@ final class MenuItemRepository extends ServiceEntityRepository
|
|||
parent::__construct($registry, MenuItem::class);
|
||||
}
|
||||
|
||||
public function getSuitableAliasQueryBuilder(MenuItem $menuItem): QueryBuilder
|
||||
{
|
||||
$ids = $this->createQueryBuilder('m')
|
||||
->select('DISTINCT IDENTITY(m.aliasOf)')
|
||||
->where('m.deletedAt IS NULL')
|
||||
->andWhere('m.aliasOf IS NOT NULL')
|
||||
->getquery();
|
||||
$ids = $ids->getScalarResult();
|
||||
$ids = array_map(static fn(array $id): Ulid => Ulid::fromBinary($id[1]), $ids);
|
||||
// /**
|
||||
// * @return MenuItem[] Returns an array of MenuItem objects
|
||||
// */
|
||||
// public function findByExampleField($value): array
|
||||
// {
|
||||
// return $this->createQueryBuilder('m')
|
||||
// ->andWhere('m.exampleField = :val')
|
||||
// ->setParameter('val', $value)
|
||||
// ->orderBy('m.id', 'ASC')
|
||||
// ->setMaxResults(10)
|
||||
// ->getQuery()
|
||||
// ->getResult()
|
||||
// ;
|
||||
// }
|
||||
|
||||
$qb = $this->createQueryBuilder('m');
|
||||
$qb
|
||||
->where('m.foodVendor = :vendorId')
|
||||
->andWhere('m.deletedAt IS NULL')
|
||||
->andWhere('m.id != :id');
|
||||
foreach ($ids as $key => $id) {
|
||||
$qb->andWhere("m.id != :idBy{$key}")
|
||||
->setParameter("idBy{$key}", $id, UlidType::NAME);
|
||||
}
|
||||
$qb
|
||||
->orderBy('m.name', 'ASC')
|
||||
->setParameter('vendorId', $menuItem->getFoodVendor()->getId(), UlidType::NAME)
|
||||
->setParameter('id', $menuItem->getId(), UlidType::NAME);
|
||||
return $qb;
|
||||
}
|
||||
// public function findOneBySomeField($value): ?MenuItem
|
||||
// {
|
||||
// return $this->createQueryBuilder('m')
|
||||
// ->andWhere('m.exampleField = :val')
|
||||
// ->setParameter('val', $value)
|
||||
// ->getQuery()
|
||||
// ->getOneOrNullResult()
|
||||
// ;
|
||||
// }
|
||||
}
|
||||
|
|
100
src/Service/FakeData.php
Normal file
100
src/Service/FakeData.php
Normal file
|
@ -0,0 +1,100 @@
|
|||
<?php declare(strict_types=1);
|
||||
|
||||
namespace App\Service;
|
||||
|
||||
use App\Entity\FoodOrder;
|
||||
use App\Entity\FoodVendor;
|
||||
use App\Entity\OrderItem;
|
||||
use App\Repository\FoodOrderRepository;
|
||||
use App\Repository\FoodVendorRepository;
|
||||
use App\Repository\OrderItemRepository;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
|
||||
use function range;
|
||||
|
||||
final readonly class FakeData
|
||||
{
|
||||
public function __construct(
|
||||
private EntityManagerInterface $entityManager,
|
||||
private FoodVendorRepository $foodVendorRepository,
|
||||
private FoodOrderRepository $foodOrderRepository,
|
||||
private OrderItemRepository $orderItemRepository,
|
||||
) {}
|
||||
|
||||
public function resetDb(): void
|
||||
{
|
||||
foreach ($this->orderItemRepository->findAll() as $item) {
|
||||
$this->entityManager->remove($item);
|
||||
}
|
||||
foreach ($this->foodOrderRepository->findAll() as $item) {
|
||||
$this->entityManager->remove($item);
|
||||
}
|
||||
foreach ($this->foodVendorRepository->findAll() as $item) {
|
||||
$this->entityManager->remove($item);
|
||||
}
|
||||
}
|
||||
|
||||
public function generate(int $vendorAmount = 3, int $orderAmount = 4, int $itemAmount = 10): void
|
||||
{
|
||||
$vendors = $this->generateVendors($vendorAmount);
|
||||
foreach ($vendors as $vendor) {
|
||||
$orders = $this->generateOrdersForVendor($vendor, $orderAmount);
|
||||
foreach ($orders as $order) {
|
||||
$this->generateItemsForOrder($order, $itemAmount);
|
||||
}
|
||||
}
|
||||
$this->entityManager->flush();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return FoodVendor[]
|
||||
*/
|
||||
public function generateVendors(int $amount = 10): array
|
||||
{
|
||||
$vendors = [];
|
||||
foreach (range(1, $amount) as $i) {
|
||||
$vendor = new FoodVendor;
|
||||
$vendor->setName('Food Vendor ' . $i);
|
||||
$this->entityManager->persist($vendor);
|
||||
$vendors[] = $vendor;
|
||||
}
|
||||
return $vendors;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return FoodOrder[]
|
||||
*/
|
||||
public function generateOrdersForVendor(FoodVendor $vendor, int $amount = 10): array
|
||||
{
|
||||
$orders = [];
|
||||
foreach (range(1, $amount) as $i) {
|
||||
$order = new FoodOrder;
|
||||
$order->setFoodVendor($vendor);
|
||||
if ($i % 2 === 0) {
|
||||
$order->close();
|
||||
}
|
||||
$this->entityManager->persist($order);
|
||||
$orders[] = $order;
|
||||
}
|
||||
return $orders;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return OrderItem[]
|
||||
*/
|
||||
public function generateItemsForOrder(FoodOrder $order, int $amount = 10): array
|
||||
{
|
||||
$items = [];
|
||||
foreach (range(1, $amount) as $i) {
|
||||
$item = new OrderItem;
|
||||
$item->setName('Item ' . $i);
|
||||
$item->setFoodOrder($order);
|
||||
if ($i % 2 === 0) {
|
||||
$item->setExtras('Extra ' . $i);
|
||||
}
|
||||
$this->entityManager->persist($item);
|
||||
$items[] = $item;
|
||||
}
|
||||
return $items;
|
||||
}
|
||||
}
|
|
@ -1,18 +0,0 @@
|
|||
<?php declare(strict_types=1);
|
||||
|
||||
namespace App\Service;
|
||||
|
||||
use Override;
|
||||
use Stringable;
|
||||
|
||||
use function random_int;
|
||||
|
||||
final class Favicon implements Stringable
|
||||
{
|
||||
#[Override]
|
||||
public function __toString(): string
|
||||
{
|
||||
$rotate = random_int(0, 380);
|
||||
return "data:image/svg+xml, %3Csvg enable-background='new 0 0 512 512' viewBox='0 0 512 512' xmlns='http://www.w3.org/2000/svg' %3E%3Cg transform='rotate({$rotate}, 256, 256)' %3E%3Cpath d='m51.6 72.608 199.566-34.825 213.114 34.825c19.867 0 32.553 21.19 23.171 38.701l-206.224 384.92c-9.908 18.492-36.421 18.499-46.337.011l-206.455-384.92c-9.393-17.512 3.293-38.712 23.165-38.712z' fill='%23fecb21'/%3E%3Cpath d='m270.254 307.902c0 28.665-23.238 51.902-51.902 51.902s-51.902-23.237-51.902-51.902 23.237-51.902 51.902-51.902 51.902 23.237 51.902 51.902zm65.862 81.954c-25.323-13.433-56.74-3.794-70.173 21.528-13.433 25.323-3.794 56.74 21.528 70.173m48.645-342.08c-28.665 0-51.902 23.237-51.902 51.902s23.237 51.902 51.902 51.902 51.902-23.237 51.902-51.902-23.237-51.902-51.902-51.902zm-182.102-33.763c-28.665 0-51.902 23.237-51.902 51.902s23.237 51.902 51.902 51.902 51.902-23.237 51.902-51.902-23.237-51.902-51.902-51.902z' fill='%23f43b22'/%3E%3Cpath d='m41.204 130.519c-13.328.001-26.256-7.039-33.184-19.518-10.167-18.308-3.566-41.391 14.743-51.557 34.605-19.215 72.08-34.048 111.383-44.088 39.334-10.047 80.138-15.214 121.279-15.356 40.982-.14 81.845 4.711 121.369 14.423 40.306 9.904 78.8 24.757 114.412 44.147 18.393 10.014 25.184 33.041 15.17 51.433-10.014 18.391-33.043 25.185-51.433 15.169-29.887-16.273-62.269-28.757-96.246-37.105-33.046-8.12-67.199-12.236-101.53-12.236-.496 0-.986.001-1.481.002-34.903.121-69.481 4.494-102.772 12.998-33.009 8.432-64.412 20.851-93.338 36.912-5.829 3.239-12.145 4.776-18.372 4.776z' fill='%23c4790c'/%3E%3C/g%3E%3C/svg%3E%0A";
|
||||
}
|
||||
}
|
84
symfony.lock
84
symfony.lock
|
@ -1,18 +1,4 @@
|
|||
{
|
||||
"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": {
|
||||
|
@ -27,18 +13,6 @@
|
|||
"src/Repository/.gitignore"
|
||||
]
|
||||
},
|
||||
"doctrine/doctrine-fixtures-bundle": {
|
||||
"version": "4.0",
|
||||
"recipe": {
|
||||
"repo": "github.com/symfony/recipes",
|
||||
"branch": "main",
|
||||
"version": "3.0",
|
||||
"ref": "1f5514cfa15b947298df4d771e694e578d4c204d"
|
||||
},
|
||||
"files": [
|
||||
"src/DataFixtures/AppFixtures.php"
|
||||
]
|
||||
},
|
||||
"doctrine/doctrine-migrations-bundle": {
|
||||
"version": "3.3",
|
||||
"recipe": {
|
||||
|
@ -52,21 +26,6 @@
|
|||
"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": {
|
||||
|
@ -77,7 +36,7 @@
|
|||
}
|
||||
},
|
||||
"phpunit/phpunit": {
|
||||
"version": "11.4",
|
||||
"version": "9.6",
|
||||
"recipe": {
|
||||
"repo": "github.com/symfony/recipes",
|
||||
"branch": "main",
|
||||
|
@ -151,6 +110,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": {
|
||||
|
@ -164,19 +138,6 @@
|
|||
"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": {
|
||||
|
@ -210,18 +171,5 @@
|
|||
"files": [
|
||||
"config/packages/validator.yaml"
|
||||
]
|
||||
},
|
||||
"symfony/web-profiler-bundle": {
|
||||
"version": "7.1",
|
||||
"recipe": {
|
||||
"repo": "github.com/symfony/recipes",
|
||||
"branch": "main",
|
||||
"version": "6.1",
|
||||
"ref": "e42b3f0177df239add25373083a564e5ead4e13a"
|
||||
},
|
||||
"files": [
|
||||
"config/packages/web_profiler.yaml",
|
||||
"config/routes/web_profiler.yaml"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,22 +2,9 @@
|
|||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="color-scheme" content="dark light">
|
||||
<meta name="theme-color" content="#0000ff" media="(prefers-color-scheme: light)">
|
||||
<meta name="theme-color" content="#222222" media="(prefers-color-scheme: dark)">
|
||||
<title>{% block title %}Welcome!{% endblock %}</title>
|
||||
<link rel="icon" type="image/svg+xml"
|
||||
href="{{ favicon }}" />
|
||||
{% set currentDate = "now"|date("d") %}
|
||||
{% if currentDate % 4 == 0 %}
|
||||
<link rel="stylesheet" href="/static/css/new.min.css">
|
||||
{% elseif currentDate % 4 == 1 %}
|
||||
<link rel="stylesheet" href="/static/css/simple.min.css">
|
||||
{% elseif currentDate % 4 == 2 %}
|
||||
<link rel="stylesheet" href="/static/css/water.min.css">
|
||||
{% else %}
|
||||
<link rel="stylesheet" href="/static/css/fieber.css">
|
||||
{% endif %}
|
||||
<link rel="icon" type="image/png" href="/static/img/slice-of-pizza.png" />
|
||||
<link rel="stylesheet" href="/static/css/new.min.css">
|
||||
<style>
|
||||
label{
|
||||
display: block;
|
||||
|
@ -32,10 +19,9 @@
|
|||
<a href="{{ path('app_food_order_index') }}">Orders</a> /
|
||||
<a href="{{ path('app_food_vendor_index') }}">Vendors</a> /
|
||||
<a
|
||||
href="https://git.hannover.ccc.de/lubiana/futtern/issues/new"
|
||||
href="https://hannover.ccc.de/gitlab/lubiana/futtern/issues/new"
|
||||
target="_blank"
|
||||
>Create Issue</a> /
|
||||
<a href="/api">API</a>
|
||||
>Create Issue</a>
|
||||
</nav>
|
||||
</header>
|
||||
<main>
|
||||
|
|
|
@ -4,14 +4,7 @@
|
|||
|
||||
{% block body %}
|
||||
<h1>FoodOrder index</h1>
|
||||
<div>
|
||||
<button
|
||||
hx-get="{{ path('app_food_order_new') }}"
|
||||
hx-trigger="click"
|
||||
hx-target="closest div"
|
||||
>Create new</button>
|
||||
</div>
|
||||
<hr>
|
||||
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
|
@ -25,21 +18,18 @@
|
|||
<tbody>
|
||||
{% for food_order in food_orders %}
|
||||
{{ include('food_order/table_row.html.twig') }}
|
||||
{% endfor %}
|
||||
{% if food_orders|length < 10 %}
|
||||
{% else %}
|
||||
<tr>
|
||||
<td colspan="5">
|
||||
check the <a href="{{ path('app_food_order_archive') }}">archive</a>
|
||||
for older orders
|
||||
</td>
|
||||
<td colspan="4">no records found</td>
|
||||
</tr>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
{% if prev_page > 0 %}
|
||||
<a href="{{ path('app_food_order_archive', {'page': prev_page}) }}">previous page</a> |
|
||||
{% endif %}
|
||||
{% if next_page > current_page %}
|
||||
<a href="{{ path('app_food_order_archive', {'page': next_page}) }}">next page</a>
|
||||
{% endif %}
|
||||
<div>
|
||||
<button
|
||||
hx-get="{{ path('app_food_order_new') }}"
|
||||
hx-trigger="click"
|
||||
hx-target="closest div"
|
||||
>Create new</button>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
|
|
@ -11,21 +11,17 @@
|
|||
<th>Vendor</th>
|
||||
<td>{{ food_order.foodVendor.name }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Vendorphone</th>
|
||||
<td>{{ food_order.foodVendor.phone }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Created By</th>
|
||||
<td>{{ food_order.createdBy }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>CreatedAt</th>
|
||||
<td>{{ food_order.createdAt ? food_order.createdAt|date('Y-m-d H:i:s', 'Europe/Berlin') : '' }}</td>
|
||||
<td>{{ food_order.createdAt ? food_order.createdAt|date('Y-m-d H:i:s') : '' }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>ClosedAt</th>
|
||||
<td>{{ food_order.closedAt ? food_order.closedAt|date('Y-m-d H:i:s', 'Europe/Berlin') : '' }}</td>
|
||||
<td>{{ food_order.closedAt ? food_order.closedAt|date('Y-m-d H:i:s') : '' }}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
@ -40,7 +36,6 @@
|
|||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Index</th>
|
||||
<th>username</th>
|
||||
<th>name</th>
|
||||
<th>extras</th>
|
||||
|
@ -48,9 +43,8 @@
|
|||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for item in food_order.orderItemsSortedByName %}
|
||||
{% for item in food_order.orderItems %}
|
||||
<tr>
|
||||
<td>{{ loop.index }}</td>
|
||||
<td>{{ item.createdBy }}</td>
|
||||
<td>{{ item.name }}</td>
|
||||
<td>{{ item.extras }}</td>
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
<tr>
|
||||
<td>{{ food_order.createdBy }}</td>
|
||||
<td>{{ food_order.foodVendor.name }}</td>
|
||||
<td>{{ food_order.createdAt ? food_order.createdAt|date('Y-m-d H:i:s', 'Europe/Berlin') : '' }}</td>
|
||||
<td>{{ food_order.closedAt ? food_order.closedAt|date('Y-m-d H:i:s', 'Europe/Berlin') : '' }}</td>
|
||||
<td>{{ food_order.createdAt ? food_order.createdAt|date('Y-m-d H:i:s') : '' }}</td>
|
||||
<td>{{ food_order.closedAt ? food_order.closedAt|date('Y-m-d H:i:s') : '' }}</td>
|
||||
<td>
|
||||
<a href="{{ path('app_food_order_show', {'id': food_order.id}) }}">show</a>
|
||||
</td>
|
||||
|
|
|
@ -11,29 +11,9 @@
|
|||
<th>Name</th>
|
||||
<td>{{ food_vendor.name }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Menu</th>
|
||||
<td><a href="{{ food_vendor.menuLink }}" target="_blank">{{ food_vendor.menuLink }}</a></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<section>
|
||||
<h2>known menuitems</h2>
|
||||
<ul>
|
||||
{% for item in food_vendor.menuItems %}
|
||||
<li>
|
||||
<a href="{{ path('app_menu_item_show', {'id': item.id}) }}">{{ item.name }}</a>
|
||||
{% if(item.aliasOf) %}
|
||||
(alias of: {{ item.aliasOf.name }})
|
||||
{% endif %}
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
|
||||
</section>
|
||||
|
||||
|
||||
<a href="{{ path('app_food_vendor_index') }}">back to list</a>
|
||||
|
||||
<a href="{{ path('app_food_vendor_edit', {'id': food_vendor.id}) }}">edit</a>
|
||||
|
|
|
@ -1,4 +0,0 @@
|
|||
<form method="post" action="{{ path('app_menu_item_delete', {'id': menu_item.id}) }}" onsubmit="return confirm('Are you sure you want to delete this item?');">
|
||||
<input type="hidden" name="_token" value="{{ csrf_token('delete' ~ menu_item.id) }}">
|
||||
<button class="btn">Delete</button>
|
||||
</form>
|
|
@ -1,4 +0,0 @@
|
|||
{{ form_start(form) }}
|
||||
{{ form_widget(form) }}
|
||||
<button class="btn">{{ button_label|default('Save') }}</button>
|
||||
{{ form_end(form) }}
|
|
@ -1,11 +0,0 @@
|
|||
{% extends 'base.html.twig' %}
|
||||
|
||||
{% block title %}Edit MenuItem{% endblock %}
|
||||
|
||||
{% block body %}
|
||||
<h1>Edit MenuItem</h1>
|
||||
|
||||
{{ include('menu_item/_form.html.twig', {'button_label': 'Update'}) }}
|
||||
|
||||
{{ include('menu_item/_delete_form.html.twig') }}
|
||||
{% endblock %}
|
|
@ -1,35 +0,0 @@
|
|||
{% extends 'base.html.twig' %}
|
||||
|
||||
{% block title %}MenuItem index{% endblock %}
|
||||
|
||||
{% block body %}
|
||||
<h1>MenuItem index</h1>
|
||||
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Id</th>
|
||||
<th>Name</th>
|
||||
<th>actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for menu_item in menu_items %}
|
||||
<tr>
|
||||
<td>{{ menu_item.id }}</td>
|
||||
<td>{{ menu_item.name }}</td>
|
||||
<td>
|
||||
<a href="{{ path('app_menu_item_show', {'id': menu_item.id}) }}">show</a>
|
||||
<a href="{{ path('app_menu_item_edit', {'id': menu_item.id}) }}">edit</a>
|
||||
</td>
|
||||
</tr>
|
||||
{% else %}
|
||||
<tr>
|
||||
<td colspan="3">no records found</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<a href="{{ path('app_menu_item_new') }}">Create new</a>
|
||||
{% endblock %}
|
|
@ -1,11 +0,0 @@
|
|||
{% extends 'base.html.twig' %}
|
||||
|
||||
{% block title %}New MenuItem{% endblock %}
|
||||
|
||||
{% block body %}
|
||||
<h1>Create new MenuItem</h1>
|
||||
|
||||
{{ include('menu_item/_form.html.twig') }}
|
||||
|
||||
<a href="{{ path('app_menu_item_index') }}">back to list</a>
|
||||
{% endblock %}
|
|
@ -1,44 +0,0 @@
|
|||
{% extends 'base.html.twig' %}
|
||||
|
||||
{% block title %}MenuItem{% endblock %}
|
||||
|
||||
{% block body %}
|
||||
<h1>MenuItem</h1>
|
||||
|
||||
<table class="table">
|
||||
<tbody>
|
||||
<tr>
|
||||
<th>Id</th>
|
||||
<td>{{ menu_item.id }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<td>{{ menu_item.name }}</td>
|
||||
</tr>
|
||||
{% if(menu_item.aliasOf) %}
|
||||
<tr>
|
||||
<th>Alias of</th>
|
||||
<td>{{ menu_item.aliasOf.name }}</td>
|
||||
</tr>
|
||||
{% endif %}
|
||||
{% if(menu_item.aliases|length > 0) %}
|
||||
<tr>
|
||||
<th>Aliases</th>
|
||||
<td>
|
||||
<ul>
|
||||
{% for alias in menu_item.aliases %}
|
||||
<li>{{ alias.name }}</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</td>
|
||||
</tr>
|
||||
{% endif %}
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<a href="{{ path('app_food_vendor_show', { 'id': menu_item.foodVendor.id}) }}">back to list</a>
|
||||
|
||||
<a href="{{ path('app_menu_item_edit', {'id': menu_item.id}) }}">edit</a>
|
||||
|
||||
{{ include('menu_item/_delete_form.html.twig') }}
|
||||
{% endblock %}
|
|
@ -7,14 +7,6 @@
|
|||
|
||||
{{ include('order_item/_form.html.twig') }}
|
||||
|
||||
<hr />
|
||||
|
||||
{% if food_order.foodVendor.menuLink != '' %}
|
||||
<a href="{{ food_order.foodVendor.menuLink }}" target="_blank">
|
||||
External link to Menu
|
||||
</a>
|
||||
{% endif %}
|
||||
|
||||
<div>
|
||||
<b>click a button to select a given menuitem</b>
|
||||
</div>
|
||||
|
|
67
tests/Controller/FoodOrderControllerTest.php
Normal file
67
tests/Controller/FoodOrderControllerTest.php
Normal file
|
@ -0,0 +1,67 @@
|
|||
<?php declare(strict_types=1);
|
||||
|
||||
namespace App\Tests\Controller;
|
||||
|
||||
use App\Entity\FoodOrder;
|
||||
use App\Entity\FoodVendor;
|
||||
use App\Tests\DbWebTest;
|
||||
use Override;
|
||||
use Symfony\Component\DomCrawler\Crawler;
|
||||
|
||||
use function sprintf;
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
#[Override]
|
||||
public function getEntityClass(): string
|
||||
{
|
||||
return FoodOrder::class;
|
||||
}
|
||||
|
||||
public function testIndex(): void
|
||||
{
|
||||
$order = new FoodOrder;
|
||||
$order->setFoodVendor($this->vendor);
|
||||
|
||||
$this->manager->persist($order);
|
||||
$this->manager->persist($this->vendor);
|
||||
$this->manager->flush();
|
||||
|
||||
$crawler = $this->client->request('GET', $this->path);
|
||||
self::assertResponseStatusCodeSame(200);
|
||||
self::assertPageTitleContains('FoodOrder index');
|
||||
$this->assertCount(
|
||||
1,
|
||||
$crawler->filter('td')
|
||||
->reduce(fn(Crawler $node, $i): bool => $node->text() === $this->vendor->getName()),
|
||||
);
|
||||
}
|
||||
|
||||
public function testNew(): void
|
||||
{
|
||||
$this->client->request('GET', sprintf('%snew', $this->path));
|
||||
|
||||
self::assertResponseStatusCodeSame(200);
|
||||
|
||||
$this->client->submitForm('Save', [
|
||||
'food_order[foodVendor]' => $this->vendor->getId(),
|
||||
]);
|
||||
|
||||
self::assertResponseRedirects($this->path);
|
||||
self::assertSame(1, $this->repository->count([]));
|
||||
}
|
||||
}
|
78
tests/Controller/FoodVendorControllerTest.php
Normal file
78
tests/Controller/FoodVendorControllerTest.php
Normal file
|
@ -0,0 +1,78 @@
|
|||
<?php declare(strict_types=1);
|
||||
|
||||
namespace App\Tests\Controller;
|
||||
|
||||
use App\Entity\FoodVendor;
|
||||
use App\Tests\DbWebTest;
|
||||
use Override;
|
||||
|
||||
use function sprintf;
|
||||
|
||||
final class FoodVendorControllerTest extends DbWebTest
|
||||
{
|
||||
private string $path = '/food/vendor/';
|
||||
|
||||
public function testIndex(): void
|
||||
{
|
||||
$this->client->request('GET', $this->path);
|
||||
|
||||
self::assertResponseStatusCodeSame(200);
|
||||
self::assertPageTitleContains('FoodVendor index');
|
||||
}
|
||||
|
||||
public function testNew(): void
|
||||
{
|
||||
$this->client->request('GET', sprintf('%snew', $this->path));
|
||||
|
||||
self::assertResponseStatusCodeSame(200);
|
||||
|
||||
$this->client->submitForm('Save', [
|
||||
'food_vendor[name]' => 'Testing',
|
||||
]);
|
||||
|
||||
self::assertSame(1, $this->repository->count([]));
|
||||
}
|
||||
|
||||
public function testShow(): void
|
||||
{
|
||||
$fixture = new FoodVendor;
|
||||
$fixture->setName('My Title');
|
||||
|
||||
$this->manager->persist($fixture);
|
||||
$this->manager->flush();
|
||||
|
||||
$crawler = $this->client->request('GET', sprintf('%s%s', $this->path, $fixture->getId()));
|
||||
|
||||
$this->assertResponseIsSuccessful();
|
||||
$nameNode = $crawler->filter('td')
|
||||
->last();
|
||||
$this->assertSame('My Title', $nameNode->text());
|
||||
}
|
||||
|
||||
public function testEdit(): void
|
||||
{
|
||||
$fixture = new FoodVendor;
|
||||
$fixture->setName('Value');
|
||||
|
||||
$this->manager->persist($fixture);
|
||||
$this->manager->flush();
|
||||
|
||||
$this->client->request('GET', sprintf('%s%s/edit', $this->path, $fixture->getId()));
|
||||
|
||||
$this->client->submitForm('Update', [
|
||||
'food_vendor[name]' => 'Something New',
|
||||
]);
|
||||
|
||||
self::assertResponseRedirects('/food/vendor/');
|
||||
|
||||
$fixture = $this->repository->findAll();
|
||||
|
||||
self::assertSame('Something New', $fixture[0]->getName());
|
||||
}
|
||||
|
||||
#[Override]
|
||||
public function getEntityClass(): string
|
||||
{
|
||||
return FoodVendor::class;
|
||||
}
|
||||
}
|
134
tests/Controller/OrderItemControllerTest.php
Normal file
134
tests/Controller/OrderItemControllerTest.php
Normal file
|
@ -0,0 +1,134 @@
|
|||
<?php declare(strict_types=1);
|
||||
|
||||
namespace App\Tests\Controller;
|
||||
|
||||
use App\Entity\FoodOrder;
|
||||
use App\Entity\FoodVendor;
|
||||
use App\Entity\MenuItem;
|
||||
use App\Entity\OrderItem;
|
||||
use App\Repository\MenuItemRepository;
|
||||
use App\Tests\DbWebTest;
|
||||
use Override;
|
||||
|
||||
use function sprintf;
|
||||
|
||||
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');
|
||||
|
||||
$this->manager->persist($this->vendor);
|
||||
$this->order = new FoodOrder;
|
||||
$this->order->setFoodVendor($this->vendor);
|
||||
|
||||
$this->manager->persist($this->order);
|
||||
|
||||
$this->menuItem = new MenuItem;
|
||||
$this->menuItem->setName('Testing');
|
||||
$this->menuItem->setFoodVendor($this->vendor);
|
||||
|
||||
$this->manager->persist($this->menuItem);
|
||||
$this->manager->flush();
|
||||
|
||||
$this->menuItemRepository = static::getContainer()->get(MenuItemRepository::class);
|
||||
}
|
||||
|
||||
public function testNew(): void
|
||||
{
|
||||
$this->client->request(
|
||||
'GET',
|
||||
sprintf('%snew/%s', $this->path, $this->order->getId())
|
||||
);
|
||||
|
||||
self::assertResponseStatusCodeSame(200);
|
||||
|
||||
$this->client->submitForm('Save', [
|
||||
'order_item[name]' => 'Testing',
|
||||
'order_item[extras]' => 'Testing',
|
||||
]);
|
||||
|
||||
self::assertResponseRedirects(sprintf('/food/order/%s', $this->order->getId()));
|
||||
|
||||
self::assertSame(1, $this->repository->count([]));
|
||||
self::assertSame(1, $this->menuItemRepository->count([]));
|
||||
}
|
||||
|
||||
public function testNewCreateMenuItem(): void
|
||||
{
|
||||
$this->client->request(
|
||||
'GET',
|
||||
sprintf('%snew/%s', $this->path, $this->order->getId())
|
||||
);
|
||||
|
||||
self::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()));
|
||||
|
||||
self::assertSame(1, $this->repository->count([]));
|
||||
self::assertSame(2, $this->menuItemRepository->count([]));
|
||||
}
|
||||
|
||||
public function testRemove(): void
|
||||
{
|
||||
$fixture = new OrderItem;
|
||||
$fixture->setName('Testing');
|
||||
$fixture->setExtras('Value');
|
||||
$fixture->setMenuItem($this->menuItem);
|
||||
|
||||
$fixture->setFoodOrder($this->order);
|
||||
|
||||
$this->manager->persist($fixture);
|
||||
$this->manager->flush();
|
||||
|
||||
$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([]));
|
||||
}
|
||||
|
||||
public function testCopy(): void
|
||||
{
|
||||
$orderItem = new OrderItem;
|
||||
$orderItem->setName('My Title');
|
||||
$orderItem->setExtras('My Title');
|
||||
$orderItem->setFoodOrder($this->order);
|
||||
$orderItem->setMenuItem($this->menuItem);
|
||||
|
||||
$this->manager->persist($orderItem);
|
||||
$this->manager->flush();
|
||||
|
||||
$this->client->request('GET', sprintf('%s%s/copy', $this->path, $orderItem->getId()));
|
||||
self::assertResponseRedirects(sprintf('/food/order/%s', $this->order->getId()));
|
||||
|
||||
$result = $this->repository->findBy([
|
||||
'foodOrder' => $this->order->getId(),
|
||||
]);
|
||||
$this->assertCount(2, $result);
|
||||
foreach ($result as $item) {
|
||||
$this->assertSame($orderItem->getName(), $item->getName());
|
||||
$this->assertSame($orderItem->getExtras(), $item->getExtras());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#[Override]
|
||||
public function getEntityClass(): string
|
||||
{
|
||||
return OrderItem::class;
|
||||
}
|
||||
}
|
|
@ -1,26 +0,0 @@
|
|||
<?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]);
|
||||
}
|
||||
}
|
|
@ -2,26 +2,20 @@
|
|||
|
||||
namespace App\Tests;
|
||||
|
||||
use DateInterval;
|
||||
use DateTimeImmutable;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Doctrine\ORM\EntityRepository;
|
||||
use Doctrine\ORM\Tools\SchemaTool;
|
||||
use Override;
|
||||
use Symfony\Bundle\FrameworkBundle\KernelBrowser;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||
use Symfony\Component\DomCrawler\Crawler;
|
||||
use Symfony\Component\Uid\Ulid;
|
||||
|
||||
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,34 +27,7 @@ abstract class DbWebTest extends WebTestCase
|
|||
->getAllMetadata();
|
||||
$schemaTool->dropDatabase();
|
||||
$schemaTool->updateSchema($metadata);
|
||||
}
|
||||
|
||||
protected function generateOldUlid(int $daysToSubtract = 10): Ulid
|
||||
{
|
||||
$date = (new DateTimeImmutable)->sub(new DateInterval('P' . $daysToSubtract . 'D'));
|
||||
$ulidString = Ulid::generate($date);
|
||||
return Ulid::fromString($ulidString);
|
||||
}
|
||||
|
||||
protected function assertElementContainsCount(Crawler $crawler, string $element, int $count, string $text): void
|
||||
{
|
||||
$this->assertCount(
|
||||
$count,
|
||||
$crawler->filter($element)
|
||||
->reduce(
|
||||
static fn(Crawler $node, $i): bool => str_contains($node->text(), $text),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
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;
|
||||
$this->repository = $this->manager->getRepository($this->getEntityClass());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,15 +0,0 @@
|
|||
<?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,244 +0,0 @@
|
|||
<?php declare(strict_types=1);
|
||||
|
||||
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\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;
|
||||
|
||||
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();
|
||||
});
|
||||
|
||||
describe(FoodOrderController::class, function (): void {
|
||||
test('index', function (): void {
|
||||
$order = new FoodOrder;
|
||||
$order->setFoodVendor($this->vendor);
|
||||
|
||||
$this->manager->persist($order);
|
||||
$this->manager->persist($this->vendor);
|
||||
$this->manager->flush();
|
||||
|
||||
$crawler = $this->client->request('GET', "{$this->path}list");
|
||||
$this->assertResponseStatusCodeSame(200);
|
||||
$this->assertPageTitleContains('FoodOrder index');
|
||||
$this->assertCount(
|
||||
1,
|
||||
$crawler->filter('td')
|
||||
->reduce(fn(Crawler $node, $i): bool => $node->text() === $this->vendor->getName()),
|
||||
);
|
||||
});
|
||||
|
||||
test('orderedItems', function (): void {
|
||||
$order = new FoodOrder;
|
||||
$order->setFoodVendor($this->vendor);
|
||||
|
||||
$this->manager->persist($order);
|
||||
$this->manager->persist($this->vendor);
|
||||
|
||||
$menuItemA = new MenuItem;
|
||||
$menuItemA->setName('A');
|
||||
$menuItemA->setFoodVendor($this->vendor);
|
||||
|
||||
$this->manager->persist($menuItemA);
|
||||
$itemA = new OrderItem;
|
||||
$itemA->setMenuItem($menuItemA);
|
||||
$itemA->setName($menuItemA->getName());
|
||||
|
||||
$order->addOrderItem($itemA);
|
||||
$this->manager->persist($itemA);
|
||||
|
||||
$menuItemC = new MenuItem;
|
||||
$menuItemC->setName('C');
|
||||
$menuItemC->setFoodVendor($this->vendor);
|
||||
|
||||
$this->manager->persist($menuItemC);
|
||||
$itemC = new OrderItem;
|
||||
$itemC->setMenuItem($menuItemC);
|
||||
$itemC->setName($menuItemC->getName());
|
||||
|
||||
$order->addOrderItem($itemC);
|
||||
$this->manager->persist($itemC);
|
||||
|
||||
$menuItemB = new MenuItem;
|
||||
$menuItemB->setName('B');
|
||||
$menuItemB->setFoodVendor($this->vendor);
|
||||
|
||||
$this->manager->persist($menuItemB);
|
||||
$itemB = new OrderItem;
|
||||
$itemB->setMenuItem($menuItemB);
|
||||
$itemB->setName($menuItemB->getName());
|
||||
|
||||
$order->addOrderItem($itemB);
|
||||
$this->manager->persist($itemB);
|
||||
|
||||
$this->manager->flush();
|
||||
|
||||
$crawler = $this->client->request('GET', "{$this->path}{$order->getId()}");
|
||||
$this->assertResponseIsSuccessful();
|
||||
$tdContent = $crawler->filter(
|
||||
'table.table:nth-child(6) > tbody:nth-child(2) > tr:nth-child(1) > td:nth-child(2)'
|
||||
)->text();
|
||||
$this->assertEquals('A', $tdContent);
|
||||
$tdContent = $crawler->filter(
|
||||
'table.table:nth-child(6) > tbody:nth-child(2) > tr:nth-child(2) > td:nth-child(2)'
|
||||
)->text();
|
||||
$this->assertEquals('B', $tdContent);
|
||||
$tdContent = $crawler->filter(
|
||||
'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();
|
||||
$crawler = $this->client->request('GET', "{$this->path}list");
|
||||
$this->assertResponseStatusCodeSame(200);
|
||||
$this->assertPageTitleContains('FoodOrder index');
|
||||
$this->assertElementContainsCount(
|
||||
$crawler,
|
||||
'td',
|
||||
1,
|
||||
'older orders'
|
||||
);
|
||||
$this->assertElementContainsCount(
|
||||
$crawler,
|
||||
'td',
|
||||
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();
|
||||
$crawler = $this->client->request('GET', "{$this->path}list/archive/{$page}");
|
||||
$this->assertResponseStatusCodeSame(200);
|
||||
$this->assertPageTitleContains('FoodOrder index');
|
||||
$this->assertElementContainsCount(
|
||||
$crawler,
|
||||
'td',
|
||||
$items,
|
||||
'nobody'
|
||||
);
|
||||
if ($prevPage > 0) {
|
||||
$prevPage = $prevPage === 1 ? '' : "/{$prevPage}";
|
||||
$node = $crawler->filter('a')
|
||||
->reduce(static fn(Crawler $node, $i): bool => $node->text() === 'previous page')
|
||||
->first();
|
||||
$target = $node->attr('href');
|
||||
$this->assertTrue(str_ends_with((string) $target, $prevPage));
|
||||
}
|
||||
if ($prevPage > 3) {
|
||||
$node = $crawler->filter('a')
|
||||
->reduce(static fn(Crawler $node, $i): bool => $node->text() === 'next page')
|
||||
->first();
|
||||
$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 {
|
||||
$this->client->getCookieJar()
|
||||
->set(new Cookie('username', 'Testing-1'));
|
||||
$this->client->request('GET', sprintf('%snew', $this->path));
|
||||
|
||||
$this->assertResponseStatusCodeSame(200);
|
||||
|
||||
$this->client->submitForm('Save', [
|
||||
'food_order[foodVendor]' => $this->vendor->getId(),
|
||||
]);
|
||||
|
||||
$this->assertResponseRedirects("{$this->path}list");
|
||||
$this->assertSame(1, $this->repository->count([]));
|
||||
$order = $this->repository->findOneBy([
|
||||
'createdBy' => 'Testing-1',
|
||||
]);
|
||||
assert($order instanceof FoodOrder);
|
||||
});
|
||||
|
||||
test('open', function (): void {
|
||||
$order = new FoodOrder;
|
||||
$order->setFoodVendor($this->vendor);
|
||||
$order->close();
|
||||
|
||||
$this->assertTrue($order->isClosed());
|
||||
$this->manager->persist($order);
|
||||
$this->manager->flush();
|
||||
|
||||
$this->client->request('GET', sprintf('%s%s/open', $this->path, $order->getId()));
|
||||
$this->assertResponseRedirects("{$this->path}{$order->getId()}");
|
||||
$openOrder = $this->repository->find($order->getId());
|
||||
$this->assertFalse($openOrder->isClosed());
|
||||
});
|
||||
|
||||
test('close', function (): void {
|
||||
$order = new FoodOrder;
|
||||
$order->setClosedAt();
|
||||
$order->setFoodVendor($this->vendor);
|
||||
|
||||
$this->assertFalse($order->isClosed());
|
||||
$this->manager->persist($order);
|
||||
$this->manager->flush();
|
||||
|
||||
$this->client->request('GET', sprintf('%s%s/close', $this->path, $order->getId()));
|
||||
$this->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
|
||||
);
|
|
@ -1,184 +0,0 @@
|
|||
<?php declare(strict_types=1);
|
||||
|
||||
namespace App\Tests\Feature\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 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);
|
||||
});
|
||||
|
||||
describe(FoodVendorController::class, function (): void {
|
||||
test('index', function (): void {
|
||||
$this->client->request('GET', $this->path);
|
||||
|
||||
$this->assertResponseStatusCodeSame(200);
|
||||
$this->assertPageTitleContains('FoodVendor index');
|
||||
});
|
||||
|
||||
test('new', function (): void {
|
||||
$this->assertSame(0, $this->repository->count([]));
|
||||
$this->client->request('GET', sprintf('%snew', $this->path));
|
||||
|
||||
$this->assertResponseStatusCodeSame(200);
|
||||
|
||||
$this->client->submitForm('Save', [
|
||||
'food_vendor[name]' => 'TestingNew',
|
||||
]);
|
||||
|
||||
$newVendor = $this->repository->findOneBy([
|
||||
'name' => 'TestingNew',
|
||||
]);
|
||||
$this->assertInstanceof(FoodVendor::class, $newVendor);
|
||||
$this->assertSame(1, $this->repository->count([]));
|
||||
|
||||
});
|
||||
|
||||
test('show', function (): void {
|
||||
$fixture = new FoodVendor;
|
||||
$fixture->setName('My Title');
|
||||
$fixture->setMenuLink('https://example.com/');
|
||||
|
||||
$this->manager->persist($fixture);
|
||||
$this->manager->flush();
|
||||
|
||||
$crawler = $this->client->request('GET', sprintf('%s%s', $this->path, $fixture->getId()));
|
||||
|
||||
$this->assertResponseIsSuccessful();
|
||||
|
||||
$nameNode = $crawler->filter('td')
|
||||
->last();
|
||||
$nameNode = $crawler->filter(
|
||||
'.table > tbody:nth-child(1) > tr:nth-child(1) > td:nth-child(2)'
|
||||
)->text();
|
||||
$menuLinkNode = $crawler->filter(
|
||||
'.table > tbody:nth-child(1) > tr:nth-child(2) > td:nth-child(2) > a:nth-child(1)'
|
||||
)->text();
|
||||
$this->assertSame('My Title', $nameNode);
|
||||
$this->assertSame('https://example.com/', $menuLinkNode);
|
||||
});
|
||||
|
||||
test('show with menu items', function (): void {
|
||||
$fixture = new FoodVendor;
|
||||
$fixture->setName('My Title');
|
||||
|
||||
$this->manager->persist($fixture);
|
||||
|
||||
$this->manager->flush();
|
||||
|
||||
$itemOne = new MenuItem;
|
||||
$itemOne->setName('Item One');
|
||||
|
||||
$fixture->addMenuItem($itemOne);
|
||||
$this->manager->persist($itemOne);
|
||||
|
||||
$itemTwo = new MenuItem;
|
||||
$itemTwo->setName('Item Two');
|
||||
$itemTwo->setFoodVendor($fixture);
|
||||
|
||||
$fixture->addMenuItem($itemTwo);
|
||||
$this->manager->persist($itemTwo);
|
||||
|
||||
$itemThree = new MenuItem;
|
||||
$itemThree->setName('Item Three');
|
||||
$itemThree->setFoodVendor($fixture);
|
||||
|
||||
$fixture->addMenuItem($itemThree);
|
||||
$this->manager->persist($itemThree);
|
||||
|
||||
$itemFour = new MenuItem;
|
||||
$itemFour->setName('Item Four');
|
||||
$itemFour->setFoodVendor($fixture);
|
||||
|
||||
$fixture->addMenuItem($itemFour);
|
||||
$this->manager->persist($itemFour);
|
||||
|
||||
$this->manager->flush();
|
||||
|
||||
$crawler = $this->client->request('GET', sprintf('%s%s', $this->path, $fixture->getId()));
|
||||
|
||||
$this->assertResponseIsSuccessful();
|
||||
$nameNode = $crawler->filter(
|
||||
'.table > tbody:nth-child(1) > tr:nth-child(1) > td:nth-child(2)'
|
||||
)->text();
|
||||
$this->assertSame('My Title', $nameNode);
|
||||
|
||||
$itemNodes = $crawler->filter('li');
|
||||
|
||||
$this->assertCount(4, $itemNodes);
|
||||
});
|
||||
|
||||
test('edit', function (): void {
|
||||
$fixture = new FoodVendor;
|
||||
$fixture->setName('Value');
|
||||
$fixture->setMenuLink('Value');
|
||||
$fixture->setPhone('Value');
|
||||
|
||||
$this->manager->persist($fixture);
|
||||
$this->manager->flush();
|
||||
|
||||
$crawler = $this->client->request('GET', sprintf('%s%s/edit', $this->path, $fixture->getId()));
|
||||
$this->assertSame(
|
||||
$crawler->filter('#food_vendor_name')
|
||||
->last()
|
||||
->attr('value', ''),
|
||||
'Value'
|
||||
);
|
||||
$this->assertSame(
|
||||
$crawler->filter('#food_vendor_menuLink')
|
||||
->last()
|
||||
->attr('value', ''),
|
||||
'Value'
|
||||
);
|
||||
$this->assertSame(
|
||||
$crawler->filter('#food_vendor_phone')
|
||||
->last()
|
||||
->attr('value', ''),
|
||||
'Value'
|
||||
);
|
||||
|
||||
$this->client->submitForm('Update', [
|
||||
'food_vendor[name]' => 'Something New',
|
||||
'food_vendor[menuLink]' => 'https://example.com/',
|
||||
'food_vendor[phone]' => '1234567890',
|
||||
]);
|
||||
|
||||
$this->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());
|
||||
});
|
||||
|
||||
})
|
||||
->covers(
|
||||
FoodOrder::class,
|
||||
FoodVendor::class,
|
||||
FoodOrderRepository::class,
|
||||
MenuItem::class,
|
||||
OrderItem::class,
|
||||
FoodOrderType::class,
|
||||
FoodVendorRepository::class,
|
||||
FoodVendorController::class,
|
||||
FoodVendorType::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,159 +0,0 @@
|
|||
<?php declare(strict_types=1);
|
||||
|
||||
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\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;
|
||||
|
||||
pest()
|
||||
->beforeEach(function (): void {
|
||||
$this->setEntityClass(MenuItem::class);
|
||||
$this->setPath('/menu/item/');
|
||||
|
||||
$this->repository = $this->manager->getRepository($this->entityClass);
|
||||
|
||||
$this->vendor = new FoodVendor;
|
||||
$this->vendor->setName('Food Vendor');
|
||||
|
||||
$this->manager->persist($this->vendor);
|
||||
$this->menuItem = new MenuItem;
|
||||
$this->menuItem->setName('Testing 1 2');
|
||||
|
||||
$this->vendor->addMenuItem($this->menuItem);
|
||||
$this->manager->persist($this->vendor);
|
||||
$this->manager->persist($this->menuItem);
|
||||
|
||||
$this->aliasOne = new MenuItem;
|
||||
$this->aliasOne->setName('AliasOne');
|
||||
$this->aliasOne->setFoodVendor($this->vendor);
|
||||
|
||||
$this->menuItem->addAlias($this->aliasOne);
|
||||
|
||||
$this->aliasTwo = new MenuItem;
|
||||
$this->aliasTwo->setName('AliasTwo');
|
||||
$this->aliasTwo->setFoodVendor($this->vendor);
|
||||
$this->aliasTwo->setAliasOf($this->menuItem);
|
||||
|
||||
$this->menuItem->addAlias($this->aliasTwo);
|
||||
|
||||
$this->manager->persist($this->aliasOne);
|
||||
$this->manager->persist($this->aliasTwo);
|
||||
$this->manager->persist($this->menuItem);
|
||||
$this->manager->flush();
|
||||
|
||||
});
|
||||
|
||||
describe(MenuItemController::class, function (): void {
|
||||
test('show', function (): void {
|
||||
|
||||
$crawler = $this->client->request('GET', "{$this->path}{$this->menuItem->getId()}");
|
||||
$idValue = $crawler->filter(
|
||||
'.table > tbody:nth-child(1) > tr:nth-child(1) > td:nth-child(2)'
|
||||
)->text();
|
||||
$nameValue = $crawler->filter(
|
||||
'.table > tbody:nth-child(1) > tr:nth-child(2) > td:nth-child(2)'
|
||||
)->text();
|
||||
|
||||
$aliasTwoNameValue = $crawler->filter(
|
||||
'.table > tbody:nth-child(1) > tr:nth-child(3) > td:nth-child(2) > ul:nth-child(1) > li:nth-child(1)'
|
||||
)->text();
|
||||
$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);
|
||||
$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 {
|
||||
$crawler = $this->client->request('GET', sprintf('%s%s/edit', $this->path, $this->menuItem->getId()));
|
||||
$nameElem = $crawler->filter('#menu_item_name');
|
||||
$this->assertEquals(
|
||||
'Testing 1 2',
|
||||
$nameElem->attr('value')
|
||||
);
|
||||
|
||||
$form = $crawler->selectButton('Update')
|
||||
->form();
|
||||
$form['menu_item[name]'] = 'Testing-1';
|
||||
$form['menu_item[aliases]'][0]->untick();
|
||||
|
||||
$this->client->submit($form);
|
||||
|
||||
$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());
|
||||
});
|
||||
|
||||
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(
|
||||
'Testing 1 2',
|
||||
$nameElem->attr('value')
|
||||
);
|
||||
|
||||
$form = $crawler->selectButton('Update')
|
||||
->form();
|
||||
$form['menu_item[name]'] = 'a';
|
||||
|
||||
$this->client->submit($form);
|
||||
|
||||
$this->assertResponseStatusCodeSame(422);
|
||||
});
|
||||
|
||||
test('delete', function (): void {
|
||||
$order = new FoodOrder;
|
||||
$order->setFoodVendor($this->vendor);
|
||||
|
||||
$this->manager->persist($order);
|
||||
$this->manager->flush();
|
||||
$this->assertFalse($this->menuItem->isDeleted());
|
||||
|
||||
$this->client->request('GET', "{$this->path}{$this->menuItem->getId()}");
|
||||
$this->client->submitForm('Delete', []);
|
||||
|
||||
$menuItem = $this->repository->find($this->menuItem->getId());
|
||||
|
||||
$this->assertTrue($menuItem->isDeleted());
|
||||
|
||||
$crawler = $this->client->request('GET', '/order/item/new/' . $order->getId());
|
||||
$count = $crawler->filter('body > main:nth-child(2) > div:nth-child(5)')
|
||||
->children()
|
||||
->count();
|
||||
$this->assertSame(2, $count);
|
||||
|
||||
$this->assertResponseIsSuccessful();
|
||||
|
||||
});
|
||||
})
|
||||
->covers(
|
||||
MenuItemController::class,
|
||||
OrderItemController::class,
|
||||
OrderItemType::class,
|
||||
MenuItemRepository::class,
|
||||
FoodOrder::class,
|
||||
FoodVendor::class,
|
||||
MenuItem::class,
|
||||
OrderItem::class,
|
||||
FoodOrderRepository::class,
|
||||
MenuItemType::class,
|
||||
);
|
|
@ -1,261 +0,0 @@
|
|||
<?php declare(strict_types=1);
|
||||
|
||||
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\Repository\OrderItemRepository;
|
||||
use DateTimeImmutable;
|
||||
|
||||
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);
|
||||
|
||||
$this->vendor = new FoodVendor;
|
||||
$this->vendor->setName('Food Vendor');
|
||||
|
||||
$this->manager->persist($this->vendor);
|
||||
$this->order = new FoodOrder;
|
||||
$this->order->setFoodVendor($this->vendor);
|
||||
|
||||
$this->manager->persist($this->order);
|
||||
|
||||
$this->menuItem = new MenuItem;
|
||||
$this->menuItem->setName('Testing');
|
||||
$this->menuItem->setFoodVendor($this->vendor);
|
||||
|
||||
$vendor2 = new FoodVendor;
|
||||
$vendor2->setName('Vendor 2');
|
||||
|
||||
$menuItem2 = new MenuItem;
|
||||
$menuItem2->setName('Testing2');
|
||||
$menuItem2->setFoodVendor($vendor2);
|
||||
|
||||
$this->manager->persist($vendor2);
|
||||
$this->manager->persist($menuItem2);
|
||||
|
||||
$this->manager->persist($this->menuItem);
|
||||
$this->manager->flush();
|
||||
|
||||
$this->menuItemRepository = $this::getContainer()->get(MenuItemRepository::class);
|
||||
});
|
||||
|
||||
describe(OrderItemController::class, function (): void {
|
||||
test('new', function (): void {
|
||||
$crawler = $this->client->request(
|
||||
'GET',
|
||||
sprintf('%snew/%s', $this->path, $this->order->getId())
|
||||
);
|
||||
|
||||
$children = $crawler->filter('body > main:nth-child(2) > div:nth-child(5)')
|
||||
->children();
|
||||
|
||||
$this->assertCount(1, $children);
|
||||
|
||||
$this->assertResponseStatusCodeSame(200);
|
||||
|
||||
$this->client->submitForm('Save', [
|
||||
'order_item[name]' => 'Testing',
|
||||
'order_item[extras]' => 'Testing',
|
||||
]);
|
||||
|
||||
$this->assertResponseRedirects(sprintf('/food/order/%s', $this->order->getId()));
|
||||
|
||||
$this->assertSame(1, $this->repository->count([]));
|
||||
$this->assertSame(1, $this->menuItemRepository->count([
|
||||
'foodVendor' => $this->vendor->getId(),
|
||||
]));
|
||||
});
|
||||
|
||||
test('new order closed', function (): void {
|
||||
|
||||
$this->order->setClosedAt(new DateTimeImmutable('-1 Hour'));
|
||||
$this->manager->persist($this->order);
|
||||
$this->manager->flush();
|
||||
|
||||
$this->client->request(
|
||||
'GET',
|
||||
sprintf('%snew/%s', $this->path, $this->order->getId())
|
||||
);
|
||||
|
||||
$this->assertResponseRedirects(sprintf('/food/order/%s', $this->order->getId()));
|
||||
|
||||
$this->assertSame(0, $this->repository->count([]));
|
||||
});
|
||||
|
||||
test('new create menu item', function (): void {
|
||||
$this->client->request(
|
||||
'GET',
|
||||
sprintf('%snew/%s', $this->path, $this->order->getId())
|
||||
);
|
||||
|
||||
$this->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()));
|
||||
|
||||
$this->assertSame(1, $this->repository->count([]));
|
||||
$this->assertSame(3, $this->menuItemRepository->count([]));
|
||||
});
|
||||
|
||||
test('remove', function (): void {
|
||||
$fixture = new OrderItem;
|
||||
$fixture->setName('Testing');
|
||||
$fixture->setExtras('Value');
|
||||
$fixture->setMenuItem($this->menuItem);
|
||||
|
||||
$fixture->setFoodOrder($this->order);
|
||||
|
||||
$this->manager->persist($fixture);
|
||||
$this->manager->flush();
|
||||
|
||||
$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([]));
|
||||
});
|
||||
|
||||
test('order closed', function (): void {
|
||||
$fixture = new OrderItem;
|
||||
$fixture->setName('Testing');
|
||||
$fixture->setExtras('Value');
|
||||
$fixture->setMenuItem($this->menuItem);
|
||||
$fixture->setFoodOrder($this->order);
|
||||
|
||||
$this->order->close();
|
||||
|
||||
$this->manager->persist($this->order);
|
||||
$this->manager->persist($fixture);
|
||||
$this->manager->flush();
|
||||
|
||||
$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([]));
|
||||
});
|
||||
|
||||
test('edit', function (): void {
|
||||
$orderItem = new OrderItem;
|
||||
$orderItem->setName('Testing');
|
||||
$orderItem->setExtras('My Extra');
|
||||
$orderItem->setFoodOrder($this->order);
|
||||
$orderItem->setMenuItem($this->menuItem);
|
||||
|
||||
$this->manager->persist($orderItem);
|
||||
$this->manager->flush();
|
||||
|
||||
$crawler = $this->client->request('GET', sprintf('%s%s/edit', $this->path, $orderItem->getId()));
|
||||
$nameElem = $crawler->filter('#order_item_name');
|
||||
$extrasElem = $crawler->filter('#order_item_extras');
|
||||
$this->assertEquals(
|
||||
'Testing',
|
||||
$nameElem->attr('value')
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'My Extra',
|
||||
$extrasElem->attr('value')
|
||||
);
|
||||
|
||||
$this->client->submitForm('Update', [
|
||||
'order_item[name]' => 'Testing-1',
|
||||
'order_item[extras]' => 'Testing-1',
|
||||
]);
|
||||
|
||||
$this->assertResponseRedirects(sprintf('/food/order/%s', $this->order->getId()));
|
||||
|
||||
$this->assertSame(1, $this->repository->count([]));
|
||||
$this->assertSame(3, $this->menuItemRepository->count([]));
|
||||
|
||||
});
|
||||
|
||||
test('edit order closed', function (): void {
|
||||
$orderItem = new OrderItem;
|
||||
$orderItem->setName('Testing');
|
||||
$orderItem->setExtras('My Extra');
|
||||
$orderItem->setFoodOrder($this->order);
|
||||
$orderItem->setMenuItem($this->menuItem);
|
||||
|
||||
$this->order->close();
|
||||
|
||||
$this->manager->persist($orderItem);
|
||||
$this->manager->persist($this->order);
|
||||
$this->manager->flush();
|
||||
|
||||
$this->client->request('GET', sprintf('%s%s/edit', $this->path, $orderItem->getId()));
|
||||
$this->assertResponseRedirects(sprintf('/food/order/%s', $this->order->getId()));
|
||||
});
|
||||
|
||||
test('copy', function (): void {
|
||||
$orderItem = new OrderItem;
|
||||
$orderItem->setName('My Title');
|
||||
$orderItem->setExtras('My Title');
|
||||
$orderItem->setFoodOrder($this->order);
|
||||
$orderItem->setMenuItem($this->menuItem);
|
||||
|
||||
$this->manager->persist($orderItem);
|
||||
$this->manager->flush();
|
||||
|
||||
$this->client->request('GET', sprintf('%s%s/copy', $this->path, $orderItem->getId()));
|
||||
$this->assertResponseRedirects(sprintf('/food/order/%s', $this->order->getId()));
|
||||
|
||||
$result = $this->repository->findBy([
|
||||
'foodOrder' => $this->order->getId(),
|
||||
]);
|
||||
$this->assertCount(2, $result);
|
||||
foreach ($result as $item) {
|
||||
$this->assertSame($orderItem->getName(), $item->getName());
|
||||
$this->assertSame($orderItem->getExtras(), $item->getExtras());
|
||||
}
|
||||
});
|
||||
|
||||
test('copy order closed', function (): void {
|
||||
$orderItem = new OrderItem;
|
||||
$orderItem->setName('My Title');
|
||||
$orderItem->setExtras('My Title');
|
||||
$orderItem->setFoodOrder($this->order);
|
||||
$orderItem->setMenuItem($this->menuItem);
|
||||
|
||||
$this->order->close();
|
||||
$this->manager->persist($this->order);
|
||||
$this->manager->persist($orderItem);
|
||||
$this->manager->flush();
|
||||
|
||||
$this->client->request('GET', sprintf('%s%s/copy', $this->path, $orderItem->getId()));
|
||||
$this->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,
|
||||
);
|
|
@ -1,36 +0,0 @@
|
|||
<?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
|
||||
{
|
||||
// ..
|
||||
}
|
|
@ -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);
|
|
@ -1,64 +0,0 @@
|
|||
<?php declare(strict_types=1);
|
||||
|
||||
namespace App\Tests\Unit\Entity;
|
||||
|
||||
use App\Entity\FoodOrder;
|
||||
use App\Entity\FoodVendor;
|
||||
use App\Entity\MenuItem;
|
||||
use Symfony\Component\Uid\Ulid;
|
||||
|
||||
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());
|
||||
$this->assertInstanceOf(Ulid::class, $vendor->getId());
|
||||
$this->assertEmpty($vendor->getPhone());
|
||||
$vendor->setPhone('1234567890');
|
||||
$this->assertEquals('1234567890', $vendor->getPhone());
|
||||
|
||||
$this->assertCount(0, $vendor->getFoodOrders());
|
||||
$order1 = new FoodOrder;
|
||||
$vendor->addFoodOrder($order1);
|
||||
$vendor->addFoodOrder($order1);
|
||||
$this->assertCount(1, $vendor->getFoodOrders());
|
||||
$this->assertSame($vendor, $order1->getFoodVendor());
|
||||
$vendor->removeFoodOrder($order1);
|
||||
$this->assertCount(0, $vendor->getFoodOrders());
|
||||
$this->assertNull($order1->getFoodVendor());
|
||||
});
|
||||
|
||||
test('MenutItem entity', function (): void {
|
||||
$vendor = new FoodVendor;
|
||||
$menuItem1 = new MenuItem;
|
||||
$menuItem2 = new MenuItem;
|
||||
$this->assertCount(0, $vendor->getMenuItems());
|
||||
$vendor->addMenuItem($menuItem1);
|
||||
$vendor->addMenuItem($menuItem1);
|
||||
$this->assertCount(1, $vendor->getMenuItems());
|
||||
$vendor->removeMenuItem($menuItem1);
|
||||
$this->assertCount(0, $vendor->getMenuItems());
|
||||
$this->assertNull($menuItem1->getFoodVendor());
|
||||
$vendor->addMenuItem($menuItem1);
|
||||
$menuItem2->delete();
|
||||
$vendor->addMenuItem($menuItem2);
|
||||
$this->assertCount(1, $vendor->getMenuItems());
|
||||
$this->assertCount(2, $vendor->getMenuItems(true));
|
||||
});
|
||||
|
||||
test('remove foreign menu item', function (): void {
|
||||
$vendor1 = new FoodVendor;
|
||||
$vendor2 = new FoodVendor;
|
||||
$item1 = new MenuItem;
|
||||
|
||||
$vendor1->addMenuItem($item1);
|
||||
$this->assertCount(1, $vendor1->getMenuItems());
|
||||
$vendor2->removeMenuItem($item1);
|
||||
$this->assertCount(1, $vendor1->getMenuItems());
|
||||
$this->assertSame($vendor1, $item1->getFoodVendor());
|
||||
});
|
||||
|
||||
})->covers(FoodVendor::class, FoodOrder::class, MenuItem::class);
|
|
@ -1,53 +0,0 @@
|
|||
<?php declare(strict_types=1);
|
||||
|
||||
namespace App\Tests\Unit\Entity;
|
||||
|
||||
use App\Entity\FoodVendor;
|
||||
use App\Entity\MenuItem;
|
||||
use DateTimeImmutable;
|
||||
|
||||
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());
|
||||
|
||||
$vendor = new FoodVendor;
|
||||
$vendor->setName('Test');
|
||||
|
||||
$item->setFoodVendor($vendor);
|
||||
$this->assertEquals($vendor, $item->getFoodVendor());
|
||||
|
||||
$this->assertFalse($item->isDeleted());
|
||||
$this->assertNull($item->getDeletedAt());
|
||||
$item->delete();
|
||||
$this->assertTrue($item->isDeleted());
|
||||
$this->assertInstanceOf(DateTimeImmutable::class, $item->getDeletedAt());
|
||||
});
|
||||
test('MenuItem alias', function (): void {
|
||||
$item = new MenuItem;
|
||||
$item->setName('Test');
|
||||
$this->assertEquals('Test', $item->getName());
|
||||
|
||||
$vendor = new FoodVendor;
|
||||
$vendor->setName('Test');
|
||||
|
||||
$item->setFoodVendor($vendor);
|
||||
|
||||
$item2 = new MenuItem;
|
||||
$item2->setName('Test2');
|
||||
$item2->setFoodVendor($vendor);
|
||||
|
||||
$item->addAlias($item2);
|
||||
|
||||
$this->assertCount(1, $item->getAliases());
|
||||
$this->assertSame($item, $item2->getAliasOf());
|
||||
|
||||
$item->removeAlias($item2);
|
||||
$this->assertCount(0, $item->getAliases());
|
||||
$this->assertNull($item2->getAliasOf());
|
||||
});
|
||||
})->covers(MenuItem::class, FoodVendor::class);
|
|
@ -6,8 +6,6 @@ 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