/** * Route should set name */ public function testRouteSetsName() { $route = new Slim_Route('/foo/bar', function () { }); $route->name('foo'); $this->assertEquals('foo', $route->getName()); }
/** * Route should set name and be cached by Router */ public function testRouteSetsNameAndIsCached() { $router = new RouterMock(); $route = new Slim_Route('/foo/bar', function () { }); $route->setRouter($router); $route->name('foo'); $cacheKeys = array_keys($router->cache); $cacheValues = array_values($router->cache); $this->assertEquals('foo', $route->getName()); $this->assertSame($router, $route->getRouter()); $this->assertEquals($cacheKeys[0], 'foo'); $this->assertSame($cacheValues[0], $route); }
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(); $router->setResourceUri($req->getResourceUri()); $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); }