Compare commits
No commits in common. "main" and "ci-opti" have entirely different histories.
24 changed files with 501 additions and 1514 deletions
|
@ -9,7 +9,7 @@ jobs:
|
|||
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
|
||||
|
@ -23,19 +23,7 @@ jobs:
|
|||
- name: lint
|
||||
run: composer lint
|
||||
- name: 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"
|
||||
run: composer test
|
||||
- name: GIT commit and push all changed files
|
||||
env:
|
||||
CI_COMMIT_MESSAGE: Continuous Integration Fixes
|
||||
|
|
|
@ -13,7 +13,7 @@ jobs:
|
|||
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
|
||||
|
@ -27,7 +27,7 @@ jobs:
|
|||
- name: lint
|
||||
run: composer lint
|
||||
- name: test
|
||||
run: composer mutation
|
||||
run: composer test
|
||||
- name: GIT commit and push all changed files
|
||||
env:
|
||||
CI_COMMIT_MESSAGE: Continuous Integration Fixes
|
||||
|
|
|
@ -7,14 +7,14 @@
|
|||
"php": ">=8.3",
|
||||
"ext-ctype": "*",
|
||||
"ext-iconv": "*",
|
||||
"doctrine/dbal": "^4.1",
|
||||
"doctrine/dbal": "^4",
|
||||
"doctrine/doctrine-bundle": "^2.12",
|
||||
"doctrine/doctrine-migrations-bundle": "^3.3.1",
|
||||
"doctrine/orm": "^3.2.1",
|
||||
"doctrine/doctrine-migrations-bundle": "^3.3",
|
||||
"doctrine/orm": "^3.2",
|
||||
"psr/clock": "^1.0",
|
||||
"symfony/console": "7.1.*",
|
||||
"symfony/dotenv": "7.1.*",
|
||||
"symfony/flex": "^2.4.6",
|
||||
"symfony/flex": "^2",
|
||||
"symfony/form": "7.1.*",
|
||||
"symfony/framework-bundle": "7.1.*",
|
||||
"symfony/runtime": "7.1.*",
|
||||
|
@ -25,22 +25,20 @@
|
|||
"symfony/yaml": "7.1.*"
|
||||
},
|
||||
"require-dev": {
|
||||
"infection/infection": "^0.29.6",
|
||||
"lubiana/code-quality": "^1.7.2",
|
||||
"phpunit/phpunit": "^9.6.20",
|
||||
"lubiana/code-quality": "^1.7",
|
||||
"phpunit/phpunit": "^9.6.19",
|
||||
"symfony/browser-kit": "7.1.*",
|
||||
"symfony/css-selector": "7.1.*",
|
||||
"symfony/maker-bundle": "^1.60",
|
||||
"symfony/phpunit-bridge": "^7.1.3",
|
||||
"symplify/config-transformer": "^12.3.4"
|
||||
"symfony/phpunit-bridge": "^7.1",
|
||||
"symplify/config-transformer": "^12.3"
|
||||
},
|
||||
"config": {
|
||||
"allow-plugins": {
|
||||
"php-http/discovery": true,
|
||||
"symfony/flex": true,
|
||||
"symfony/runtime": true,
|
||||
"dealerdirect/phpcodesniffer-composer-installer": true,
|
||||
"infection/extension-installer": true
|
||||
"dealerdirect/phpcodesniffer-composer-installer": true
|
||||
},
|
||||
"sort-packages": true,
|
||||
"platform": {
|
||||
|
@ -83,8 +81,7 @@
|
|||
"rector",
|
||||
"ecs --fix || ecs --fix"
|
||||
],
|
||||
"test": "bin/phpunit",
|
||||
"mutation": "infection --threads=8 --show-mutations"
|
||||
"test": "bin/phpunit"
|
||||
},
|
||||
"conflict": {
|
||||
"symfony/symfony": "*"
|
||||
|
|
1613
composer.lock
generated
1613
composer.lock
generated
File diff suppressed because it is too large
Load diff
|
@ -1,20 +0,0 @@
|
|||
{
|
||||
"$schema": "vendor/infection/infection/resources/schema.json",
|
||||
"source": {
|
||||
"directories": [
|
||||
"src"
|
||||
]
|
||||
},
|
||||
"timeout": 30,
|
||||
"logs": {
|
||||
"text": "var/log/infection.txt",
|
||||
"summary": "var/log/summary.log",
|
||||
},
|
||||
"mutators": {
|
||||
"@default": true,
|
||||
"global-ignore": [
|
||||
"App\\Service\\Favicon::__toString",
|
||||
"ORM\\Column.*"
|
||||
]
|
||||
}
|
||||
}
|
|
@ -6,9 +6,7 @@
|
|||
backupGlobals="false"
|
||||
colors="true"
|
||||
bootstrap="tests/bootstrap.php"
|
||||
convertDeprecationsToExceptions="true"
|
||||
executionOrder="random"
|
||||
resolveDependencies="true"
|
||||
convertDeprecationsToExceptions="false"
|
||||
>
|
||||
<php>
|
||||
<ini name="display_errors" value="1" />
|
||||
|
@ -30,6 +28,10 @@
|
|||
<include>
|
||||
<directory suffix=".php">src</directory>
|
||||
</include>
|
||||
<exclude>
|
||||
<directory suffix=".php">src/Command</directory>
|
||||
<file>src/Service/FakeData.php</file>
|
||||
</exclude>
|
||||
</coverage>
|
||||
|
||||
<listeners>
|
||||
|
|
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;
|
||||
}
|
||||
}
|
|
@ -95,8 +95,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 +104,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);
|
||||
|
|
|
@ -46,6 +46,7 @@ final class MenuItemController extends AbstractController
|
|||
{
|
||||
if ($this->isCsrfTokenValid('delete' . $menuItem->getId(), $request->getPayload()->getString('_token'))) {
|
||||
$menuItem->delete();
|
||||
$entityManager->persist($menuItem);
|
||||
$entityManager->flush();
|
||||
}
|
||||
|
||||
|
|
|
@ -56,7 +56,6 @@ final class OrderItemController extends AbstractController
|
|||
}
|
||||
$menuItems = $menuItemRepository->findBy([
|
||||
'foodVendor' => $foodOrder->getFoodVendor(),
|
||||
'deletedAt' => null,
|
||||
]);
|
||||
|
||||
return $this->render('order_item/new.html.twig', [
|
||||
|
|
|
@ -134,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)) {
|
||||
if ($this->orderItems->removeElement($orderItem) && $orderItem->getFoodOrder() === $this) {
|
||||
$orderItem->setFoodOrder(null);
|
||||
}
|
||||
|
||||
|
|
|
@ -80,7 +80,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);
|
||||
}
|
||||
|
||||
|
@ -113,7 +113,7 @@ 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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
{
|
||||
|
@ -29,4 +31,12 @@ final class FoodOrderType extends AbstractType
|
|||
$builder->setAction($action);
|
||||
}
|
||||
}
|
||||
|
||||
#[Override]
|
||||
public function configureOptions(OptionsResolver $resolver): void
|
||||
{
|
||||
$resolver->setDefaults([
|
||||
'data_class' => FoodOrder::class,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,8 +19,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();
|
||||
}
|
||||
|
|
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;
|
||||
}
|
||||
}
|
|
@ -118,13 +118,7 @@ final class FoodVendorControllerTest extends DbWebTest
|
|||
$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->client->request('GET', sprintf('%s%s/edit', $this->path, $fixture->getId()));
|
||||
|
||||
$this->client->submitForm('Update', [
|
||||
'food_vendor[name]' => 'Something New',
|
||||
|
|
|
@ -34,21 +34,6 @@ final class HomeControllerTest extends DbWebTest
|
|||
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
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
namespace App\Tests\Controller;
|
||||
|
||||
use App\Entity\FoodOrder;
|
||||
use App\Entity\FoodVendor;
|
||||
use App\Entity\MenuItem;
|
||||
use App\Tests\DbWebTest;
|
||||
|
@ -86,11 +85,6 @@ final class MenuItemControllerTest extends DbWebTest
|
|||
$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());
|
||||
|
||||
|
@ -100,14 +94,5 @@ final class MenuItemControllerTest extends DbWebTest
|
|||
$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();
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,16 +38,6 @@ 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();
|
||||
|
||||
|
@ -56,16 +46,11 @@ final class OrderItemControllerTest extends DbWebTest
|
|||
|
||||
public function testNew(): void
|
||||
{
|
||||
$crawler = $this->client->request(
|
||||
$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', [
|
||||
|
@ -76,9 +61,7 @@ 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([
|
||||
'foodVendor' => $this->vendor->getId(),
|
||||
]));
|
||||
self::assertSame(1, $this->menuItemRepository->count([]));
|
||||
}
|
||||
|
||||
public function testNewOrderClosed(): void
|
||||
|
@ -115,7 +98,7 @@ final class OrderItemControllerTest extends DbWebTest
|
|||
self::assertResponseRedirects(sprintf('/food/order/%s', $this->order->getId()));
|
||||
|
||||
self::assertSame(1, $this->repository->count([]));
|
||||
self::assertSame(3, $this->menuItemRepository->count([]));
|
||||
self::assertSame(2, $this->menuItemRepository->count([]));
|
||||
}
|
||||
|
||||
public function testRemove(): void
|
||||
|
@ -188,7 +171,7 @@ final class OrderItemControllerTest extends DbWebTest
|
|||
self::assertResponseRedirects(sprintf('/food/order/%s', $this->order->getId()));
|
||||
|
||||
self::assertSame(1, $this->repository->count([]));
|
||||
self::assertSame(3, $this->menuItemRepository->count([]));
|
||||
self::assertSame(2, $this->menuItemRepository->count([]));
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -16,9 +16,8 @@ final class FoodOrderTest extends TestCase
|
|||
$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());
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,16 +22,9 @@ final class FoodVendorTest extends TestCase
|
|||
$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());
|
||||
|
@ -40,24 +33,11 @@ final class FoodVendorTest extends TestCase
|
|||
$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());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,7 +4,6 @@ namespace App\Tests\Entity;
|
|||
|
||||
use App\Entity\FoodVendor;
|
||||
use App\Entity\MenuItem;
|
||||
use DateTimeImmutable;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
final class MenuItemTest extends TestCase
|
||||
|
@ -22,9 +21,7 @@ final class MenuItemTest extends TestCase
|
|||
$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());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue