migrate test cases to use pestphp syntax
All checks were successful
/ ls (pull_request) Successful in 1m27s
/ ls (push) Successful in 1m24s
/ ls (release) Successful in 49s

This commit is contained in:
lubiana 2025-02-01 22:37:07 +01:00
parent af9354ff22
commit 9c98735db7
Signed by: lubiana
SSH key fingerprint: SHA256:vW1EA0fRR3Fw+dD/sM0K+x3Il2gSry6YRYHqOeQwrfk
14 changed files with 365 additions and 415 deletions

View file

@ -0,0 +1,244 @@
<?php declare(strict_types=1);
namespace App\Tests\Feature\Controller;
use App\Controller\FoodOrderController;
use App\Entity\FoodOrder;
use App\Entity\FoodVendor;
use App\Entity\MenuItem;
use App\Entity\OrderItem;
use App\Form\FoodOrderType;
use App\Repository\FoodOrderRepository;
use App\Repository\FoodVendorRepository;
use Symfony\Component\BrowserKit\Cookie;
use Symfony\Component\DomCrawler\Crawler;
use function assert;
use function describe;
use function pest;
use function range;
use function sprintf;
use function str_ends_with;
use function test;
pest()
->beforeEach(function (): void {
$this->setEntityClass(FoodOrder::class);
$this->setPath('/food/order/');
$this->repository = $this->manager->getRepository($this->entityClass);
$this->vendor = new FoodVendor;
$this->vendor->setName('Food Vendor');
$this->manager->persist($this->vendor);
$this->manager->flush();
});
describe(FoodOrderController::class, function (): void {
test('index', function (): void {
$order = new FoodOrder;
$order->setFoodVendor($this->vendor);
$this->manager->persist($order);
$this->manager->persist($this->vendor);
$this->manager->flush();
$crawler = $this->client->request('GET', "{$this->path}list");
$this->assertResponseStatusCodeSame(200);
$this->assertPageTitleContains('FoodOrder index');
$this->assertCount(
1,
$crawler->filter('td')
->reduce(fn(Crawler $node, $i): bool => $node->text() === $this->vendor->getName()),
);
});
test('orderedItems', function (): void {
$order = new FoodOrder;
$order->setFoodVendor($this->vendor);
$this->manager->persist($order);
$this->manager->persist($this->vendor);
$menuItemA = new MenuItem;
$menuItemA->setName('A');
$menuItemA->setFoodVendor($this->vendor);
$this->manager->persist($menuItemA);
$itemA = new OrderItem;
$itemA->setMenuItem($menuItemA);
$itemA->setName($menuItemA->getName());
$order->addOrderItem($itemA);
$this->manager->persist($itemA);
$menuItemC = new MenuItem;
$menuItemC->setName('C');
$menuItemC->setFoodVendor($this->vendor);
$this->manager->persist($menuItemC);
$itemC = new OrderItem;
$itemC->setMenuItem($menuItemC);
$itemC->setName($menuItemC->getName());
$order->addOrderItem($itemC);
$this->manager->persist($itemC);
$menuItemB = new MenuItem;
$menuItemB->setName('B');
$menuItemB->setFoodVendor($this->vendor);
$this->manager->persist($menuItemB);
$itemB = new OrderItem;
$itemB->setMenuItem($menuItemB);
$itemB->setName($menuItemB->getName());
$order->addOrderItem($itemB);
$this->manager->persist($itemB);
$this->manager->flush();
$crawler = $this->client->request('GET', "{$this->path}{$order->getId()}");
$this->assertResponseIsSuccessful();
$tdContent = $crawler->filter(
'table.table:nth-child(6) > tbody:nth-child(2) > tr:nth-child(1) > td:nth-child(2)'
)->text();
$this->assertEquals('A', $tdContent);
$tdContent = $crawler->filter(
'table.table:nth-child(6) > tbody:nth-child(2) > tr:nth-child(2) > td:nth-child(2)'
)->text();
$this->assertEquals('B', $tdContent);
$tdContent = $crawler->filter(
'table.table:nth-child(6) > tbody:nth-child(2) > tr:nth-child(3) > td:nth-child(2)'
)->text();
$this->assertEquals('C', $tdContent);
});
test('paginatedIndex', function (): void {
foreach (range(1, 35) as $i) {
$order = new FoodOrder($this->generateOldUlid());
$order->setFoodVendor($this->vendor);
$order->close();
$this->manager->persist($order);
}
$this->manager->flush();
$crawler = $this->client->request('GET', "{$this->path}list");
$this->assertResponseStatusCodeSame(200);
$this->assertPageTitleContains('FoodOrder index');
$this->assertElementContainsCount(
$crawler,
'td',
1,
'older orders'
);
$this->assertElementContainsCount(
$crawler,
'td',
0,
'next page'
);
});
test('paginatedFirstPage', function (int $page, int $prevPage, int $nextPage, int $items = 10): void {
foreach (range(1, 35) as $i) {
$order = new FoodOrder($this->generateOldUlid());
$order->setFoodVendor($this->vendor);
$order->close();
$this->manager->persist($order);
}
$this->manager->flush();
$crawler = $this->client->request('GET', "{$this->path}list/archive/{$page}");
$this->assertResponseStatusCodeSame(200);
$this->assertPageTitleContains('FoodOrder index');
$this->assertElementContainsCount(
$crawler,
'td',
$items,
'nobody'
);
if ($prevPage > 0) {
$prevPage = $prevPage === 1 ? '' : "/{$prevPage}";
$node = $crawler->filter('a')
->reduce(static fn(Crawler $node, $i): bool => $node->text() === 'previous page')
->first();
$target = $node->attr('href');
$this->assertTrue(str_ends_with((string) $target, $prevPage));
}
if ($prevPage > 3) {
$node = $crawler->filter('a')
->reduce(static fn(Crawler $node, $i): bool => $node->text() === 'next page')
->first();
$target = $node->attr('href');
$this->assertTrue(str_ends_with((string) $target, "/{$nextPage}"));
}
})
->with(
[
[1, 0, 2],
[2, 1, 3],
[3, 2, 4],
[4, 3, 0, 5],
]
);
test('new', function (): void {
$this->client->getCookieJar()
->set(new Cookie('username', 'Testing-1'));
$this->client->request('GET', sprintf('%snew', $this->path));
$this->assertResponseStatusCodeSame(200);
$this->client->submitForm('Save', [
'food_order[foodVendor]' => $this->vendor->getId(),
]);
$this->assertResponseRedirects("{$this->path}list");
$this->assertSame(1, $this->repository->count([]));
$order = $this->repository->findOneBy([
'createdBy' => 'Testing-1',
]);
assert($order instanceof FoodOrder);
});
test('open', function (): void {
$order = new FoodOrder;
$order->setFoodVendor($this->vendor);
$order->close();
$this->assertTrue($order->isClosed());
$this->manager->persist($order);
$this->manager->flush();
$this->client->request('GET', sprintf('%s%s/open', $this->path, $order->getId()));
$this->assertResponseRedirects("{$this->path}{$order->getId()}");
$openOrder = $this->repository->find($order->getId());
$this->assertFalse($openOrder->isClosed());
});
test('close', function (): void {
$order = new FoodOrder;
$order->setClosedAt();
$order->setFoodVendor($this->vendor);
$this->assertFalse($order->isClosed());
$this->manager->persist($order);
$this->manager->flush();
$this->client->request('GET', sprintf('%s%s/close', $this->path, $order->getId()));
$this->assertResponseRedirects("{$this->path}{$order->getId()}");
$openOrder = $this->repository->find($order->getId());
$this->assertTrue($openOrder->isClosed());
});
})
->covers(
FoodOrderController::class,
FoodOrder::class,
FoodVendor::class,
FoodOrderRepository::class,
MenuItem::class,
OrderItem::class,
FoodOrderType::class,
FoodVendorRepository::class
);

