/** * @covers Pushy\Router\FrontController::__construct * @covers Pushy\Router\FrontController::dispatch * @covers Pushy\Router\FrontController::setParameters */ public function testDispatchWithParams() { $route = $this->getMock('\\Pushy\\Router\\AccessPoint'); $route->expects($this->any())->method('getCallback')->will($this->returnValue(function ($request) { return 'foo'; })); $route->expects($this->any())->method('getPath')->will($this->returnValue('/(foo)/')); $router = $this->getMock('\\Pushy\\Router\\Routable'); $router->expects($this->any())->method('getRouteByRequest')->will($this->returnValue($route)); $request = $this->getMock('\\Pushy\\Network\\Http\\RequestData'); $request->expects($this->any())->method('setParameters')->will($this->returnCallback(function ($params) { \PHPUnit_Framework_Assert::assertSame(['foo'], $params); })); $request->expects($this->any())->method('getPath')->will($this->returnValue('/foo')); $response = $this->getMock('\\Pushy\\Network\\Http\\ResponseData'); $response->expects($this->any())->method('setBody')->will($this->returnCallback(function ($body) { \PHPUnit_Framework_Assert::assertSame('foo', $body); })); $frontcontroller = new FrontController($request, $response, $router); $this->assertNull($frontcontroller->dispatch()); }
/** * 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();