/** * Find the route that matches the current request * * @param Slab\Router\RouteCollection * @param Slab\Core\Http\RequestInterface * @return array Result **/ public function findRoute(RouteCollection $routes, RequestInterface $request) { $dispatcher = new RouteDispatcher(); $result = $dispatcher->dispatch($request, $routes); if ($result['status'] !== $dispatcher::FOUND) { return null; } return $result; }
/** * Test dispatching a request against not-found * * @return void **/ public function testDispatcherMiss() { $request = m::mock('Slab\\Core\\Http\\RequestInterface'); $request->shouldReceive('getMethod')->once()->andReturn('POST'); $request->shouldReceive('getPath')->once()->andReturn('foo/bar'); $routes = m::mock('Slab\\Router\\RouteCollection'); $routes->shouldReceive('getRoutes')->with('POST')->once()->andReturn([['path' => '', 'handler' => 'myHandler1'], ['path' => 'foo', 'handler' => 'myHandler2'], ['path' => 'foo/bar/baz', 'handler' => 'myHandler3'], ['path' => 'bar', 'handler' => 'myHandler4']]); $dispatcher = new RouteDispatcher(); $result = $dispatcher->dispatch($request, $routes); $this->assertEquals(['status' => 404], $result); }