From f259294e6ffaefd35f5b0e29f40c77e05ba43e7d Mon Sep 17 00:00:00 2001 From: lubiana Date: Sat, 15 Jun 2024 16:59:48 +0200 Subject: [PATCH] add order item tests --- src/Controller/OrderItemController.php | 2 +- tests/Controller/OrderItemControllerTest.php | 98 ++++++++++---------- 2 files changed, 49 insertions(+), 51 deletions(-) diff --git a/src/Controller/OrderItemController.php b/src/Controller/OrderItemController.php index e9f17c3..5f819ef 100644 --- a/src/Controller/OrderItemController.php +++ b/src/Controller/OrderItemController.php @@ -92,7 +92,7 @@ final class OrderItemController extends AbstractController ]); } - #[Route('/{id}', name: 'app_order_item_delete')] + #[Route('/delete/{id}', name: 'app_order_item_delete')] public function delete(OrderItem $orderItem, EntityManagerInterface $entityManager): Response { $foodOrder = $orderItem->getFoodOrder(); diff --git a/tests/Controller/OrderItemControllerTest.php b/tests/Controller/OrderItemControllerTest.php index cb4ed3c..5be450c 100644 --- a/tests/Controller/OrderItemControllerTest.php +++ b/tests/Controller/OrderItemControllerTest.php @@ -2,6 +2,8 @@ namespace App\Tests\Controller; +use App\Entity\FoodOrder; +use App\Entity\FoodVendor; use App\Entity\OrderItem; use App\Tests\DbWebTest; use Override; @@ -10,12 +12,28 @@ use function sprintf; final class OrderItemControllerTest extends DbWebTest { + public FoodVendor $vendor; + public FoodOrder $order; 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->manager->flush(); + } + public function testNew(): void { - $this->markTestIncomplete(); - $this->client->request('GET', sprintf('%snew', $this->path)); + $this->client->request('GET', sprintf('%snew/%s', $this->path, $this->order->getId())); self::assertResponseStatusCodeSame(200); @@ -24,71 +42,51 @@ final class OrderItemControllerTest extends DbWebTest 'order_item[extras]' => 'Testing', ]); - self::assertResponseRedirects($this->path); + self::assertResponseRedirects(sprintf('/food/order/%s', $this->order->getId())); self::assertSame(1, $this->repository->count([])); } - public function testShow(): void - { - $this->markTestIncomplete(); - $fixture = new OrderItem; - $fixture->setName('My Title'); - $fixture->setExtras('My Title'); - - $this->manager->persist($fixture); - $this->manager->flush(); - - $this->client->request('GET', sprintf('%s%s', $this->path, $fixture->getId())); - - self::assertResponseStatusCodeSame(200); - self::assertPageTitleContains('OrderItem'); - - // Use assertions to check that the properties are properly displayed. - } - - public function testEdit(): void - { - $this->markTestIncomplete(); - $fixture = new OrderItem; - $fixture->setName('Value'); - $fixture->setExtras('Value'); - - $this->manager->persist($fixture); - $this->manager->flush(); - - $this->client->request('GET', sprintf('%s%s/edit', $this->path, $fixture->getId())); - - $this->client->submitForm('Update', [ - 'order_item[name]' => 'Something New', - 'order_item[extras]' => 'Something New', - ]); - - self::assertResponseRedirects('/order/item/'); - - $fixture = $this->repository->findAll(); - - self::assertSame('Something New', $fixture[0]->getName()); - self::assertSame('Something New', $fixture[0]->getExtras()); - } - public function testRemove(): void { - $this->markTestIncomplete(); $fixture = new OrderItem; $fixture->setName('Value'); $fixture->setExtras('Value'); + $fixture->setFoodOrder($this->order); $this->manager->persist($fixture); $this->manager->flush(); - $this->client->request('GET', sprintf('%s%s', $this->path, $fixture->getId())); - $this->client->submitForm('Delete'); + $this->client->request('GET', sprintf('%sdelete/%s', $this->path, $fixture->getId())); - self::assertResponseRedirects('/order/item/'); + 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); + + $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 { -- 2.39.5