Compare commits

..

30 commits
0.0.8 ... main

Author SHA1 Message Date
Continuous Integration
70b39515ec Continuous Integration Fixes
All checks were successful
/ ls (push) Successful in 2m16s
/ ls (release) Successful in 51s
2024-12-19 00:16:09 +00:00
86986310ad
add phone number to orderview
All checks were successful
/ ls (pull_request) Successful in 2m24s
2024-12-19 01:13:44 +01:00
b65a4814f4
#64: wip add phonenumberfield to foodvendor 2024-12-19 01:11:09 +01:00
Continuous Integration
2d3100b5c9 Continuous Integration Fixes
All checks were successful
/ ls (push) Successful in 2m20s
2024-12-18 23:38:27 +00:00
cb1ab0ed18
improve unit tests
All checks were successful
/ ls (pull_request) Successful in 2m32s
2024-12-19 00:35:23 +01:00
a974688872
update workflow image
All checks were successful
/ ls (pull_request) Successful in 2m21s
/ ls (push) Successful in 2m21s
2024-12-18 14:30:24 +01:00
8c783d780c
update dependencies
Some checks failed
/ ls (pull_request) Failing after 2m43s
2024-12-18 14:21:34 +01:00
Continuous Integration
ee5d515ac1 Continuous Integration Fixes
All checks were successful
/ ls (push) Successful in 2m17s
/ ls (release) Successful in 54s
2024-09-23 17:11:33 +00:00
80758abd60
fix ci
All checks were successful
/ ls (pull_request) Successful in 2m23s
2024-09-23 19:09:18 +02:00
9e35499269
do not show deleted menuitems
Some checks failed
/ ls (pull_request) Failing after 2m23s
2024-09-23 19:02:17 +02:00
441568bdb7
add pr feedback
All checks were successful
/ ls (pull_request) Successful in 2m18s
/ ls (push) Successful in 2m9s
2024-09-17 20:48:01 +02:00
7674b6a6bd
add mutation testing
All checks were successful
/ ls (pull_request) Successful in 2m13s
/ ls (push) Successful in 2m11s
2024-09-17 17:55:33 +02:00
12ff38ecd6
bump deps
All checks were successful
/ ls (pull_request) Successful in 57s
/ ls (push) Successful in 52s
/ ls (release) Successful in 37s
2024-08-31 21:40:05 +02:00
b1e82037c7
update dependencies
All checks were successful
/ ls (pull_request) Successful in 41s
/ ls (push) Successful in 38s
/ ls (release) Successful in 25s
2024-08-18 09:19:12 +02:00
3f3ede8548
fix issue link
All checks were successful
/ ls (pull_request) Successful in 37s
/ ls (push) Successful in 38s
/ ls (release) Successful in 25s
2024-08-16 21:57:49 +02:00
56206acd8a
#37 add external link to foodvendor
All checks were successful
/ ls (pull_request) Successful in 38s
/ ls (push) Successful in 37s
/ ls (release) Successful in 25s
2024-08-16 21:52:53 +02:00
34171d6c2b
100% test coverage
All checks were successful
/ ls (pull_request) Successful in 37s
/ ls (push) Successful in 37s
/ ls (release) Successful in 24s
2024-08-16 13:44:16 +02:00
2a28465626
lint
All checks were successful
/ ls (pull_request) Successful in 37s
/ ls (push) Successful in 35s
2024-08-16 11:15:23 +02:00
6f23c3c1b7
improve test coverage
All checks were successful
/ ls (pull_request) Successful in 39s
2024-08-16 11:14:41 +02:00
a4f62868fd
#42 linting
All checks were successful
/ ls (pull_request) Successful in 35s
/ ls (push) Successful in 34s
/ ls (release) Successful in 25s
2024-08-15 18:33:33 +02:00
311802be6b
#42: fix bug
Some checks failed
/ ls (pull_request) Successful in 39s
/ ls (push) Failing after 36s
2024-08-15 18:31:10 +02:00
674adcba60
#42: allow updates to menuitems
All checks were successful
/ ls (pull_request) Successful in 37s
/ ls (push) Successful in 39s
/ ls (release) Successful in 25s
2024-08-15 18:22:46 +02:00
0068654885
#49: change order item form labels
All checks were successful
/ ls (pull_request) Successful in 36s
/ ls (push) Successful in 36s
/ ls (release) Successful in 25s
2024-08-15 16:33:13 +02:00
c324973d28
#44: show item name on orderitem editform
All checks were successful
/ ls (pull_request) Successful in 35s
/ ls (push) Successful in 36s
/ ls (release) Successful in 28s
2024-08-14 20:39:14 +02:00
Continuous Integration
25b73e7da5 Continuous Integration Fixes
All checks were successful
/ ls (push) Successful in 34s
2024-08-14 17:41:59 +00:00
83989916a3
#45 sort orderitems aplhabetically in order view show
All checks were successful
/ ls (pull_request) Successful in 35s
2024-08-14 19:41:04 +02:00
add3631376
\#40 add list of menuitems in foodvendor show
All checks were successful
/ ls (pull_request) Successful in 33s
/ ls (push) Successful in 31s
/ ls (release) Successful in 34s
2024-07-17 21:19:01 +02:00
a0d277464d
#38: pidserspass
All checks were successful
/ ls (pull_request) Successful in 34s
/ ls (push) Successful in 33s
/ ls (release) Successful in 26s
2024-07-10 23:39:28 +02:00
9afa7fe431
#29: add more tests
All checks were successful
/ ls (pull_request) Successful in 37s
/ ls (push) Successful in 32s
2024-07-10 22:18:56 +02:00
c4cd275c83
#29: add test for homecontroller 2024-07-10 19:05:28 +02:00
49 changed files with 3006 additions and 802 deletions

View file

@ -3,13 +3,13 @@ jobs:
ls:
runs-on: docker
container:
image: git.php.fail/lubiana/container/php:ci
image: git.php.fail/lubiana/container/php:8.4.1-ci
steps:
- name: Manually checkout
env:
REPO: '${{ github.repository }}'
TOKEN: '${{ secrets.GITHUB_TOKEN }}'
GIT_SERVER: 'hannover.ccc.de/gitlab'
GIT_SERVER: 'git.hannover.ccc.de'
run: |
git clone --branch $GITHUB_HEAD_REF https://${TOKEN}@${GIT_SERVER}/${REPO}.git .
git fetch
@ -23,7 +23,19 @@ jobs:
- name: lint
run: composer lint
- name: test
run: composer test
run: composer mutation
- name: Add comment to pull request
run: |
echo '```' >> /tmp/pull-request-comment
cat var/log/infection.txt >> /tmp/pull-request-comment
cat var/log/summary.log >> /tmp/pull-request-comment
echo '```' >> /tmp/pull-request-comment
jq -n --arg msg "$(cat /tmp/pull-request-comment)" '{"body": $msg}' > /tmp/git-msg
curl -X POST \
-H "Authorization: token ${GITHUB_TOKEN}" \
-H "Content-Type: application/json" \
-d @/tmp/git-msg \
"${{ env.GITHUB_SERVER_URL }}/api/v1/repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/comments"
- name: GIT commit and push all changed files
env:
CI_COMMIT_MESSAGE: Continuous Integration Fixes

View file

@ -6,14 +6,14 @@ jobs:
ls:
runs-on: docker
container:
image: git.php.fail/lubiana/container/php:ci
image: git.php.fail/lubiana/container/php:8.4.1-ci
steps:
- name: Manually checkout
env:
REPO: '${{ github.repository }}'
TOKEN: '${{ secrets.GITHUB_TOKEN }}'
BRANCH: '${{ env.GITHUB_REF_NAME }}'
GIT_SERVER: 'hannover.ccc.de/gitlab'
GIT_SERVER: 'git.hannover.ccc.de'
run: |
git clone --branch $GITHUB_REF_NAME https://${TOKEN}@${GIT_SERVER}/${REPO}.git .
git fetch
@ -27,7 +27,7 @@ jobs:
- name: lint
run: composer lint
- name: test
run: composer test
run: composer mutation
- name: GIT commit and push all changed files
env:
CI_COMMIT_MESSAGE: Continuous Integration Fixes

View file

@ -4,7 +4,7 @@ jobs:
ls:
runs-on: docker
container:
image: git.php.fail/lubiana/container/php:ci
image: git.php.fail/lubiana/container/php:8.4.1-ci
steps:
- name: Manually checkout
env:

View file

@ -7,13 +7,14 @@
"php": ">=8.3",
"ext-ctype": "*",
"ext-iconv": "*",
"doctrine/dbal": "^4",
"doctrine/dbal": "^4.1",
"doctrine/doctrine-bundle": "^2.12",
"doctrine/doctrine-migrations-bundle": "^3.3",
"doctrine/orm": "^3.2",
"doctrine/doctrine-migrations-bundle": "^3.3.1",
"doctrine/orm": "^3.2.1",
"psr/clock": "^1.0",
"symfony/console": "7.1.*",
"symfony/dotenv": "7.1.*",
"symfony/flex": "^2",
"symfony/flex": "^2.4.6",
"symfony/form": "7.1.*",
"symfony/framework-bundle": "7.1.*",
"symfony/runtime": "7.1.*",
@ -24,20 +25,22 @@
"symfony/yaml": "7.1.*"
},
"require-dev": {
"lubiana/code-quality": "^1.7",
"phpunit/phpunit": "^9.5",
"infection/infection": "^0.29.6",
"lubiana/code-quality": "^1.7.2",
"phpunit/phpunit": "^9.6.20",
"symfony/browser-kit": "7.1.*",
"symfony/css-selector": "7.1.*",
"symfony/maker-bundle": "^1.60",
"symfony/phpunit-bridge": "^7.1",
"symplify/config-transformer": "^12.3"
"symfony/phpunit-bridge": "^7.1.3",
"symplify/config-transformer": "^12.3.4"
},
"config": {
"allow-plugins": {
"php-http/discovery": true,
"symfony/flex": true,
"symfony/runtime": true,
"dealerdirect/phpcodesniffer-composer-installer": true
"dealerdirect/phpcodesniffer-composer-installer": true,
"infection/extension-installer": true
},
"sort-packages": true,
"platform": {
@ -80,7 +83,8 @@
"rector",
"ecs --fix || ecs --fix"
],
"test": "bin/phpunit"
"test": "bin/phpunit",
"mutation": "infection --threads=8 --show-mutations"
},
"conflict": {
"symfony/symfony": "*"

2170
composer.lock generated

File diff suppressed because it is too large Load diff

View file

@ -5,6 +5,9 @@ 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', [

20
infection.json5 Normal file
View file

@ -0,0 +1,20 @@
{
"$schema": "vendor/infection/infection/resources/schema.json",
"source": {
"directories": [
"src"
]
},
"timeout": 30,
"logs": {
"text": "var/log/infection.txt",
"summary": "var/log/summary.log",
},
"mutators": {
"@default": true,
"global-ignore": [
"App\\Service\\Favicon::__toString",
"ORM\\Column.*"
]
}
}

View file

@ -0,0 +1,36 @@
<?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)');
}
}

View file

@ -0,0 +1,35 @@
<?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');
}
}

View file

@ -0,0 +1,35 @@
<?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');
}
}

View file

@ -6,7 +6,9 @@
backupGlobals="false"
colors="true"
bootstrap="tests/bootstrap.php"
convertDeprecationsToExceptions="false"
convertDeprecationsToExceptions="true"
executionOrder="random"
resolveDependencies="true"
>
<php>
<ini name="display_errors" value="1" />

View file

@ -0,0 +1,13 @@
<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>

After

Width:  |  Height:  |  Size: 1.5 KiB

View file

@ -1,35 +0,0 @@
<?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;
}
}

View file

@ -1,66 +0,0 @@
<?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;
}
}

View file

@ -15,28 +15,45 @@ use Symfony\Component\Routing\Attribute\Route;
final class FoodOrderController extends AbstractController
{
#[Route(
path: '/list/{page}',
path: '/list',
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 index(FoodOrderRepository $foodOrderRepository, int $page = 1): Response
public function archive(FoodOrderRepository $foodOrderRepository, int $page = 1): Response
{
$days = 4;
if ($page > 1) {
$days = 0;
}
$nextPage = $page + 1;
$prevPage = $page - 1;
$itemsPerPage = 10;
if($foodOrderRepository->count() < $page * $itemsPerPage) {
$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: $days),
'food_orders' => $foodOrderRepository->findLatestEntries(
page: $page,
pagesize: $itemsPerPage,
days: 0
),
'current_page' => $page,
'next_page' => $nextPage,
'prev_page' => $prevPage,
@ -78,7 +95,8 @@ final class FoodOrderController extends AbstractController
#[Route('/{id}/close', name: 'app_food_order_close', methods: ['GET'])]
public function close(FoodOrder $foodOrder, FoodOrderRepository $repository): Response
{
$repository->save($foodOrder->close());
$foodOrder->close();
$repository->save();
return $this->redirectToRoute('app_food_order_show', [
'id' => $foodOrder->getId(),
], Response::HTTP_SEE_OTHER);
@ -87,7 +105,8 @@ final class FoodOrderController extends AbstractController
#[Route('/{id}/open', name: 'app_food_order_open', methods: ['GET'])]
public function open(FoodOrder $foodOrder, FoodOrderRepository $repository): Response
{
$repository->save($foodOrder->open());
$foodOrder->open();
$repository->save();
return $this->redirectToRoute('app_food_order_show', [
'id' => $foodOrder->getId(),
], Response::HTTP_SEE_OTHER);

View file

@ -23,8 +23,10 @@ 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);
@ -63,7 +65,6 @@ final class FoodVendorController extends AbstractController
}
return $this->render('food_vendor/edit.html.twig', [
'food_vendor' => $foodVendor,
'form' => $form,
]);
}

View file

@ -0,0 +1,57 @@
<?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()) {
$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);
}
}

View file

@ -56,6 +56,7 @@ final class OrderItemController extends AbstractController
}
$menuItems = $menuItemRepository->findBy([
'foodVendor' => $foodOrder->getFoodVendor(),
'deletedAt' => null,
]);
return $this->render('order_item/new.html.twig', [
@ -90,18 +91,39 @@ 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): Response
{
public function edit(
Request $request,
OrderItem $orderItem,
EntityManagerInterface $entityManager,
MenuItemRepository $menuItemRepository,
): 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', [

View file

@ -8,19 +8,14 @@ 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)]
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;
@ -39,8 +34,11 @@ class FoodOrder
])]
private string|null $createdBy = 'nobody';
public function __construct()
{
public function __construct(
#[ORM\Id]
#[ORM\Column(type: UlidType::NAME, unique: true)]
private Ulid|null $id = new Ulid
) {
$this->orderItems = new ArrayCollection;
$this->open();
}
@ -60,7 +58,7 @@ class FoodOrder
return $this->closedAt;
}
public function setClosedAt(DateTimeImmutable|null $closedAt): static
public function setClosedAt(DateTimeImmutable|null $closedAt = null): static
{
$this->closedAt = $closedAt;
@ -69,7 +67,10 @@ class FoodOrder
public function isClosed(): bool
{
return $this->closedAt instanceof DateTimeImmutable && $this->closedAt->getTimestamp() <= (new DateTimeImmutable)->getTimestamp();
if (! $this->closedAt instanceof DateTimeImmutable) {
return false;
}
return $this->closedAt < new DateTimeImmutable;
}
public function close(): static
@ -103,6 +104,23 @@ 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)) {
@ -116,7 +134,7 @@ class FoodOrder
public function removeOrderItem(OrderItem $orderItem): static
{
// set the owning side to null (unless already changed)
if ($this->orderItems->removeElement($orderItem) && $orderItem->getFoodOrder() === $this) {
if ($this->orderItems->removeElement($orderItem)) {
$orderItem->setFoodOrder(null);
}

View file

@ -13,15 +13,14 @@ use Symfony\Component\Uid\Ulid;
#[ORM\Entity(repositoryClass: FoodVendorRepository::class)]
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>
*/
@ -34,8 +33,16 @@ class FoodVendor
#[ORM\OneToMany(targetEntity: MenuItem::class, mappedBy: 'foodVendor', orphanRemoval: true)]
private Collection $menuItems;
public function __construct()
{
#[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->foodOrders = new ArrayCollection;
$this->menuItems = new ArrayCollection;
}
@ -78,7 +85,7 @@ class FoodVendor
public function removeFoodOrder(FoodOrder $foodOrder): static
{
// set the owning side to null (unless already changed)
if ($this->foodOrders->removeElement($foodOrder) && $foodOrder->getFoodVendor() === $this) {
if ($this->foodOrders->removeElement($foodOrder)) {
$foodOrder->setFoodVendor(null);
}
@ -88,9 +95,14 @@ class FoodVendor
/**
* @return Collection<int, MenuItem>
*/
public function getMenuItems(): Collection
public function getMenuItems(bool $withDeleted = false): Collection
{
return $this->menuItems;
if ($withDeleted) {
return $this->menuItems;
}
return $this->menuItems->filter(
static fn(MenuItem $item): bool => $item->isDeleted() === false
);
}
public function addMenuItem(MenuItem $menuItem): static
@ -106,10 +118,33 @@ class FoodVendor
public function removeMenuItem(MenuItem $menuItem): static
{
// set the owning side to null (unless already changed)
if ($this->menuItems->removeElement($menuItem) && $menuItem->getFoodVendor() === $this) {
if ($this->menuItems->removeElement($menuItem)) {
$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;
}
}

View file

@ -3,6 +3,7 @@
namespace App\Entity;
use App\Repository\MenuItemRepository;
use DateTimeImmutable;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\IdGenerator\UlidGenerator;
use Symfony\Bridge\Doctrine\Types\UlidType;
@ -11,12 +12,6 @@ use Symfony\Component\Uid\Ulid;
#[ORM\Entity(repositoryClass: MenuItemRepository::class)]
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;
@ -24,6 +19,17 @@ class MenuItem
#[ORM\JoinColumn(nullable: false)]
private FoodVendor|null $foodVendor = null;
#[ORM\Column(nullable: true)]
private DateTimeImmutable|null $deletedAt = 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
) {}
public function getId(): Ulid|null
{
return $this->id;
@ -52,4 +58,27 @@ 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;
}
}

View file

@ -2,13 +2,11 @@
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
{
@ -31,12 +29,4 @@ final class FoodOrderType extends AbstractType
$builder->setAction($action);
}
}
#[Override]
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'data_class' => FoodOrder::class,
]);
}
}

View file

@ -15,6 +15,8 @@ final class FoodVendorType extends AbstractType
{
$builder
->add('name')
->add('menuLink')
->add('phone')
;
}

28
src/Form/MenuItemType.php Normal file
View file

@ -0,0 +1,28 @@
<?php declare(strict_types=1);
namespace App\Form;
use App\Entity\MenuItem;
use Override;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
final class MenuItemType extends AbstractType
{
#[Override]
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('name')
;
}
#[Override]
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'data_class' => MenuItem::class,
]);
}
}

View file

@ -15,10 +15,12 @@ final class OrderItemType extends AbstractType
{
$builder
->add(child: 'name', options: [
'data' => $options['name'] ?? '',
'label' => 'order item',
])
->add(child: 'extras')
->add(child: 'createdBy', options: [
'label' => 'your name',
])
->add('extras')
->add('createdBy')
;
}

View file

@ -5,7 +5,6 @@ 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
{
@ -13,17 +12,7 @@ final class UserNameFormType extends AbstractType
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add(child: 'username', options: [
'required' => false,
])
->add(child: 'username')
;
}
#[Override]
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
// Configure your form options here
]);
}
}

View file

@ -19,10 +19,8 @@ final class FoodOrderRepository extends ServiceEntityRepository
parent::__construct($registry, FoodOrder::class);
}
public function save(FoodOrder $order): void
public function save(): void
{
$this->getEntityManager()
->persist($order);
$this->getEntityManager()
->flush();
}

View file

@ -1,100 +0,0 @@
<?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;
}
}

18
src/Service/Favicon.php Normal file
View file

@ -0,0 +1,18 @@
<?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";
}
}

View file

@ -3,8 +3,16 @@
<head>
<meta charset="UTF-8">
<title>{% block title %}Welcome!{% endblock %}</title>
<link rel="icon" type="image/png" href="/static/img/slice-of-pizza.png" />
<link rel="stylesheet" href="/static/css/new.min.css">
<link rel="icon" type="image/svg+xml"
href="{{ favicon }}" />
{% set currentDate = "now"|date("d") %}
{% if currentDate % 3 == 0 %}
<link rel="stylesheet" href="/static/css/new.min.css">
{% elseif currentDate % 3 == 1 %}
<link rel="stylesheet" href="/static/css/simple.min.css">
{% else %}
<link rel="stylesheet" href="/static/css/water.min.css">
{% endif %}
<style>
label{
display: block;
@ -19,7 +27,7 @@
<a href="{{ path('app_food_order_index') }}">Orders</a> /
<a href="{{ path('app_food_vendor_index') }}">Vendors</a> /
<a
href="https://hannover.ccc.de/gitlab/lubiana/futtern/issues/new"
href="https://git.hannover.ccc.de/lubiana/futtern/issues/new"
target="_blank"
>Create Issue</a>
</nav>

View file

@ -25,17 +25,21 @@
<tbody>
{% for food_order in food_orders %}
{{ include('food_order/table_row.html.twig') }}
{% else %}
<tr>
<td colspan="4">no records found</td>
</tr>
{% endfor %}
{% if food_orders|length < 10 %}
<tr>
<td colspan="5">
check the <a href="{{ path('app_food_order_archive') }}">archive</a>
for older orders
</td>
</tr>
{% endif %}
</tbody>
</table>
{% if prev_page > 0 %}
<a href="{{ path('app_food_order_index', {'page': prev_page}) }}">previous page</a> |
<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_index', {'page': next_page}) }}">next page</a>
<a href="{{ path('app_food_order_archive', {'page': next_page}) }}">next page</a>
{% endif %}
{% endblock %}

View file

@ -11,6 +11,10 @@
<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>
@ -43,7 +47,7 @@
</tr>
</thead>
<tbody>
{% for item in food_order.orderItems %}
{% for item in food_order.orderItemsSortedByName %}
<tr>
<td>{{ item.createdBy }}</td>
<td>{{ item.name }}</td>

View file

@ -11,9 +11,26 @@
<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>
</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>

View file

@ -0,0 +1,4 @@
<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>

View file

@ -0,0 +1,4 @@
{{ form_start(form) }}
{{ form_widget(form) }}
<button class="btn">{{ button_label|default('Save') }}</button>
{{ form_end(form) }}

View file

@ -0,0 +1,11 @@
{% 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 %}

View file

@ -0,0 +1,35 @@
{% 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 %}

View file

@ -0,0 +1,11 @@
{% 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 %}

View file

@ -0,0 +1,26 @@
{% 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>
</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 %}

View file

@ -7,6 +7,14 @@
{{ 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>

View file

@ -4,11 +4,17 @@ namespace App\Tests\Controller;
use App\Entity\FoodOrder;
use App\Entity\FoodVendor;
use App\Entity\MenuItem;
use App\Entity\OrderItem;
use App\Tests\DbWebTest;
use Override;
use Symfony\Component\BrowserKit\Cookie;
use Symfony\Component\DomCrawler\Crawler;
use function assert;
use function range;
use function sprintf;
use function str_ends_with;
final class FoodOrderControllerTest extends DbWebTest
{
@ -51,8 +57,127 @@ final class FoodOrderControllerTest extends DbWebTest
);
}
public function testOrderedItems(): 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()}");
self::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);
}
public function testPaginatedIndex(): void
{
$this->generatePaginatedOrders();
$crawler = $this->client->request('GET', "{$this->path}list");
self::assertResponseStatusCodeSame(200);
self::assertPageTitleContains('FoodOrder index');
$this->assertElementContainsCount(
$crawler,
'td',
1,
'older orders'
);
$this->assertElementContainsCount(
$crawler,
'td',
0,
'next page'
);
}
/**
* @testWith [1, 0, 2]
* [2, 1, 3]
* [3, 2, 4]
* [4, 3, 0, 5]
*/
public function testPaginatedFirstPage(int $page, int $prevPage, int $nextPage, int $items = 10): void
{
$this->generatePaginatedOrders();
$crawler = $this->client->request('GET', "{$this->path}list/archive/{$page}");
self::assertResponseStatusCodeSame(200);
self::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}"));
}
}
public function testNew(): void
{
$this->client->getCookieJar()
->set(new Cookie('username', 'Testing-1'));
$this->client->request('GET', sprintf('%snew', $this->path));
self::assertResponseStatusCodeSame(200);
@ -63,5 +188,53 @@ final class FoodOrderControllerTest extends DbWebTest
self::assertResponseRedirects("{$this->path}list");
self::assertSame(1, $this->repository->count([]));
$order = $this->repository->findOneBy([
'createdBy' => 'Testing-1',
]);
assert($order instanceof FoodOrder);
}
public function testOpen(): 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()));
self::assertResponseRedirects("{$this->path}{$order->getId()}");
$openOrder = $this->repository->find($order->getId());
$this->assertFalse($openOrder->isClosed());
}
public function testClose(): 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()));
self::assertResponseRedirects("{$this->path}{$order->getId()}");
$openOrder = $this->repository->find($order->getId());
$this->assertTrue($openOrder->isClosed());
}
private function generatePaginatedOrders(): void
{
foreach (range(1, 35) as $i) {
$order = new FoodOrder($this->generateOldUlid());
$order->setFoodVendor($this->vendor);
$order->close();
$this->manager->persist($order);
}
$this->manager->flush();
}
}

View file

@ -3,6 +3,7 @@
namespace App\Tests\Controller;
use App\Entity\FoodVendor;
use App\Entity\MenuItem;
use App\Tests\DbWebTest;
use Override;
@ -37,6 +38,7 @@ final class FoodVendorControllerTest extends DbWebTest
{
$fixture = new FoodVendor;
$fixture->setName('My Title');
$fixture->setMenuLink('https://example.com/');
$this->manager->persist($fixture);
$this->manager->flush();
@ -44,23 +46,104 @@ final class FoodVendorControllerTest extends DbWebTest
$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());
$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);
}
public function testShowMenuItems(): 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);
}
public function testEdit(): void
{
$fixture = new FoodVendor;
$fixture->setName('Value');
$fixture->setMenuLink('Value');
$fixture->setPhone('Value');
$this->manager->persist($fixture);
$this->manager->flush();
$this->client->request('GET', sprintf('%s%s/edit', $this->path, $fixture->getId()));
$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',
]);
self::assertResponseRedirects('/food/vendor/');
@ -68,6 +151,8 @@ final class FoodVendorControllerTest extends DbWebTest
$fixture = $this->repository->findAll();
self::assertSame('Something New', $fixture[0]->getName());
self::assertSame('https://example.com/', $fixture[0]->getMenuLink());
self::assertSame('1234567890', $fixture[0]->getPhone());
}
#[Override]