View file

@ -0,0 +1,184 @@
<?php declare(strict_types=1);
namespace App\Tests\Feature\Controller;
use App\Controller\FoodVendorController;
use App\Entity\FoodOrder;
use App\Entity\FoodVendor;
use App\Entity\MenuItem;
use App\Entity\OrderItem;
use App\Form\FoodOrderType;
use App\Form\FoodVendorType;
use App\Repository\FoodOrderRepository;
use App\Repository\FoodVendorRepository;
use function describe;
use function pest;
use function sprintf;
use function test;
pest()
->beforeEach(function (): void {
$this->setEntityClass(FoodVendor::class);
$this->setPath('/food/vendor/');
$this->repository = $this->manager->getRepository($this->entityClass);
});
describe(FoodVendorController::class, function (): void {
test('index', function (): void {
$this->client->request('GET', $this->path);
$this->assertResponseStatusCodeSame(200);
$this->assertPageTitleContains('FoodVendor index');
});
test('new', function (): void {
$this->assertSame(0, $this->repository->count([]));
$this->client->request('GET', sprintf('%snew', $this->path));
$this->assertResponseStatusCodeSame(200);
$this->client->submitForm('Save', [
'food_vendor[name]' => 'TestingNew',
]);
$newVendor = $this->repository->findOneBy([
'name' => 'TestingNew',
]);
$this->assertInstanceof(FoodVendor::class, $newVendor);
$this->assertSame(1, $this->repository->count([]));
});
test('show', function (): void {
$fixture = new FoodVendor;
$fixture->setName('My Title');
$fixture->setMenuLink('https://example.com/');
$this->manager->persist($fixture);
$this->manager->flush();
$crawler = $this->client->request('GET', sprintf('%s%s', $this->path, $fixture->getId()));
$this->assertResponseIsSuccessful();
$nameNode = $crawler->filter('td')
->last();
$nameNode = $crawler->filter(
'.table > tbody:nth-child(1) > tr:nth-child(1) > td:nth-child(2)'
)->text();
$menuLinkNode = $crawler->filter(
'.table > tbody:nth-child(1) > tr:nth-child(2) > td:nth-child(2) > a:nth-child(1)'
)->text();
$this->assertSame('My Title', $nameNode);
$this->assertSame('https://example.com/', $menuLinkNode);
});
test('show with menu items', function (): void {
$fixture = new FoodVendor;
$fixture->setName('My Title');
$this->manager->persist($fixture);
$this->manager->flush();
$itemOne = new MenuItem;
$itemOne->setName('Item One');
$fixture->addMenuItem($itemOne);
$this->manager->persist($itemOne);
$itemTwo = new MenuItem;
$itemTwo->setName('Item Two');
$itemTwo->setFoodVendor($fixture);
$fixture->addMenuItem($itemTwo);
$this->manager->persist($itemTwo);
$itemThree = new MenuItem;
$itemThree->setName('Item Three');
$itemThree->setFoodVendor($fixture);
$fixture->addMenuItem($itemThree);
$this->manager->persist($itemThree);
$itemFour = new MenuItem;
$itemFour->setName('Item Four');
$itemFour->setFoodVendor($fixture);
$fixture->addMenuItem($itemFour);
$this->manager->persist($itemFour);
$this->manager->flush();
$crawler = $this->client->request('GET', sprintf('%s%s', $this->path, $fixture->getId()));
$this->assertResponseIsSuccessful();
$nameNode = $crawler->filter(
'.table > tbody:nth-child(1) > tr:nth-child(1) > td:nth-child(2)'
)->text();
$this->assertSame('My Title', $nameNode);
$itemNodes = $crawler->filter('li');
$this->assertCount(4, $itemNodes);
});
test('edit', function (): void {
$fixture = new FoodVendor;
$fixture->setName('Value');
$fixture->setMenuLink('Value');
$fixture->setPhone('Value');
$this->manager->persist($fixture);
$this->manager->flush();
$crawler = $this->client->request('GET', sprintf('%s%s/edit', $this->path, $fixture->getId()));
$this->assertSame(
$crawler->filter('#food_vendor_name')
->last()
->attr('value', ''),
'Value'
);
$this->assertSame(
$crawler->filter('#food_vendor_menuLink')
->last()
->attr('value', ''),
'Value'
);
$this->assertSame(
$crawler->filter('#food_vendor_phone')
->last()
->attr('value', ''),
'Value'
);
$this->client->submitForm('Update', [
'food_vendor[name]' => 'Something New',
'food_vendor[menuLink]' => 'https://example.com/',
'food_vendor[phone]' => '1234567890',
]);
$this->assertResponseRedirects('/food/vendor/');
$fixture = $this->repository->findAll();
$this->assertSame('Something New', $fixture[0]->getName());
$this->assertSame('https://example.com/', $fixture[0]->getMenuLink());
$this->assertSame('1234567890', $fixture[0]->getPhone());
});
})
->covers(
FoodOrder::class,
FoodVendor::class,
FoodOrderRepository::class,
MenuItem::class,
OrderItem::class,
FoodOrderType::class,
FoodVendorRepository::class,
FoodVendorController::class,
FoodVendorType::class
)
;

View file

@ -0,0 +1,71 @@
<?php declare(strict_types=1);
namespace App\Tests\Feature\Controller;
use App\Controller\HomeController;
use App\Form\UserNameFormType;
use function describe;
use function test;
describe(HomeController::class, function (): void {
test('index', function (): void {
$this->client->request(
'GET',
'/'
);
$this->assertResponseStatusCodeSame(302);
$this->assertResponseHeaderSame('Location', '/food/order/list');
});
test('username', function (): void {
$this->client->request(
'GET',
'/username',
);
$this->assertResponseStatusCodeSame(200);
$this->client->submitForm('Save', [
'user_name_form[username]' => 'Testing-1',
]);
$this->assertResponseStatusCodeSame(302);
$this->assertResponseHeaderSame('Location', '/food/order/list');
$this->assertResponseCookieValueSame('username', 'Testing-1');
$crawler = $this->client->request(
'GET',
'/username',
);
$this->assertResponseStatusCodeSame(200);
$this->assertSame(
$crawler->filter('#user_name_form_username')
->last()
->attr('value', ''),
'Testing-1'
);
});
test('username empty', function (): void {
$this->client->request(
'GET',
'/username',
);
$this->assertResponseStatusCodeSame(200);
$this->client->submitForm('Save', [
'user_name_form[username]' => '',
]);
$this->assertResponseStatusCodeSame(302);
$this->assertResponseHeaderSame('Location', '/food/order/list');
$this->assertResponseCookieValueSame('username', '');
});
})
->covers(HomeController::class, UserNameFormType::class);

View file

@ -0,0 +1,159 @@
<?php declare(strict_types=1);
namespace App\Tests\Feature\Controller;
use App\Controller\MenuItemController;
use App\Controller\OrderItemController;
use App\Entity\FoodOrder;
use App\Entity\FoodVendor;
use App\Entity\MenuItem;
use App\Entity\OrderItem;
use App\Form\MenuItemType;
use App\Form\OrderItemType;
use App\Repository\FoodOrderRepository;
use App\Repository\MenuItemRepository;
use function describe;
use function pest;
use function sprintf;
use function test;
pest()
->beforeEach(function (): void {
$this->setEntityClass(MenuItem::class);
$this->setPath('/menu/item/');
$this->repository = $this->manager->getRepository($this->entityClass);
$this->vendor = new FoodVendor;
$this->vendor->setName('Food Vendor');
$this->manager->persist($this->vendor);
$this->menuItem = new MenuItem;
$this->menuItem->setName('Testing 1 2');
$this->vendor->addMenuItem($this->menuItem);
$this->manager->persist($this->vendor);
$this->manager->persist($this->menuItem);
$this->aliasOne = new MenuItem;
$this->aliasOne->setName('AliasOne');
$this->aliasOne->setFoodVendor($this->vendor);
$this->menuItem->addAlias($this->aliasOne);
$this->aliasTwo = new MenuItem;
$this->aliasTwo->setName('AliasTwo');
$this->aliasTwo->setFoodVendor($this->vendor);
$this->aliasTwo->setAliasOf($this->menuItem);
$this->menuItem->addAlias($this->aliasTwo);
$this->manager->persist($this->aliasOne);
$this->manager->persist($this->aliasTwo);
$this->manager->persist($this->menuItem);
$this->manager->flush();
});
describe(MenuItemController::class, function (): void {
test('show', function (): void {
$crawler = $this->client->request('GET', "{$this->path}{$this->menuItem->getId()}");
$idValue = $crawler->filter(
'.table > tbody:nth-child(1) > tr:nth-child(1) > td:nth-child(2)'
)->text();
$nameValue = $crawler->filter(
'.table > tbody:nth-child(1) > tr:nth-child(2) > td:nth-child(2)'
)->text();
$aliasTwoNameValue = $crawler->filter(
'.table > tbody:nth-child(1) > tr:nth-child(3) > td:nth-child(2) > ul:nth-child(1) > li:nth-child(1)'
)->text();
$aliasOneNameValue = $crawler->filter(
'.table > tbody:nth-child(1) > tr:nth-child(3) > td:nth-child(2) > ul:nth-child(1) > li:nth-child(2)'
)->text();
$this->assertResponseStatusCodeSame(200);
$this->assertEquals($idValue, $this->menuItem->getId());
$this->assertEquals($nameValue, $this->menuItem->getName());
$this->assertEquals($aliasTwoNameValue, $this->aliasOne->getName());
$this->assertEquals($aliasOneNameValue, $this->aliasTwo->getName());
});
test('edit', function (): void {
$crawler = $this->client->request('GET', sprintf('%s%s/edit', $this->path, $this->menuItem->getId()));
$nameElem = $crawler->filter('#menu_item_name');
$this->assertEquals(
'Testing 1 2',
$nameElem->attr('value')
);
$form = $crawler->selectButton('Update')
->form();
$form['menu_item[name]'] = 'Testing-1';
$form['menu_item[aliases]'][0]->untick();
$this->client->submit($form);
$this->assertResponseRedirects(sprintf('/menu/item/%s', $this->menuItem->getId()));
$menuItem = $this->repository->find($this->menuItem->getId());
$this->assertEquals('Testing-1', $menuItem->getName());
$this->assertEquals(1, $menuItem->getAliases()->count());
$aliasOne = $this->repository->find($this->aliasOne->getId());
$this->assertNull($aliasOne->getAliasOf());
});
test('edit invalid', function (): void {
$crawler = $this->client->request('GET', sprintf('%s%s/edit', $this->path, $this->menuItem->getId()));
$nameElem = $crawler->filter('#menu_item_name');
$this->assertEquals(
'Testing 1 2',
$nameElem->attr('value')
);
$form = $crawler->selectButton('Update')
->form();
$form['menu_item[name]'] = 'a';
$this->client->submit($form);
$this->assertResponseStatusCodeSame(422);
});
test('delete', function (): void {
$order = new FoodOrder;
$order->setFoodVendor($this->vendor);
$this->manager->persist($order);
$this->manager->flush();
$this->assertFalse($this->menuItem->isDeleted());
$this->client->request('GET', "{$this->path}{$this->menuItem->getId()}");
$this->client->submitForm('Delete', []);
$menuItem = $this->repository->find($this->menuItem->getId());
$this->assertTrue($menuItem->isDeleted());
$crawler = $this->client->request('GET', '/order/item/new/' . $order->getId());
$count = $crawler->filter('body > main:nth-child(2) > div:nth-child(5)')
->children()
->count();
$this->assertSame(2, $count);
$this->assertResponseIsSuccessful();
});
})
->covers(
MenuItemController::class,
OrderItemController::class,
OrderItemType::class,
MenuItemRepository::class,
FoodOrder::class,
FoodVendor::class,
MenuItem::class,
OrderItem::class,
FoodOrderRepository::class,
MenuItemType::class,
);

