@@ -22,19 +22,19 @@ public static function routeProvider()
2222 'simple-match ' => [
2323 new Regex ('/(?<foo>[^/]+) ' , '/%foo% ' ),
2424 '/bar ' ,
25- null ,
25+ 0 ,
2626 ['foo ' => 'bar ' ]
2727 ],
2828 'no-match-without-leading-slash ' => [
2929 new Regex ('(?<foo>[^/]+) ' , '%foo% ' ),
3030 '/bar ' ,
31- null ,
31+ 0 ,
3232 null
3333 ],
3434 'no-match-with-trailing-slash ' => [
3535 new Regex ('/(?<foo>[^/]+) ' , '/%foo% ' ),
3636 '/bar/ ' ,
37- null ,
37+ 0 ,
3838 null
3939 ],
4040 'offset-skips-beginning ' => [
@@ -43,22 +43,16 @@ public static function routeProvider()
4343 1 ,
4444 ['foo ' => 'bar ' ]
4545 ],
46- 'offset-enables-partial-matching ' => [
47- new Regex ('/(?<foo>[^/]+) ' , '/%foo% ' ),
48- '/bar/baz ' ,
49- 0 ,
50- ['foo ' => 'bar ' ]
51- ],
5246 'url-encoded-parameters-are-decoded ' => [
5347 new Regex ('/(?<foo>[^/]+) ' , '/%foo% ' ),
5448 '/foo%20bar ' ,
55- null ,
49+ 0 ,
5650 ['foo ' => 'foo bar ' ]
5751 ],
5852 'empty-matches-are-replaced-with-defaults ' => [
5953 new Regex ('/foo(?:/(?<bar>[^/]+))?/baz-(?<baz>[^/]+) ' , '/foo/baz-%baz% ' , ['bar ' => 'bar ' ]),
6054 '/foo/baz-baz ' ,
61- null ,
55+ 0 ,
6256 ['bar ' => 'bar ' , 'baz ' => 'baz ' ]
6357 ],
6458 ];
@@ -74,23 +68,30 @@ public static function routeProvider()
7468 public function testMatching (Regex $ route , $ path , $ offset , array $ params = null )
7569 {
7670 $ request = new ServerRequest ([], [], new Uri ('http://example.com ' . $ path ));
77- $ match = $ route ->match ($ request , $ offset );
71+ $ result = $ route ->match ($ request , $ offset );
7872
7973 if ($ params === null ) {
80- $ this ->assertNull ( $ match );
74+ $ this ->assertFalse ( $ result -> isSuccess () );
8175 } else {
82- $ this ->assertInstanceOf (RouteMatch::class, $ match );
83-
84- if ($ offset === null ) {
85- $ this ->assertEquals (strlen ($ path ), $ match ->getLength ());
86- }
76+ $ this ->assertTrue ($ result ->isSuccess ());
77+ $ match = $ result ->getRouteMatch ();
8778
8879 foreach ($ params as $ key => $ value ) {
8980 $ this ->assertEquals ($ value , $ match ->getParam ($ key ));
9081 }
9182 }
9283 }
9384
85+ public function testPartialMatching ()
86+ {
87+ $ route = new Regex ('/(?<foo>[^/]+) ' , '/%foo% ' );
88+ $ request = new ServerRequest ([], [], new Uri ('http://example.com/bar/baz ' ));
89+ $ result = $ route ->partialMatch ($ request , 0 );
90+
91+ $ this ->assertTrue ($ result ->isSuccess ());
92+ $ this ->assertEquals ('bar ' , $ result ->getRouteMatch ()->getParam ('foo ' ));
93+ }
94+
9495 /**
9596 * @dataProvider routeProvider
9697 * @param Regex $route
@@ -104,12 +105,12 @@ public function testAssembling(Regex $route, $path, $offset, array $params = nul
104105 self ::markTestSkipped ('Data which will not match are not tested for assembling. ' );
105106 }
106107
107- $ result = $ route ->assemble ($ params );
108+ $ uri = $ route ->assemble ($ params );
108109
109110 if ($ offset !== null ) {
110- $ this ->assertEquals ($ offset , strpos ($ path , $ result , $ offset ));
111+ $ this ->assertEquals ($ offset , strpos ($ path , $ uri -> getPath () , $ offset ));
111112 } else {
112- $ this ->assertEquals ($ path , $ result );
113+ $ this ->assertEquals ($ path , $ uri -> getPath () );
113114 }
114115 }
115116
@@ -118,7 +119,7 @@ public function testGetAssembledParams()
118119 $ route = new Regex ('/(?<foo>.+) ' , '/%foo% ' );
119120 $ route ->assemble (['foo ' => 'bar ' , 'baz ' => 'bat ' ]);
120121
121- $ this ->assertEquals (['foo ' ], $ route ->getAssembledParams ());
122+ $ this ->assertEquals (['foo ' ], $ route ->getLastAssembledParams ());
122123 }
123124
124125 public function testFactory ()
@@ -144,9 +145,10 @@ public function testRawDecode()
144145 $ raw = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789`-=[] \\; \',.~!@$^&*()_+{}|:"<> ' ;
145146 $ request = new ServerRequest ([], [], new Uri ('http://example.com/ ' . $ raw ));
146147 $ route = new Regex ('/(?<foo>[^/]+) ' , '/%foo% ' );
147- $ match = $ route ->match ($ request );
148+ $ result = $ route ->match ($ request );
148149
149- $ this ->assertSame ($ raw , $ match ->getParam ('foo ' ));
150+ $ this ->assertTrue ($ result ->isSuccess ());
151+ $ this ->assertSame ($ raw , $ result ->getRouteMatch ()->getParam ('foo ' ));
150152 }
151153
152154 public function testEncodedDecode ()
@@ -159,8 +161,9 @@ public function testEncodedDecode()
159161
160162 $ request = new ServerRequest ([], [], new Uri ('http://example.com/ ' . $ in ));
161163 $ route = new Regex ('/(?<foo>[^/]+) ' , '/%foo% ' );
162- $ match = $ route ->match ($ request );
164+ $ result = $ route ->match ($ request );
163165
164- $ this ->assertSame ($ out , $ match ->getParam ('foo ' ));
166+ $ this ->assertTrue ($ result ->isSuccess ());
167+ $ this ->assertSame ($ out , $ result ->getRouteMatch ()->getParam ('foo ' ));
165168 }
166169}
0 commit comments