first commit
This commit is contained in:
73
tests/Kernel/RoutesTest.php
Normal file
73
tests/Kernel/RoutesTest.php
Normal file
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Kernel;
|
||||
|
||||
use Netig\Netslim\Kernel\Runtime\Module\ModuleRegistry;
|
||||
use Netig\Netslim\Kernel\Runtime\Routing\Routes;
|
||||
use Netig\Netslim\Kernel\Runtime\RuntimePaths;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Slim\Factory\AppFactory;
|
||||
|
||||
#[\PHPUnit\Framework\Attributes\AllowMockObjectsWithoutExpectations]
|
||||
final class RoutesTest extends TestCase
|
||||
{
|
||||
protected function setUp(): void
|
||||
{
|
||||
RuntimePaths::setApplicationRoot(dirname(__DIR__, 2) . '/tests/Fixtures/Application');
|
||||
ModuleRegistry::reset();
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
RuntimePaths::resetApplicationRoot();
|
||||
RuntimePaths::resetProjectRoot();
|
||||
ModuleRegistry::reset();
|
||||
}
|
||||
|
||||
public function testRegisterDeclaresOnlyCoreModuleRoutesForFixtureApplication(): void
|
||||
{
|
||||
$app = AppFactory::create();
|
||||
Routes::register($app);
|
||||
|
||||
$actual = [];
|
||||
|
||||
foreach ($app->getRouteCollector()->getRoutes() as $route) {
|
||||
$pattern = $route->getPattern();
|
||||
$methods = array_values(array_diff($route->getMethods(), ['HEAD', 'OPTIONS']));
|
||||
|
||||
$actual[$pattern] ??= [];
|
||||
$actual[$pattern] = array_values(array_unique(array_merge($actual[$pattern], $methods)));
|
||||
sort($actual[$pattern]);
|
||||
}
|
||||
|
||||
ksort($actual);
|
||||
|
||||
$expected = [
|
||||
'/account/password' => ['GET', 'POST'],
|
||||
'/admin/categories' => ['GET'],
|
||||
'/admin/categories/create' => ['POST'],
|
||||
'/admin/categories/delete/{id}' => ['POST'],
|
||||
'/admin/media' => ['GET'],
|
||||
'/admin/media/delete/{id}' => ['POST'],
|
||||
'/admin/media/picker' => ['GET'],
|
||||
'/admin/media/upload' => ['POST'],
|
||||
'/admin/users' => ['GET'],
|
||||
'/admin/users/create' => ['GET', 'POST'],
|
||||
'/admin/users/delete/{id}' => ['POST'],
|
||||
'/admin/users/role/{id}' => ['POST'],
|
||||
'/auth/login' => ['GET', 'POST'],
|
||||
'/auth/logout' => ['POST'],
|
||||
'/password/forgot' => ['GET', 'POST'],
|
||||
'/password/reset' => ['GET', 'POST'],
|
||||
];
|
||||
|
||||
foreach ($expected as $pattern => $methods) {
|
||||
sort($methods);
|
||||
}
|
||||
ksort($expected);
|
||||
|
||||
self::assertSame($expected, $actual);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user