Skip to content
This repository was archived by the owner on Sep 16, 2021. It is now read-only.

Allow path providers that don't add path elements each time #47

Merged
merged 1 commit into from
Dec 21, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion AutoRoute/BuilderContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,10 @@ public function getFullPath()
{
$paths = array();
foreach ($this->routeStacks as $routeStack) {
$paths[] = $routeStack->getPath();
$path = $routeStack->getPath();
if (!empty($path)) {
$paths[] = $path;
}
}

$path = implode('/', $paths);
Expand Down
12 changes: 10 additions & 2 deletions AutoRoute/RouteStack.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*/
class RouteStack
{
protected $pathElements;
protected $pathElements = array();
protected $routes = array();
protected $context;
protected $existingRoute;
Expand Down Expand Up @@ -90,6 +90,10 @@ public function getPathElements()
*/
public function getPaths()
{
if (empty($this->pathElements)) {
return array();
}

$tmp = array();

foreach ($this->pathElements as $pathElement) {
Expand Down Expand Up @@ -135,7 +139,11 @@ public function getFullPath()
$fullPath = $this->getPath();

if ($parentPath) {
$fullPath = $parentPath.'/'.$fullPath;
if (empty($fullPath)) {
$fullPath = $parentPath;
} else {
$fullPath = $parentPath.'/'.$fullPath;
}
}

return $fullPath;
Expand Down
27 changes: 27 additions & 0 deletions Tests/Unit/AutoRoute/BuilderContextTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,33 @@ public function testStageAndCommitRouteStack()
$this->assertCount(1, $this->builderContext->getRouteStacks());
}

public function testIgnoreEmptyPath()
{
$this->routeStack->expects($this->at(3))
->method('getPath')
->will($this->returnValue('route'));

$this->routeStack->expects($this->at(4))
->method('getPath')
->will($this->returnValue(''));

$this->routeStack->expects($this->at(5))
->method('getPath')
->will($this->returnValue('foo/bar'));

$this->routeStack->expects($this->exactly(3))
->method('isClosed')
->will($this->returnValue(true));

for ($i = 0; $i < 3; $i++) {
$this->builderContext->stageRouteStack($this->routeStack);
$this->builderContext->commitRouteStack();
}

$this->assertCount(3, $this->builderContext->getRouteStacks());
$this->assertEquals('route/foo/bar', $this->builderContext->getFullPath());
}

/**
* @expectedException \RuntimeException
*/
Expand Down
6 changes: 6 additions & 0 deletions Tests/Unit/AutoRoute/RouteStackTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ public function setUp()
$this->route2 = new \stdClass;
}

public function testGetEmptyPath()
{
$this->assertEmpty($this->routeStack->getPaths());
$this->assertEquals('', $this->routeStack->getFullPath());
}

public function testAddPathElement()
{
$this->routeStack->addPathElements(array('foo', 'bar'));
Expand Down