Skip to content

Commit

Permalink
Merge branch 'llvdl-1669' into 3.x
Browse files Browse the repository at this point in the history
  • Loading branch information
akrabat committed May 7, 2016
2 parents f762537 + ce12f9c commit 1b90353
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
10 changes: 10 additions & 0 deletions Slim/Routable.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,14 @@ public function add($callable)
$this->middleware[] = new DeferredCallable($callable, $this->container);
return $this;
}

/**
* Set the route pattern
*
* @set string
*/
public function setPattern($newPattern)
{
$this->pattern = $newPattern;
}
}
10 changes: 10 additions & 0 deletions tests/RouteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -408,4 +408,14 @@ public function testInvokeDeferredCallable()
$this->assertInstanceOf('Slim\Http\Response', $result);
$this->assertEquals([$container['CallableTest'], 'toCall'], InvocationStrategyTest::$LastCalledFor);
}

/**
* Ensure that the pattern can be dynamically changed
*/
public function testPatternCanBeChanged()
{
$route = $this->routeFactory();
$route->setPattern('/hola/{nombre}');
$this->assertEquals('/hola/{nombre}', $route->getPattern());
}
}
20 changes: 20 additions & 0 deletions tests/RouterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -286,4 +286,24 @@ public function testRouteRemovalNotExists()
$this->router->setBasePath('/base/path');
$this->router->removeNamedRoute('non-existing-route-name');
}

public function testPathForWithModifiedRoutePattern()
{
$this->router->setBasePath('/base/path');

$methods = ['GET'];
$pattern = '/hello/{first:\w+}/{last}';
$callable = function ($request, $response, $args) {
echo sprintf('Hello %s %s', $args['voornaam'], $args['achternaam']);
};
$route = $this->router->map($methods, $pattern, $callable);
$route->setName('foo');

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

$this->assertEquals(
'/hallo/josh/lockhart',
$this->router->relativePathFor('foo', ['voornaam' => 'josh', 'achternaam' => 'lockhart'])
);
}
}

0 comments on commit 1b90353

Please sign in to comment.