1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70:
<?php
declare(strict_types=1);
namespace Test\Router;
use App\Router\RouterFactory;
use Nette\Application\Routers\Route;
use Nette\Application\Routers\RouteList;
use Nette\DI\Container;
use Tester\Assert;
use Tester\TestCase;
$container = require __DIR__ . '/../bootstrap.php';
class RouterFactoryTest extends TestCase {
private $container;
public function __construct(Container $container) {
$this->container = $container;
}
public function testCreateRouter() {
$routeList = RouterFactory::createRouter();
$expected = [
['Cloud:' => '[<lang [a-z]{2}>/]cloud/<presenter>/<action>[/<id>]'],
['Config:' => '[<lang [a-z]{2}>/]config/<presenter>/<action>[/<id>]'],
['Gateway:' => '[<lang [a-z]{2}>/]gateway/<presenter>/<action>'],
['IqrfApp:' => '[<lang [a-z]{2}>/]iqrfnet/<presenter>/<action>'],
['Service:' => '[<lang [a-z]{2}>/]service/<presenter>/<action>'],
'[<lang [a-z]{2}>/]<presenter>/<action>[/<id>]',
];
Assert::type(RouteList::class, $routeList);
Assert::same('', $routeList->getModule());
Assert::same($expected, array_map(function ($type) {
if ($type instanceof Route) {
return $type->getMask();
} elseif ($type instanceof RouteList) {
return [$type->getModule() => array_map(function ($route) {
return $route->getMask();
}, (array) $type->getIterator())[0]];
}
}, (array) $routeList->getIterator()));
}
}
$test = new RouterFactoryTest($container);
$test->run();