View file

@ -0,0 +1,261 @@
<?php declare(strict_types=1);
namespace App\Tests\Feature\Controller;
use App\Controller\OrderItemController;
use App\Entity\FoodOrder;
use App\Entity\FoodVendor;
use App\Entity\MenuItem;
use App\Entity\OrderItem;
use App\Form\OrderItemType;
use App\Repository\FoodOrderRepository;
use App\Repository\MenuItemRepository;
use App\Repository\OrderItemRepository;
use DateTimeImmutable;
use function describe;
use function pest;
use function sprintf;
use function test;
pest()
->beforeEach(function (): void {
$this->setEntityClass(OrderItem::class);
$this->setPath('/order/item/');
$this->repository = $this->manager->getRepository($this->entityClass);
$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->menuItem = new MenuItem;
$this->menuItem->setName('Testing');
$this->menuItem->setFoodVendor($this->vendor);
$vendor2 = new FoodVendor;
$vendor2->setName('Vendor 2');
$menuItem2 = new MenuItem;
$menuItem2->setName('Testing2');
$menuItem2->setFoodVendor($vendor2);
$this->manager->persist($vendor2);
$this->manager->persist($menuItem2);
$this->manager->persist($this->menuItem);
$this->manager->flush();
$this->menuItemRepository = $this::getContainer()->get(MenuItemRepository::class);
});
describe(OrderItemController::class, function (): void {
test('new', function (): void {
$crawler = $this->client->request(
'GET',
sprintf('%snew/%s', $this->path, $this->order->getId())
);
$children = $crawler->filter('body > main:nth-child(2) > div:nth-child(5)')
->children();
$this->assertCount(1, $children);
$this->assertResponseStatusCodeSame(200);
$this->client->submitForm('Save', [
'order_item[name]' => 'Testing',
'order_item[extras]' => 'Testing',
]);
$this->assertResponseRedirects(sprintf('/food/order/%s', $this->order->getId()));
$this->assertSame(1, $this->repository->count([]));
$this->assertSame(1, $this->menuItemRepository->count([
'foodVendor' => $this->vendor->getId(),
]));
});
test('new order closed', function (): void {
$this->order->setClosedAt(new DateTimeImmutable('-1 Hour'));
$this->manager->persist($this->order);
$this->manager->flush();
$this->client->request(
'GET',
sprintf('%snew/%s', $this->path, $this->order->getId())
);
$this->assertResponseRedirects(sprintf('/food/order/%s', $this->order->getId()));
$this->assertSame(0, $this->repository->count([]));
});
test('new create menu item', function (): void {
$this->client->request(
'GET',
sprintf('%snew/%s', $this->path, $this->order->getId())
);
$this->assertResponseStatusCodeSame(200);
$this->client->submitForm('Save', [
'order_item[name]' => 'Testing-1',
'order_item[extras]' => 'Testing-1',
]);
$this->assertResponseRedirects(sprintf('/food/order/%s', $this->order->getId()));
$this->assertSame(1, $this->repository->count([]));
$this->assertSame(3, $this->menuItemRepository->count([]));
});
test('remove', function (): void {
$fixture = new OrderItem;
$fixture->setName('Testing');
$fixture->setExtras('Value');
$fixture->setMenuItem($this->menuItem);
$fixture->setFoodOrder($this->order);
$this->manager->persist($fixture);
$this->manager->flush();
$this->client->request('GET', sprintf('%sdelete/%s', $this->path, $fixture->getId()));
$this->assertResponseRedirects(sprintf('/food/order/%s', $this->order->getId()));
$this->assertSame(0, $this->repository->count([]));
});
test('order closed', function (): void {
$fixture = new OrderItem;
$fixture->setName('Testing');
$fixture->setExtras('Value');
$fixture->setMenuItem($this->menuItem);
$fixture->setFoodOrder($this->order);
$this->order->close();
$this->manager->persist($this->order);
$this->manager->persist($fixture);
$this->manager->flush();
$this->client->request('GET', sprintf('%sdelete/%s', $this->path, $fixture->getId()));
$this->assertResponseRedirects(sprintf('/food/order/%s', $this->order->getId()));
$this->assertSame(1, $this->repository->count([]));
});
test('edit', function (): void {
$orderItem = new OrderItem;
$orderItem->setName('Testing');
$orderItem->setExtras('My Extra');
$orderItem->setFoodOrder($this->order);
$orderItem->setMenuItem($this->menuItem);
$this->manager->persist($orderItem);
$this->manager->flush();
$crawler = $this->client->request('GET', sprintf('%s%s/edit', $this->path, $orderItem->getId()));
$nameElem = $crawler->filter('#order_item_name');
$extrasElem = $crawler->filter('#order_item_extras');
$this->assertEquals(
'Testing',
$nameElem->attr('value')
);
$this->assertEquals(
'My Extra',
$extrasElem->attr('value')
);
$this->client->submitForm('Update', [
'order_item[name]' => 'Testing-1',
'order_item[extras]' => 'Testing-1',
]);
$this->assertResponseRedirects(sprintf('/food/order/%s', $this->order->getId()));
$this->assertSame(1, $this->repository->count([]));
$this->assertSame(3, $this->menuItemRepository->count([]));
});
test('edit order closed', function (): void {
$orderItem = new OrderItem;
$orderItem->setName('Testing');
$orderItem->setExtras('My Extra');
$orderItem->setFoodOrder($this->order);
$orderItem->setMenuItem($this->menuItem);
$this->order->close();
$this->manager->persist($orderItem);
$this->manager->persist($this->order);
$this->manager->flush();
$this->client->request('GET', sprintf('%s%s/edit', $this->path, $orderItem->getId()));
$this->assertResponseRedirects(sprintf('/food/order/%s', $this->order->getId()));
});
test('copy', function (): void {
$orderItem = new OrderItem;
$orderItem->setName('My Title');
$orderItem->setExtras('My Title');
$orderItem->setFoodOrder($this->order);
$orderItem->setMenuItem($this->menuItem);
$this->manager->persist($orderItem);
$this->manager->flush();
$this->client->request('GET', sprintf('%s%s/copy', $this->path, $orderItem->getId()));
$this->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());
}
});
test('copy order closed', function (): void {
$orderItem = new OrderItem;
$orderItem->setName('My Title');
$orderItem->setExtras('My Title');
$orderItem->setFoodOrder($this->order);
$orderItem->setMenuItem($this->menuItem);
$this->order->close();
$this->manager->persist($this->order);
$this->manager->persist($orderItem);
$this->manager->flush();
$this->client->request('GET', sprintf('%s%s/copy', $this->path, $orderItem->getId()));
$this->assertResponseRedirects(sprintf('/food/order/%s', $this->order->getId()));
$result = $this->repository->findBy([
'foodOrder' => $this->order->getId(),
]);
$this->assertCount(1, $result);
});
})
->covers(
OrderItemController::class,
MenuItemRepository::class,
OrderItemRepository::class,
OrderItemType::class,
FoodOrder::class,
FoodVendor::class,
MenuItem::class,
OrderItem::class,
FoodOrderRepository::class,
);