View file

@ -0,0 +1,76 @@
<?php declare(strict_types=1);
namespace App\Tests\Controller;
use App\Tests\DbWebTest;
use Override;
final class HomeControllerTest extends DbWebTest
{
public function testIndex(): void
{
$this->client->request(
'GET',
'/'
);
self::assertResponseStatusCodeSame(302);
self::assertResponseHeaderSame('Location', '/food/order/list');
}
public function testSetUsername(): void
{
$this->client->request(
'GET',
'/username',
);
self::assertResponseStatusCodeSame(200);
$this->client->submitForm('Save', [
'user_name_form[username]' => 'Testing-1',
]);
self::assertResponseStatusCodeSame(302);
self::assertResponseHeaderSame('Location', '/food/order/list');
self::assertResponseCookieValueSame('username', 'Testing-1');
$crawler = $this->client->request(
'GET',
'/username',
);
self::assertResponseStatusCodeSame(200);
$this->assertSame(
$crawler->filter('#user_name_form_username')
->last()
->attr('value', ''),
'Testing-1'
);
}
public function testRemoveUsername(): void
{
$this->client->request(
'GET',
'/username',
);
self::assertResponseStatusCodeSame(200);
$this->client->submitForm('Save', [
'user_name_form[username]' => '',
]);
self::assertResponseStatusCodeSame(302);
self::assertResponseHeaderSame('Location', '/food/order/list');
self::assertResponseCookieValueSame('username', '');
}
#[Override]
public function getEntityClass(): string
{
return '';
}
}

View file

@ -0,0 +1,113 @@
<?php declare(strict_types=1);
namespace App\Tests\Controller;
use App\Entity\FoodOrder;
use App\Entity\FoodVendor;
use App\Entity\MenuItem;
use App\Tests\DbWebTest;
use Override;
use function sprintf;
final class MenuItemControllerTest extends DbWebTest
{
private string $path = '/menu/item/';
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 MenuItem::class;
}
public function testShow(): void
{
$menuItem = new MenuItem;
$menuItem->setName('Testing 1 2');
$this->vendor->addMenuItem($menuItem);
$this->manager->persist($this->vendor);
$this->manager->persist($menuItem);
$this->manager->flush();
$crawler = $this->client->request('GET', "{$this->path}{$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();
self::assertResponseStatusCodeSame(200);
$this->assertEquals($idValue, $menuItem->getId());
$this->assertEquals($nameValue, $menuItem->getName());
}
public function testEdit(): void
{
$menuItem = new MenuItem;
$menuItem->setName('Testing 1 2');
$this->vendor->addMenuItem($menuItem);
$this->manager->persist($this->vendor);
$this->manager->persist($menuItem);
$this->manager->flush();
$crawler = $this->client->request('GET', sprintf('%s%s/edit', $this->path, $menuItem->getId()));
$nameElem = $crawler->filter('#menu_item_name');
$this->assertEquals(
'Testing 1 2',
$nameElem->attr('value')
);
$this->client->submitForm('Update', [
'menu_item[name]' => 'Testing-1',
]);
self::assertResponseRedirects(sprintf('/menu/item/%s', $menuItem->getId()));
}
public function testDelete(): void
{
$menuItem = new MenuItem;
$menuItem->setName('Testing 1 2');
$this->vendor->addMenuItem($menuItem);
$this->manager->persist($this->vendor);
$this->manager->persist($menuItem);
$order = new FoodOrder;
$order->setFoodVendor($this->vendor);
$this->manager->persist($order);
$this->manager->flush();
$this->assertFalse($menuItem->isDeleted());
$this->client->request('GET', "{$this->path}{$menuItem->getId()}");
$this->client->submitForm('Delete', []);
$menuItem = $this->repository->find($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(0, $count);
$this->assertResponseIsSuccessful();
}
}

View file

@ -8,6 +8,7 @@ use App\Entity\MenuItem;
use App\Entity\OrderItem;
use App\Repository\MenuItemRepository;
use App\Tests\DbWebTest;
use DateTimeImmutable;
use Override;
use function sprintf;
@ -37,6 +38,16 @@ final class OrderItemControllerTest extends DbWebTest
$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();
@ -45,11 +56,16 @@ final class OrderItemControllerTest extends DbWebTest
public function testNew(): void
{
$this->client->request(
$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);
self::assertResponseStatusCodeSame(200);
$this->client->submitForm('Save', [
@ -60,7 +76,26 @@ final class OrderItemControllerTest extends DbWebTest
self::assertResponseRedirects(sprintf('/food/order/%s', $this->order->getId()));
self::assertSame(1, $this->repository->count([]));
self::assertSame(1, $this->menuItemRepository->count([]));
self::assertSame(1, $this->menuItemRepository->count([
'foodVendor' => $this->vendor->getId(),
]));
}
public function testNewOrderClosed(): 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())
);
self::assertResponseRedirects(sprintf('/food/order/%s', $this->order->getId()));
self::assertSame(0, $this->repository->count([]));
}
public function testNewCreateMenuItem(): void
@ -80,7 +115,7 @@ final class OrderItemControllerTest extends DbWebTest
self::assertResponseRedirects(sprintf('/food/order/%s', $this->order->getId()));
self::assertSame(1, $this->repository->count([]));
self::assertSame(2, $this->menuItemRepository->count([]));
self::assertSame(3, $this->menuItemRepository->count([]));
}
public function testRemove(): void
@ -101,6 +136,80 @@ final class OrderItemControllerTest extends DbWebTest
self::assertSame(0, $this->repository->count([]));
}
public function testOrderClosed(): 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()));
self::assertResponseRedirects(sprintf('/food/order/%s', $this->order->getId()));
self::assertSame(1, $this->repository->count([]));
}
public function testEdit(): 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',
]);
self::assertResponseRedirects(sprintf('/food/order/%s', $this->order->getId()));
self::assertSame(1, $this->repository->count([]));
self::assertSame(3, $this->menuItemRepository->count([]));
}
public function testEditOrderClosed(): 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()));
self::assertResponseRedirects(sprintf('/food/order/%s', $this->order->getId()));
}
public function testCopy(): void
{
$orderItem = new OrderItem;
@ -123,7 +232,28 @@ final class OrderItemControllerTest extends DbWebTest
$this->assertSame($orderItem->getName(), $item->getName());
$this->assertSame($orderItem->getExtras(), $item->getExtras());
}
}
public function testCopyOrderClosed(): 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()));
self::assertResponseRedirects(sprintf('/food/order/%s', $this->order->getId()));
$result = $this->repository->findBy([
'foodOrder' => $this->order->getId(),
]);
$this->assertCount(1, $result);
}
#[Override]

View file

@ -2,12 +2,18 @@
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
{
@ -28,6 +34,26 @@ abstract class DbWebTest extends WebTestCase
$schemaTool->dropDatabase();
$schemaTool->updateSchema($metadata);
$this->repository = $this->manager->getRepository($this->getEntityClass());
if ($this->getEntityClass() !== '') {
$this->repository = $this->manager->getRepository($this->getEntityClass());
}
}
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),
)
);
}
}

View file

@ -0,0 +1,24 @@
<?php declare(strict_types=1);
namespace App\Tests\Entity;
use App\Entity\FoodOrder;
use App\Entity\OrderItem;
use PHPUnit\Framework\TestCase;
final class FoodOrderTest extends TestCase
{
public function testFoodOrder(): void
{
$order = new FoodOrder;
$orderItem = new OrderItem;
$this->assertCount(0, $order->getOrderItems());
$order->addOrderItem($orderItem);
$order->addOrderItem($orderItem);
$this->assertCount(1, $order->getOrderItems());
$this->assertSame($order, $orderItem->getFoodOrder());
$order->removeOrderItem($orderItem);
$this->assertCount(0, $order->getOrderItems());
$this->assertNull($orderItem->getFoodOrder());
}
}

View file

@ -0,0 +1,66 @@
<?php declare(strict_types=1);
namespace App\Tests\Entity;
use App\Entity\FoodOrder;
use App\Entity\FoodVendor;
use App\Entity\MenuItem;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Uid\Ulid;
final class FoodVendorTest extends TestCase
{
public function testFoodVendor(): 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());
}
public function testMenuItem(): 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));
}
public function testRemoveForeignMenuItem(): 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());
}
}

View file

@ -0,0 +1,30 @@
<?php declare(strict_types=1);
namespace App\Tests\Entity;
use App\Entity\FoodVendor;
use App\Entity\MenuItem;
use DateTimeImmutable;
use PHPUnit\Framework\TestCase;
final class MenuItemTest extends TestCase
{
public function testMenuItem(): 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());
}
}