/** * @covers Pushy\Router\Router::__construct * @covers Pushy\Router\Router::getRouteByRequest */ public function testGetRouteByRequestNoMatchThrowsException() { $router = new Router($this->getMock('\\Pushy\\Router\\RouteBuilder')); $request = $this->getMock('\\Pushy\\Network\\Http\\RequestData'); $request->expects($this->any())->method('getMethod')->will($this->returnValue('GET')); $this->setExpectedException('\\Pushy\\Router\\NoMatchingRouteException'); $route = $router->getRouteByRequest($request); }
/** * Prevent rendering of pages when on CLI */ if (php_sapi_name() === 'cli') { return; } /** * Setup the request object */ $request = new Request(new ImmutableArray($_GET), new ImmutableArray($_POST), new ImmutableArray($_SERVER), new ImmutableArray($_FILES)); /** * Setup the response object */ $response = new Response(); /** * Setup the router */ $routeFactory = new RouteFactory(); $router = new Router($routeFactory); $router->get('frontpage', '#^/?$#', function (RequestData $request) { $response->setBody('Pushy!'); }); /** * Run the app */ $frontcontroller = new FrontController($request, $response, $router); $frontcontroller->dispatch(); /** * Render the content */ echo $response->render();