From 634f13d968790b4dc331d9ee02ec0c4d7f1cff1c Mon Sep 17 00:00:00 2001 From: lubiana Date: Thu, 27 Jun 2024 16:57:15 +0200 Subject: [PATCH] reset database for each test, test menuitem creation --- tests/Controller/OrderItemControllerTest.php | 24 ++++++++++++++++++++ tests/DbWebTest.php | 7 +----- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/tests/Controller/OrderItemControllerTest.php b/tests/Controller/OrderItemControllerTest.php index a7b0fb8..a5f6da2 100644 --- a/tests/Controller/OrderItemControllerTest.php +++ b/tests/Controller/OrderItemControllerTest.php @@ -6,6 +6,7 @@ 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; @@ -16,6 +17,7 @@ final class OrderItemControllerTest extends DbWebTest public FoodVendor $vendor; public FoodOrder $order; public Menuitem $menuItem; + public MenuItemRepository $menuItemRepository; private string $path = '/order/item/'; #[Override] @@ -37,6 +39,7 @@ final class OrderItemControllerTest extends DbWebTest $this->manager->persist($this->menuItem); $this->manager->flush(); + $this->menuItemRepository = static::getContainer()->get(MenuItemRepository::class); } public function testNew(): void @@ -56,6 +59,27 @@ 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([])); + } + + 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 diff --git a/tests/DbWebTest.php b/tests/DbWebTest.php index cbcf5c9..c2491c6 100644 --- a/tests/DbWebTest.php +++ b/tests/DbWebTest.php @@ -25,13 +25,8 @@ abstract class DbWebTest extends WebTestCase $schemaTool = new SchemaTool($this->manager); $metadata = $this->manager->getMetadataFactory() ->getAllMetadata(); + $schemaTool->dropDatabase(); $schemaTool->updateSchema($metadata); - $this->repository = $this->manager->getRepository($this->getEntityClass()); - foreach ($this->repository->findAll() as $object) { - $this->manager->remove($object); - } - - $this->manager->flush(); } } -- 2.39.5