migrate test cases to use pestphp syntax
This commit is contained in:
parent
af9354ff22
commit
9c98735db7
14 changed files with 365 additions and 415 deletions
|
@ -1,172 +0,0 @@
|
|||
<?php declare(strict_types=1);
|
||||
|
||||
namespace App\Tests\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 App\Tests\DbWebTest;
|
||||
use Override;
|
||||
use PHPUnit\Framework\Attributes\CoversClass;
|
||||
|
||||
use function sprintf;
|
||||
|
||||
#[CoversClass(MenuItemController::class)]
|
||||
#[CoversClass(OrderItemController::class)]
|
||||
#[CoversClass(OrderItemType::class)]
|
||||
#[CoversClass(MenuItemRepository::class)]
|
||||
#[CoversClass(FoodOrder::class)]
|
||||
#[CoversClass(FoodVendor::class)]
|
||||
#[CoversClass(MenuItem::class)]
|
||||
#[CoversClass(OrderItem::class)]
|
||||
#[CoversClass(FoodOrderRepository::class)]
|
||||
#[CoversClass(MenuItemType::class)]
|
||||
final class MenuItemControllerTest extends DbWebTest
|
||||
{
|
||||
private string $path = '/menu/item/';
|
||||
private FoodVendor $vendor;
|
||||
private MenuItem $menuItem;
|
||||
private MenuItem $aliasOne;
|
||||
private MenuItem $aliasTwo;
|
||||
|
||||
#[Override]
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$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();
|
||||
|
||||
}
|
||||
|
||||
#[Override]
|
||||
public function getEntityClass(): string
|
||||
{
|
||||
return MenuItem::class;
|
||||
}
|
||||
|
||||
public function testShow(): 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();
|
||||
self::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());
|
||||
}
|
||||
|
||||
public function testEdit(): 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);
|
||||
|
||||
self::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());
|
||||
}
|
||||
|
||||
public function testEditInvalid(): 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);
|
||||
|
||||
self::assertResponseStatusCodeSame(422);
|
||||
}
|
||||
|
||||
public function testDelete(): 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();
|
||||
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue