2024-06-14 15:41:00 +00:00
|
|
|
<?php declare(strict_types=1);
|
|
|
|
|
2024-06-14 18:43:11 +00:00
|
|
|
namespace App\Tests\Controller;
|
2024-06-14 15:41:00 +00:00
|
|
|
|
2024-06-15 14:59:48 +00:00
|
|
|
use App\Entity\FoodOrder;
|
|
|
|
use App\Entity\FoodVendor;
|
2024-06-26 18:31:27 +00:00
|
|
|
use App\Entity\MenuItem;
|
2024-06-14 15:41:00 +00:00
|
|
|
use App\Entity\OrderItem;
|
|
|
|
use App\Tests\DbWebTest;
|
|
|
|
use Override;
|
|
|
|
|
|
|
|
use function sprintf;
|
|
|
|
|
|
|
|
final class OrderItemControllerTest extends DbWebTest
|
|
|
|
{
|
2024-06-15 14:59:48 +00:00
|
|
|
public FoodVendor $vendor;
|
|
|
|
public FoodOrder $order;
|
2024-06-26 18:31:27 +00:00
|
|
|
public Menuitem $menuItem;
|
2024-06-14 15:41:00 +00:00
|
|
|
private string $path = '/order/item/';
|
|
|
|
|
2024-06-15 14:59:48 +00:00
|
|
|
#[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);
|
2024-06-26 18:31:27 +00:00
|
|
|
|
|
|
|
$this->menuItem = new MenuItem();
|
|
|
|
$this->menuItem->setName('Testing');
|
|
|
|
$this->menuItem->setFoodVendor($this->vendor);
|
|
|
|
$this->manager->persist($this->menuItem);
|
2024-06-15 14:59:48 +00:00
|
|
|
$this->manager->flush();
|
|
|
|
}
|
|
|
|
|
2024-06-14 15:41:00 +00:00
|
|
|
public function testNew(): void
|
|
|
|
{
|
2024-06-15 16:37:22 +00:00
|
|
|
$this->client->request(
|
|
|
|
'GET',
|
|
|
|
sprintf('%snew/%s', $this->path, $this->order->getId())
|
|
|
|
);
|
2024-06-14 15:41:00 +00:00
|
|
|
|
|
|
|
self::assertResponseStatusCodeSame(200);
|
|
|
|
|
|
|
|
$this->client->submitForm('Save', [
|
|
|
|
'order_item[name]' => 'Testing',
|
|
|
|
'order_item[extras]' => 'Testing',
|
|
|
|
]);
|
|
|
|
|
2024-06-15 14:59:48 +00:00
|
|
|
self::assertResponseRedirects(sprintf('/food/order/%s', $this->order->getId()));
|
2024-06-14 15:41:00 +00:00
|
|
|
|
|
|
|
self::assertSame(1, $this->repository->count([]));
|
|
|
|
}
|
|
|
|
|
2024-06-15 14:59:48 +00:00
|
|
|
public function testRemove(): void
|
2024-06-14 15:41:00 +00:00
|
|
|
{
|
|
|
|
$fixture = new OrderItem;
|
2024-06-26 18:31:27 +00:00
|
|
|
$fixture->setName('Testing');
|
2024-06-14 15:41:00 +00:00
|
|
|
$fixture->setExtras('Value');
|
2024-06-26 18:31:27 +00:00
|
|
|
$fixture->setMenuItem($this->menuItem);
|
|
|
|
|
2024-06-15 14:59:48 +00:00
|
|
|
$fixture->setFoodOrder($this->order);
|
2024-06-14 15:41:00 +00:00
|
|
|
|
|
|
|
$this->manager->persist($fixture);
|
|
|
|
$this->manager->flush();
|
|
|
|
|
2024-06-15 14:59:48 +00:00
|
|
|
$this->client->request('GET', sprintf('%sdelete/%s', $this->path, $fixture->getId()));
|
2024-06-14 15:41:00 +00:00
|
|
|
|
2024-06-15 14:59:48 +00:00
|
|
|
self::assertResponseRedirects(sprintf('/food/order/%s', $this->order->getId()));
|
|
|
|
self::assertSame(0, $this->repository->count([]));
|
2024-06-14 15:41:00 +00:00
|
|
|
}
|
|
|
|
|
2024-06-15 14:59:48 +00:00
|
|
|
public function testCopy(): void
|
2024-06-14 15:41:00 +00:00
|
|
|
{
|
2024-06-15 14:59:48 +00:00
|
|
|
$orderItem = new OrderItem;
|
|
|
|
$orderItem->setName('My Title');
|
|
|
|
$orderItem->setExtras('My Title');
|
|
|
|
$orderItem->setFoodOrder($this->order);
|
2024-06-26 18:31:27 +00:00
|
|
|
$orderItem->setMenuItem($this->menuItem);
|
2024-06-14 15:41:00 +00:00
|
|
|
|
2024-06-15 14:59:48 +00:00
|
|
|
$this->manager->persist($orderItem);
|
2024-06-14 15:41:00 +00:00
|
|
|
$this->manager->flush();
|
|
|
|
|
2024-06-15 14:59:48 +00:00
|
|
|
$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());
|
|
|
|
}
|
2024-06-14 15:41:00 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#[Override]
|
|
|
|
public function getEntityClass(): string
|
|
|
|
{
|
|
|
|
return OrderItem::class;
|
|
|
|
}
|
|
|
|
}
|