This repository was archived by the owner on Sep 16, 2021. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +47
-3
lines changed Expand file tree Collapse file tree 4 files changed +47
-3
lines changed Original file line number Diff line number Diff line change @@ -103,7 +103,10 @@ public function getFullPath()
103
103
{
104
104
$ paths = array ();
105
105
foreach ($ this ->routeStacks as $ routeStack ) {
106
- $ paths [] = $ routeStack ->getPath ();
106
+ $ path = $ routeStack ->getPath ();
107
+ if (!empty ($ path )) {
108
+ $ paths [] = $ path ;
109
+ }
107
110
}
108
111
109
112
$ path = implode ('/ ' , $ paths );
Original file line number Diff line number Diff line change 10
10
*/
11
11
class RouteStack
12
12
{
13
- protected $ pathElements ;
13
+ protected $ pathElements = array () ;
14
14
protected $ routes = array ();
15
15
protected $ context ;
16
16
protected $ existingRoute ;
@@ -90,6 +90,10 @@ public function getPathElements()
90
90
*/
91
91
public function getPaths ()
92
92
{
93
+ if (empty ($ this ->pathElements )) {
94
+ return array ();
95
+ }
96
+
93
97
$ tmp = array ();
94
98
95
99
foreach ($ this ->pathElements as $ pathElement ) {
@@ -135,7 +139,11 @@ public function getFullPath()
135
139
$ fullPath = $ this ->getPath ();
136
140
137
141
if ($ parentPath ) {
138
- $ fullPath = $ parentPath .'/ ' .$ fullPath ;
142
+ if (empty ($ fullPath )) {
143
+ $ fullPath = $ parentPath ;
144
+ } else {
145
+ $ fullPath = $ parentPath .'/ ' .$ fullPath ;
146
+ }
139
147
}
140
148
141
149
return $ fullPath ;
Original file line number Diff line number Diff line change @@ -25,6 +25,33 @@ public function testStageAndCommitRouteStack()
25
25
$ this ->assertCount (1 , $ this ->builderContext ->getRouteStacks ());
26
26
}
27
27
28
+ public function testIgnoreEmptyPath ()
29
+ {
30
+ $ this ->routeStack ->expects ($ this ->at (3 ))
31
+ ->method ('getPath ' )
32
+ ->will ($ this ->returnValue ('route ' ));
33
+
34
+ $ this ->routeStack ->expects ($ this ->at (4 ))
35
+ ->method ('getPath ' )
36
+ ->will ($ this ->returnValue ('' ));
37
+
38
+ $ this ->routeStack ->expects ($ this ->at (5 ))
39
+ ->method ('getPath ' )
40
+ ->will ($ this ->returnValue ('foo/bar ' ));
41
+
42
+ $ this ->routeStack ->expects ($ this ->exactly (3 ))
43
+ ->method ('isClosed ' )
44
+ ->will ($ this ->returnValue (true ));
45
+
46
+ for ($ i = 0 ; $ i < 3 ; $ i ++) {
47
+ $ this ->builderContext ->stageRouteStack ($ this ->routeStack );
48
+ $ this ->builderContext ->commitRouteStack ();
49
+ }
50
+
51
+ $ this ->assertCount (3 , $ this ->builderContext ->getRouteStacks ());
52
+ $ this ->assertEquals ('route/foo/bar ' , $ this ->builderContext ->getFullPath ());
53
+ }
54
+
28
55
/**
29
56
* @expectedException \RuntimeException
30
57
*/
Original file line number Diff line number Diff line change @@ -16,6 +16,12 @@ public function setUp()
16
16
$ this ->route2 = new \stdClass ;
17
17
}
18
18
19
+ public function testGetEmptyPath ()
20
+ {
21
+ $ this ->assertEmpty ($ this ->routeStack ->getPaths ());
22
+ $ this ->assertEquals ('' , $ this ->routeStack ->getFullPath ());
23
+ }
24
+
19
25
public function testAddPathElement ()
20
26
{
21
27
$ this ->routeStack ->addPathElements (array ('foo ' , 'bar ' ));
You can’t perform that action at this time.
0 commit comments