From 9e37e30f7c11d74f528dea2a96ba623371ef8cdf Mon Sep 17 00:00:00 2001 From: Augusto Pascutti Date: Sun, 11 Mar 2012 01:25:58 -0300 Subject: [PATCH] Quick-clean way of fixing #18 --- library/Respect/Rest/Router.php | 1 + tests/library/Respect/Rest/RouterTest.php | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/library/Respect/Rest/Router.php b/library/Respect/Rest/Router.php index dc6813c..16364c6 100644 --- a/library/Respect/Rest/Router.php +++ b/library/Respect/Rest/Router.php @@ -144,6 +144,7 @@ public function dispatchRequest(Request $request=null) if ($this->matchRoute($request, $route, $params)) return $this->configureRequest($request, $route, static::cleanUpParams($params)); + header('HTTP/1.1 404'); $request->route = null; return $request; } diff --git a/tests/library/Respect/Rest/RouterTest.php b/tests/library/Respect/Rest/RouterTest.php index 01f2cf9..42869ea 100644 --- a/tests/library/Respect/Rest/RouterTest.php +++ b/tests/library/Respect/Rest/RouterTest.php @@ -95,4 +95,24 @@ function test_converting_router_to_string_should_dispatch_and_run_it() $response = (string) $this->router; $this->assertEquals('ok', $response); } + function test_dispatch_non_existing_route() + { + global $header; + $this->router->any('/', function() {}); + $this->router->dispatch('get', '/my/name/is/hall'); + $this->assertContains('HTTP/1.1 404', $header); + } } +$header=array(); +/** + * [header description] + * @return void + */ +function header($string, $replace=true, $http_response_code=200) +{ + global $header; + if (!$replace && isset($header)) + return; + + $header[$string] = $string; +} \ No newline at end of file