/** * @dataProvider setup_test_provider * @test */ public function setup_test($input, $expected) { list(Router::$current_uri, $_SERVER['QUERY_STRING']) = $input; if ($expected[0] === '') { // The default route should exist. No 404 will be thrown. Router::setup(); } else { // Other tested URIs should not exist. A 404 must be thrown. try { Router::setup(); $this->setExpectedException('Kohana_404_Exception'); } catch (Kohana_404_Exception $e) { // Correct, do nothing } catch (Exception $e) { // Unexpected exception $this->setExpectedException('Kohana_404_Exception'); } } $this->assertEquals($expected[0], Router::$current_uri); $this->assertEquals($expected[1], Router::$query_string); $this->assertEquals($expected[2], Router::$segments); }
<?php /** * The entry file for the web application. All requests should be sent through * this file. */ use Symfony\Component\HttpFoundation\Request; require_once __DIR__ . '/../vendor/autoload.php'; $router = new Router(); $dispatcher = $router->setup()->getDispatcher(); $request = Request::createFromGlobals(); $response = $dispatcher->dispatch($request->getMethod(), $request->getPathInfo()); $response->send();