100% test coverage
This commit is contained in:
parent
2a28465626
commit
34171d6c2b
8 changed files with 214 additions and 16 deletions
98
tests/Controller/MenuItemControllerTest.php
Normal file
98
tests/Controller/MenuItemControllerTest.php
Normal file
|
@ -0,0 +1,98 @@
|
|||
<?php declare(strict_types=1);
|
||||
|
||||
namespace App\Tests\Controller;
|
||||
|
||||
use App\Entity\FoodVendor;
|
||||
use App\Entity\MenuItem;
|
||||
use App\Tests\DbWebTest;
|
||||
use Override;
|
||||
|
||||
use function sprintf;
|
||||
|
||||
final class MenuItemControllerTest extends DbWebTest
|
||||
{
|
||||
private string $path = '/menu/item/';
|
||||
private FoodVendor $vendor;
|
||||
|
||||
#[Override]
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->vendor = new FoodVendor;
|
||||
$this->vendor->setName('Food Vendor');
|
||||
|
||||
$this->manager->persist($this->vendor);
|
||||
$this->manager->flush();
|
||||
}
|
||||
|
||||
#[Override]
|
||||
public function getEntityClass(): string
|
||||
{
|
||||
return MenuItem::class;
|
||||
}
|
||||
|
||||
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()}");
|
||||
$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();
|
||||
self::assertResponseStatusCodeSame(200);
|
||||
$this->assertEquals($idValue, $menuItem->getId());
|
||||
$this->assertEquals($nameValue, $menuItem->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()));
|
||||
$nameElem = $crawler->filter('#menu_item_name');
|
||||
$this->assertEquals(
|
||||
'Testing 1 2',
|
||||
$nameElem->attr('value')
|
||||
);
|
||||
|
||||
$this->client->submitForm('Update', [
|
||||
'menu_item[name]' => 'Testing-1',
|
||||
]);
|
||||
|
||||
self::assertResponseRedirects(sprintf('/menu/item/%s', $menuItem->getId()));
|
||||
}
|
||||
|
||||
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);
|
||||
$this->manager->flush();
|
||||
$this->assertFalse($menuItem->isDeleted());
|
||||
|
||||
$this->client->request('GET', "{$this->path}{$menuItem->getId()}");
|
||||
$this->client->submitForm('Delete', []);
|
||||
|
||||
$menuItem = $this->repository->find($menuItem->getId());
|
||||
|
||||
$this->assertTrue($menuItem->isDeleted());
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue