#29_improve-tests #36
2 changed files with 72 additions and 1 deletions
69
tests/Controller/HomeControllerTest.php
Normal file
69
tests/Controller/HomeControllerTest.php
Normal file
|
@ -0,0 +1,69 @@
|
||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Tests\Controller;
|
||||||
|
|
||||||
|
use App\Entity\FoodOrder;
|
||||||
|
use App\Entity\FoodVendor;
|
||||||
|
use App\Entity\MenuItem;
|
||||||
|
use App\Entity\OrderItem;
|
||||||
|
use App\Repository\MenuItemRepository;
|
||||||
|
use App\Tests\DbWebTest;
|
||||||
|
use Override;
|
||||||
|
|
||||||
|
use function sprintf;
|
||||||
|
|
||||||
|
final class HomeControllerTest extends DbWebTest
|
||||||
|
{
|
||||||
|
public function testIndex(): void
|
||||||
|
{
|
||||||
|
$this->client->request(
|
||||||
|
'GET',
|
||||||
|
'/'
|
||||||
|
);
|
||||||
|
|
||||||
|
self::assertResponseStatusCodeSame(302);
|
||||||
|
self::assertResponseHeaderSame('Location', '/food/order/list');
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSetUsername(): void
|
||||||
|
{
|
||||||
|
$this->client->request(
|
||||||
|
'GET',
|
||||||
|
'/username',
|
||||||
|
);
|
||||||
|
|
||||||
|
self::assertResponseStatusCodeSame(200);
|
||||||
|
|
||||||
|
$this->client->submitForm('Save', [
|
||||||
|
'user_name_form[username]' => 'Testing-1',
|
||||||
|
]);
|
||||||
|
self::assertResponseStatusCodeSame(302);
|
||||||
|
self::assertResponseHeaderSame('Location', '/food/order/list');
|
||||||
|
self::assertResponseCookieValueSame('username', 'Testing-1');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function testRemoveUsername(): void
|
||||||
|
{
|
||||||
|
$this->client->request(
|
||||||
|
'GET',
|
||||||
|
'/username',
|
||||||
|
);
|
||||||
|
|
||||||
|
self::assertResponseStatusCodeSame(200);
|
||||||
|
|
||||||
|
$this->client->submitForm('Save', [
|
||||||
|
'user_name_form[username]' => '',
|
||||||
|
]);
|
||||||
|
self::assertResponseStatusCodeSame(302);
|
||||||
|
self::assertResponseHeaderSame('Location', '/food/order/list');
|
||||||
|
self::assertResponseCookieValueSame('username', '');
|
||||||
|
}
|
||||||
|
|
||||||
|
#[Override]
|
||||||
|
public function getEntityClass(): string
|
||||||
|
{
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
}
|
|
@ -28,6 +28,8 @@ abstract class DbWebTest extends WebTestCase
|
||||||
$schemaTool->dropDatabase();
|
$schemaTool->dropDatabase();
|
||||||
$schemaTool->updateSchema($metadata);
|
$schemaTool->updateSchema($metadata);
|
||||||
|
|
||||||
$this->repository = $this->manager->getRepository($this->getEntityClass());
|
if ($this->getEntityClass() !== '') {
|
||||||
|
$this->repository = $this->manager->getRepository($this->getEntityClass());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue