/** * Test middleware with arguments */ public function testRouteMiddlwareArguments() { $this->expectOutputString('foobar'); $route = new \Slim\Route('/foo', function () { echo "bar"; }); $route->setName('foo'); $route->setMiddleware(function ($route) { echo $route->getName(); }); $route->matches('/foo'); //<-- Extracts params from resource URI $route->dispatch(); }
public function testDispatchWithoutCallable() { \Slim\Environment::mock(array('REQUEST_METHOD' => 'GET', 'REMOTE_ADDR' => '127.0.0.1', 'SCRIPT_NAME' => '', 'PATH_INFO' => '/hello/josh', 'QUERY_STRING' => 'one=1&two=2&three=3', 'SERVER_NAME' => 'slim', 'SERVER_PORT' => 80, 'slim.url_scheme' => 'http', 'slim.input' => '', 'slim.errors' => fopen('php://stderr', 'w'), 'HTTP_HOST' => 'slim')); $env = \Slim\Environment::getInstance(); $req = new \Slim\Http\Request($env); $router = new \Slim\Router(); $router->setResourceUri($req->getResourceUri()); $route = new \Slim\Route('/hello/:name', 'foo'); $route->matches($req->getResourceUri()); //<-- Extracts params from resource URI $this->assertFalse($router->dispatch($route)); }
/** * Route does not match URI with wildcard */ public function testRouteDoesNotMatchResourceWithWildcard() { $resource = '/hello'; $route = new \Slim\Route('/hello/:path+', function () { }); $result = $route->matches($resource); $this->assertFalse($result); $this->assertEquals(array(), $route->getParams()); }
public function testRouteMiddlwareArguments() { $this->expectOutputString('foobar'); \Slim\Environment::mock(array('SCRIPT_NAME' => '', 'PATH_INFO' => '/foo')); $env = \Slim\Environment::getInstance(); $req = new \Slim\Http\Request($env); $router = new \Slim\Router(); $route = new \Slim\Route('/foo', function () { echo "bar"; }); $route->setName('foo'); $route->setMiddleware(function ($route) { echo $route->getName(); }); $route->matches($req->getResourceUri()); //<-- Extracts params from resource URI $router->dispatch($route); }