improve coverage, remove infection
All checks were successful
/ ls (pull_request) Successful in 1m30s
All checks were successful
/ ls (pull_request) Successful in 1m30s
This commit is contained in:
parent
eaa723a58b
commit
0aa25d107b
10 changed files with 160 additions and 1317 deletions
|
@ -9,6 +9,7 @@ use Override;
|
|||
|
||||
use function sprintf;
|
||||
|
||||
|
||||
final class FoodVendorControllerTest extends DbWebTest
|
||||
{
|
||||
private string $path = '/food/vendor/';
|
||||
|
@ -23,15 +24,20 @@ final class FoodVendorControllerTest extends DbWebTest
|
|||
|
||||
public function testNew(): void
|
||||
{
|
||||
self::assertSame(0, $this->repository->count([]));
|
||||
$this->client->request('GET', sprintf('%snew', $this->path));
|
||||
|
||||
self::assertResponseStatusCodeSame(200);
|
||||
|
||||
$this->client->submitForm('Save', [
|
||||
'food_vendor[name]' => 'Testing',
|
||||
'food_vendor[name]' => 'TestingNew',
|
||||
]);
|
||||
|
||||
$newVendor = $this->repository->findOneBy(['name' => 'TestingNew']);
|
||||
$this->assertInstanceof(FoodVendor::class, $newVendor);
|
||||
self::assertSame(1, $this->repository->count([]));
|
||||
|
||||
|
||||
}
|
||||
|
||||
public function testShow(): void
|
||||
|
|
|
@ -14,6 +14,9 @@ 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
|
||||
|
@ -23,7 +26,30 @@ final class MenuItemControllerTest extends DbWebTest
|
|||
$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]
|
||||
|
@ -34,70 +60,82 @@ final class MenuItemControllerTest extends DbWebTest
|
|||
|
||||
public function testShow(): void
|
||||
{
|
||||
$menuItem = new MenuItem;
|
||||
$menuItem->setName('Testing 1 2');
|
||||
|
||||
$this->vendor->addMenuItem($menuItem);
|
||||
$this->manager->persist($this->vendor);
|
||||
$this->manager->persist($menuItem);
|
||||
$this->manager->flush();
|
||||
|
||||
$crawler = $this->client->request('GET', "{$this->path}{$menuItem->getId()}");
|
||||
$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, $menuItem->getId());
|
||||
$this->assertEquals($nameValue, $menuItem->getName());
|
||||
$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
|
||||
{
|
||||
$menuItem = new MenuItem;
|
||||
$menuItem->setName('Testing 1 2');
|
||||
|
||||
$this->vendor->addMenuItem($menuItem);
|
||||
$this->manager->persist($this->vendor);
|
||||
$this->manager->persist($menuItem);
|
||||
$this->manager->flush();
|
||||
|
||||
$crawler = $this->client->request('GET', sprintf('%s%s/edit', $this->path, $menuItem->getId()));
|
||||
$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')
|
||||
);
|
||||
|
||||
$this->client->submitForm('Update', [
|
||||
'menu_item[name]' => 'Testing-1',
|
||||
]);
|
||||
$form = $crawler->selectButton('Update')->form();
|
||||
$form['menu_item[name]'] = 'Testing-1';
|
||||
$form['menu_item[aliases]'][0]->untick();
|
||||
|
||||
self::assertResponseRedirects(sprintf('/menu/item/%s', $menuItem->getId()));
|
||||
$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
|
||||
{
|
||||
$menuItem = new MenuItem;
|
||||
$menuItem->setName('Testing 1 2');
|
||||
|
||||
$this->vendor->addMenuItem($menuItem);
|
||||
$this->manager->persist($this->vendor);
|
||||
$this->manager->persist($menuItem);
|
||||
|
||||
$order = new FoodOrder;
|
||||
$order->setFoodVendor($this->vendor);
|
||||
|
||||
$this->manager->persist($order);
|
||||
$this->manager->flush();
|
||||
$this->assertFalse($menuItem->isDeleted());
|
||||
$this->assertFalse($this->menuItem->isDeleted());
|
||||
|
||||
$this->client->request('GET', "{$this->path}{$menuItem->getId()}");
|
||||
$this->client->request('GET', "{$this->path}{$this->menuItem->getId()}");
|
||||
$this->client->submitForm('Delete', []);
|
||||
|
||||
$menuItem = $this->repository->find($menuItem->getId());
|
||||
$menuItem = $this->repository->find($this->menuItem->getId());
|
||||
|
||||
$this->assertTrue($menuItem->isDeleted());
|
||||
|
||||
|
@ -105,7 +143,7 @@ final class MenuItemControllerTest extends DbWebTest
|
|||
$count = $crawler->filter('body > main:nth-child(2) > div:nth-child(5)')
|
||||
->children()
|
||||
->count();
|
||||
$this->assertSame(0, $count);
|
||||
$this->assertSame(2, $count);
|
||||
|
||||
$this->assertResponseIsSuccessful();
|
||||
|
||||
|
|
|
@ -27,4 +27,29 @@ final class MenuItemTest extends TestCase
|
|||
$this->assertTrue($item->isDeleted());
|
||||
$this->assertInstanceOf(DateTimeImmutable::class, $item->getDeletedAt());
|
||||
}
|
||||
|
||||
public function testMenuItemAlias(): void
|
||||
{
|
||||
$item = new MenuItem;
|
||||
$item->setName('Test');
|
||||
$this->assertEquals('Test', $item->getName());
|
||||
|
||||
$vendor = new FoodVendor;
|
||||
$vendor->setName('Test');
|
||||
$item->setFoodVendor($vendor);
|
||||
|
||||
$item2 = new MenuItem;
|
||||
$item2->setName('Test2');
|
||||
$item2->setFoodVendor($vendor);
|
||||
|
||||
$item->addAlias($item2);
|
||||
|
||||
$this->assertCount(1, $item->getAliases());
|
||||
$this->assertSame($item, $item2->getAliasOf());
|
||||
|
||||
$item->removeAlias($item2);
|
||||
$this->assertCount(0, $item->getAliases());
|
||||
$this->assertNull($item2->getAliasOf());
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue