/** * @covers OpCacheGUI\Network\Router::__construct * @covers OpCacheGUI\Network\Router::post * @covers OpCacheGUI\Network\Router::run * @covers OpCacheGUI\Network\Router::getIdentifier */ public function testRunMatchesLast() { $requestMock = $this->getMock('\\OpCacheGUI\\Network\\RequestData'); $requestMock->method('getVerb')->willReturn('POST'); $requestMock->method('path')->willReturn('somepath'); $routeMockMatch = $this->getMockBuilder('\\OpCacheGUI\\Network\\Route')->disableOriginalConstructor()->getMock(); $routeMockMatch->method('matchesRequest')->willReturn(true); $routeMockMatch->method('run')->willReturn('match'); $routeMockNoMatch = $this->getMockBuilder('\\OpCacheGUI\\Network\\Route')->disableOriginalConstructor()->getMock(); $routeMockNoMatch->method('matchesRequest')->willReturn(false); $routeMockNoMatch->method('run')->willReturn('nomatch'); $factoryMock = $this->getMock('\\OpCacheGUI\\Network\\RouteBuilder'); $factoryMock->method('build')->will($this->onConsecutiveCalls($routeMockNoMatch, $routeMockMatch)); $router = new Router($requestMock, $factoryMock); $router->post('id', function () { }); $router->post('id', function () { }); $this->assertSame('match', $router->run()); }
* Setup the request object */ $request = new Request($_GET, $_POST, $_SERVER); /** * Setup the router */ $routeFactory = new RouteFactory(); $router = new Router($request, $routeFactory, $uriScheme); /** * Load public routes */ require_once __DIR__ . '/public-routes.php'; /** * Load the routes */ if (!extension_loaded('Zend OPcache') || opcache_get_status() === false) { if (!in_array($router->getIdentifier(), ['error', 'mainjs', 'maincss', 'fontawesome-webfont_eot', 'fontawesome-webfont_woff', 'fontawesome-webfont_ttf', 'fontawesome-webfont_svg'], true)) { header('Location: ' . $urlRenderer->get('error')); exit; } $router->get('error', function () use($htmlTemplate) { return $htmlTemplate->render('error.phtml', ['login' => true, 'title' => 'Error', 'type' => !extension_loaded('Zend OPcache') ? 'installed' : 'enabled']); }); } else { require_once __DIR__ . '/routes.php'; } /** * Dispatch the request */ echo $router->run();