infinito/application/symfony/tests/Integration/Controller/RoutesReachableIntegrationTest.php

79 lines
2.3 KiB
PHP
Raw Normal View History

2019-01-05 16:41:21 +01:00
<?php
2019-01-05 21:26:36 +01:00
namespace Tests\Integration\Controller;
2019-01-05 16:41:21 +01:00
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use App\DBAL\Types\LanguageType;
2019-01-05 17:27:40 +01:00
use App\DBAL\Types\Meta\Right\LayerType;
2019-01-05 16:41:21 +01:00
use App\DBAL\Types\RESTResponseType;
use Symfony\Component\HttpFoundation\Request;
2019-01-05 16:41:21 +01:00
/**
* @author kevinfrantz
*
* @todo Implement more tests for success etc.
*/
2019-01-05 21:26:36 +01:00
class RoutesReachableIntegrationTest extends KernelTestCase
2019-01-05 16:41:21 +01:00
{
public function setUp(): void
{
self::bootKernel();
}
2019-01-05 21:26:36 +01:00
public function testAllRoutePossibilities()
2019-01-05 16:41:21 +01:00
{
foreach (LayerType::getChoices() as $layer => $layerDescription) {
$this->controller($layer);
}
}
private function controller(string $entity)
{
2019-01-05 19:03:08 +01:00
$this->language($entity, Request::METHOD_GET);
$this->language($entity, Request::METHOD_POST);
$this->language($entity.'s', Request::METHOD_GET);
$this->slugAndId($entity, Request::METHOD_PUT);
$this->slugAndId($entity, Request::METHOD_GET);
$this->slugAndId($entity, Request::METHOD_DELETE);
2019-01-05 16:41:21 +01:00
}
private function slugAndId(string $route, string $method): void
{
$this->language("$route/12345", $method);
$this->language("$route/asdfg", $method);
2019-01-05 16:41:21 +01:00
}
2019-01-05 18:39:32 +01:00
/**
* @todo Implement routing without i18l part!
*
* @param string $entity
* @param string $method
*/
2019-01-05 16:41:21 +01:00
private function language(string $entity, string $method): void
{
2019-01-05 18:39:32 +01:00
//$this->type('api/'.$entity, $method);
2019-01-05 21:26:36 +01:00
foreach (LanguageType::getChoices() as $language) {
2019-01-05 18:39:32 +01:00
$this->type("$language/api/$entity", $method);
2019-01-05 21:26:36 +01:00
$this->type("$language/html/$entity", $method);
2019-01-05 16:41:21 +01:00
}
}
private function type(string $route, string $method): void
{
$this->routeAssert($route, $method);
foreach (RESTResponseType::getChoices() as $restResponseType => $value) {
$this->routeAssert("$route.$restResponseType", $method);
}
}
private function routeAssert(string $url, string $method): void
2019-01-05 16:41:21 +01:00
{
$request = new Request([], [], [], [], [], [
2019-01-05 16:41:21 +01:00
'REQUEST_URI' => $url,
]);
2019-01-05 18:39:32 +01:00
$request->setMethod($method);
2019-01-05 16:41:21 +01:00
$response = static::$kernel->handle($request);
2019-01-05 18:39:32 +01:00
$this->assertNotEquals(404, $response->getStatusCode(), "Route $url with Method $method sends an 404 response!");
2019-01-05 16:41:21 +01:00
}
}