Skip to content

Commit

Permalink
Merge 2900788 into 794073a
Browse files Browse the repository at this point in the history
  • Loading branch information
danielgsims committed May 17, 2016
2 parents 794073a + 2900788 commit 46ff55b
Showing 1 changed file with 41 additions and 4 deletions.
45 changes: 41 additions & 4 deletions tests/RouterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ public function testRemoveRoute()
$callable = function ($request, $response, $args) {
echo sprintf('Hello ignore me');
};

$this->router->setBasePath('/base/path');

$route1 = $this->router->map($methods, '/foo', $callable);
Expand All @@ -245,7 +245,7 @@ public function testRemoveRoute()

$route4 = $this->router->map($methods, '/buzz', $callable);
$route4->setName('buzz');

$routeToRemove = $this->router->getNamedRoute('fizz');

$routeCountBefore = count($this->router->getRoutes());
Expand Down Expand Up @@ -286,7 +286,7 @@ public function testRouteRemovalNotExists()
$this->router->setBasePath('/base/path');
$this->router->removeNamedRoute('non-existing-route-name');
}

public function testPathForWithModifiedRoutePattern()
{
$this->router->setBasePath('/base/path');
Expand All @@ -298,7 +298,7 @@ public function testPathForWithModifiedRoutePattern()
};
$route = $this->router->map($methods, $pattern, $callable);
$route->setName('foo');

$route->setPattern('/hallo/{voornaam:\w+}/{achternaam}');

$this->assertEquals(
Expand Down Expand Up @@ -400,4 +400,41 @@ public function testCreateDispatcherReturnsSameDispatcherASecondTime()
$dispatcher2 = $method->invoke($this->router);
$this->assertSame($dispatcher2, $dispatcher);
}

/**
* Test that the router urlFor will proxy into a pathFor method, and trigger
* the user deprecated warning
*/
public function testUrlForAliasesPathFor()
{
//create a temporary error handler, store the error str in this value
$errorString = null;

set_error_handler(function ($no, $str) use (&$errorString) {
$errorString = $str;
}, E_USER_DEPRECATED);

//create the parameters we expect
$name = 'foo';
$data = ['name' => 'josh'];
$queryParams = ['a' => 'b', 'c' => 'd'];

//create a router that mocks the pathFor with expected args
$router = $this->getMock('\Slim\Router', ['pathFor']);
$router->expects($this->once())->method('pathFor')->with($name, $data, $queryParams);
$router->urlFor($name, $data, $queryParams);

//check that our error was triggered
$this->assertEquals($errorString, 'urlFor() is deprecated. Use pathFor() instead.');

restore_error_handler();
}

/**
* @expectedException \RuntimeException
*/
public function testLookupRouteThrowsExceptionIfRouteNotFound()
{
$this->router->lookupRoute("thisIsMissing");
}
}

0 comments on commit 46ff55b

Please sign in to comment.