/** * @covers CodeCollab\Router\Router::__construct * @covers CodeCollab\Router\Router::addRoute * @covers CodeCollab\Router\Router::get * @covers CodeCollab\Router\Router::buildCache * @covers CodeCollab\Router\Router::getDispatcher */ public function testGetDispatcherExistingFileDoReload() { $routeCollector = $this->createMock(RouteCollector::class); $routeCollector->method('getData')->willReturn(['foo' => 'bar']); $router = new Router($routeCollector, function ($data) { \PHPUnit_Framework_Assert::assertSame(['foo' => 'bar'], $data); return $this->createMock(Dispatcher::class); }, TEST_DATA_DIR . '/cache/routes.php', true); $this->assertFalse(file_exists(TEST_DATA_DIR . '/cache/routes.php')); copy(TEST_DATA_DIR . '/routes.php', TEST_DATA_DIR . '/cache/routes.php'); $this->assertTrue(file_exists(TEST_DATA_DIR . '/cache/routes.php')); $this->assertInstanceOf(Dispatcher::class, $router->get('/', [])->getDispatcher()); $this->assertTrue(file_exists(TEST_DATA_DIR . '/cache/routes.php')); $routes = (require TEST_DATA_DIR . '/cache/routes.php'); $this->assertSame(['foo' => 'bar'], $routes); }
/** * @covers CodeCollab\Router\Router::__construct * @covers CodeCollab\Router\Router::addRoute * @covers CodeCollab\Router\Router::get * @covers CodeCollab\Router\Router::buildCache * @covers CodeCollab\Router\Router::getDispatcher */ public function testGetDispatcherExistingFileDoReload() { $routeCollector = $this->getMockBuilder('FastRoute\\RouteCollector')->disableOriginalConstructor()->getMock(); $routeCollector->method('getData')->willReturn(['foo' => 'bar']); $router = new Router($routeCollector, function ($data) { \PHPUnit_Framework_Assert::assertSame(['foo' => 'bar'], $data); return $this->getMock('FastRoute\\Dispatcher'); }, TEST_DATA_DIR . '/cache/routes.php', true); $this->assertFalse(file_exists(TEST_DATA_DIR . '/cache/routes.php')); copy(TEST_DATA_DIR . '/routes.php', TEST_DATA_DIR . '/cache/routes.php'); $this->assertTrue(file_exists(TEST_DATA_DIR . '/cache/routes.php')); $this->assertInstanceOf('FastRoute\\Dispatcher', $router->get('/', [])->getDispatcher()); $this->assertTrue(file_exists(TEST_DATA_DIR . '/cache/routes.php')); $routes = (require TEST_DATA_DIR . '/cache/routes.php'); $this->assertSame(['foo' => 'bar'], $routes); }