add order item tests
All checks were successful
/ ls (pull_request) Successful in 29s
/ ls (push) Successful in 29s

This commit is contained in:
Jonas 2024-06-15 16:59:48 +02:00
parent db246ddd8c
commit f259294e6f
Signed by: lubiana
SSH key fingerprint: SHA256:gkqM8DUX4Blf6P52fycW8ISTd+4eAHH+Uzu9iyc8hAM
2 changed files with 49 additions and 51 deletions

View file

@ -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();

View file

@ -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
{