reset database for each test, test menuitem creation
Some checks failed
/ ls (pull_request) Successful in 35s
/ ls (push) Failing after 34s

This commit is contained in:
Jonas 2024-06-27 16:57:15 +02:00
parent 01354fa70c
commit 634f13d968
Signed by: lubiana
SSH key fingerprint: SHA256:gkqM8DUX4Blf6P52fycW8ISTd+4eAHH+Uzu9iyc8hAM
2 changed files with 25 additions and 6 deletions

View file

@ -6,6 +6,7 @@ use App\Entity\FoodOrder;
use App\Entity\FoodVendor; use App\Entity\FoodVendor;
use App\Entity\MenuItem; use App\Entity\MenuItem;
use App\Entity\OrderItem; use App\Entity\OrderItem;
use App\Repository\MenuItemRepository;
use App\Tests\DbWebTest; use App\Tests\DbWebTest;
use Override; use Override;
@ -16,6 +17,7 @@ final class OrderItemControllerTest extends DbWebTest
public FoodVendor $vendor; public FoodVendor $vendor;
public FoodOrder $order; public FoodOrder $order;
public Menuitem $menuItem; public Menuitem $menuItem;
public MenuItemRepository $menuItemRepository;
private string $path = '/order/item/'; private string $path = '/order/item/';
#[Override] #[Override]
@ -37,6 +39,7 @@ final class OrderItemControllerTest extends DbWebTest
$this->manager->persist($this->menuItem); $this->manager->persist($this->menuItem);
$this->manager->flush(); $this->manager->flush();
$this->menuItemRepository = static::getContainer()->get(MenuItemRepository::class);
} }
public function testNew(): void public function testNew(): void
@ -56,6 +59,27 @@ final class OrderItemControllerTest extends DbWebTest
self::assertResponseRedirects(sprintf('/food/order/%s', $this->order->getId())); self::assertResponseRedirects(sprintf('/food/order/%s', $this->order->getId()));
self::assertSame(1, $this->repository->count([])); 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 public function testRemove(): void

View file

@ -25,13 +25,8 @@ abstract class DbWebTest extends WebTestCase
$schemaTool = new SchemaTool($this->manager); $schemaTool = new SchemaTool($this->manager);
$metadata = $this->manager->getMetadataFactory() $metadata = $this->manager->getMetadataFactory()
->getAllMetadata(); ->getAllMetadata();
$schemaTool->dropDatabase();
$schemaTool->updateSchema($metadata); $schemaTool->updateSchema($metadata);
$this->repository = $this->manager->getRepository($this->getEntityClass()); $this->repository = $this->manager->getRepository($this->getEntityClass());
foreach ($this->repository->findAll() as $object) {
$this->manager->remove($object);
}
$this->manager->flush();
} }
} }