reset database for each test, test menuitem creation
This commit is contained in:
parent
01354fa70c
commit
634f13d968
2 changed files with 25 additions and 6 deletions
|
@ -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
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue