@@ -125,49 +125,66 @@ public function testCanCastAsString()
125125 $ this ->assertSame ($ expected , (string ) $ uri );
126126 }
127127
128- public function testSimpleUri ()
129- {
130- $ url = 'http://example.com ' ;
131- $ uri = new URI ($ url );
132-
133- $ this ->assertSame ($ url , (string ) $ uri );
134- $ this ->assertSame ('' , $ uri ->getPath ());
135-
136- $ url = 'http://example.com/ ' ;
137- $ uri = new URI ($ url );
138-
139- $ this ->assertSame ($ url , (string ) $ uri );
140- $ this ->assertSame ('/ ' , $ uri ->getPath ());
141- }
142-
143- public function testSimpleUriWithPath ()
128+ /**
129+ * @dataProvider provideURLs
130+ */
131+ public function testSimpleUri (string $ url , string $ expectedURL , string $ expectedPath )
144132 {
145- $ url = 'http://example.com/one/two ' ;
146- $ uri = new URI ($ url );
147-
148- $ this ->assertSame ($ url , (string ) $ uri );
149- $ this ->assertSame ('/one/two ' , $ uri ->getPath ());
150-
151- $ url = 'http://example.com/one/two/ ' ;
152133 $ uri = new URI ($ url );
153134
154- $ this ->assertSame ($ url , (string ) $ uri );
155- $ this ->assertSame (' /one/two/ ' , $ uri ->getPath ());
135+ $ this ->assertSame ($ expectedURL , (string ) $ uri );
136+ $ this ->assertSame ($ expectedPath , $ uri ->getPath ());
156137 }
157138
158- public function testSimpleUriWithPathDoubleSlashes ()
139+ public function provideURLs (): array
159140 {
160- $ url = 'http://example.com/one/two// ' ;
161- $ uri = new URI ($ url );
162-
163- $ this ->assertSame ('http://example.com/one/two/ ' , (string ) $ uri );
164- $ this ->assertSame ('/one/two/ ' , $ uri ->getPath ());
165-
166- $ url = 'http://example.com//one/two/ ' ;
167- $ uri = new URI ($ url );
168-
169- $ this ->assertSame ('http://example.com/one/two/ ' , (string ) $ uri );
170- $ this ->assertSame ('/one/two/ ' , $ uri ->getPath ());
141+ return [
142+ '' => [
143+ 'http://example.com ' , // url
144+ 'http://example.com ' , // expectedURL
145+ '' , // expectedPath
146+ ],
147+ '/ ' => [
148+ 'http://example.com/ ' ,
149+ 'http://example.com/ ' ,
150+ '/ ' ,
151+ ],
152+ '/one/two ' => [
153+ 'http://example.com/one/two ' ,
154+ 'http://example.com/one/two ' ,
155+ '/one/two ' ,
156+ ],
157+ '/one/two/ ' => [
158+ 'http://example.com/one/two/ ' ,
159+ 'http://example.com/one/two/ ' ,
160+ '/one/two/ ' ,
161+ ],
162+ '/one/two// ' => [
163+ 'http://example.com/one/two// ' ,
164+ 'http://example.com/one/two/ ' ,
165+ '/one/two/ ' ,
166+ ],
167+ '//one/two// ' => [
168+ 'http://example.com//one/two// ' ,
169+ 'http://example.com/one/two/ ' ,
170+ '/one/two/ ' ,
171+ ],
172+ '//one//two// ' => [
173+ 'http://example.com//one//two// ' ,
174+ 'http://example.com/one/two/ ' ,
175+ '/one/two/ ' ,
176+ ],
177+ '///one/two ' => [
178+ 'http://example.com///one/two ' , // url
179+ 'http://example.com/one/two ' , // expectedURL
180+ '/one/two ' , // expectedPath
181+ ],
182+ '/one/two/// ' => [
183+ 'http://example.com/one/two/// ' ,
184+ 'http://example.com/one/two/ ' ,
185+ '/one/two/ ' ,
186+ ],
187+ ];
171188 }
172189
173190 public function testEmptyUri ()
@@ -344,6 +361,76 @@ public function testSetPathSetsValue()
344361 $ this ->assertSame ($ expected , (string ) $ uri );
345362 }
346363
364+ /**
365+ * @dataProvider providePaths
366+ */
367+ public function testSetPath (string $ path , string $ expectedURL , string $ expectedPath )
368+ {
369+ $ url = 'http://example.com/ ' ;
370+ $ uri = new URI ($ url );
371+
372+ $ uri ->setPath ($ path );
373+
374+ $ this ->assertSame ($ expectedURL , (string ) $ uri );
375+ $ this ->assertSame ($ expectedPath , $ uri ->getPath ());
376+ }
377+
378+ public function providePaths (): array
379+ {
380+ return [
381+ '' => [
382+ '' , // path
383+ 'http://example.com ' , // expectedURL
384+ '' , // expectedPath
385+ ],
386+ '/ ' => [
387+ '/ ' ,
388+ 'http://example.com/ ' ,
389+ '/ ' ,
390+ ],
391+ '/one/two ' => [
392+ '/one/two ' ,
393+ 'http://example.com/one/two ' ,
394+ '/one/two ' ,
395+ ],
396+ '//one/two ' => [
397+ '//one/two ' ,
398+ 'http://example.com/one/two ' ,
399+ '/one/two ' ,
400+ ],
401+ '/one/two/ ' => [
402+ '/one/two/ ' ,
403+ 'http://example.com/one/two/ ' ,
404+ '/one/two/ ' ,
405+ ],
406+ '/one/two// ' => [
407+ '/one/two// ' ,
408+ 'http://example.com/one/two/ ' ,
409+ '/one/two/ ' ,
410+ ],
411+ '//one/two// ' => [
412+ '//one/two// ' ,
413+ 'http://example.com/one/two/ ' ,
414+ '/one/two/ ' ,
415+ ],
416+ '//one//two// ' => [
417+ '//one//two// ' ,
418+ 'http://example.com/one/two/ ' ,
419+ '/one/two/ ' ,
420+ ],
421+ '///one/two ' => [
422+ '///one/two ' ,
423+ 'http://example.com/one/two ' ,
424+ '/one/two ' ,
425+ ],
426+ '/one/two/// ' => [
427+ '/one/two/// ' , // path
428+ 'http://example.com/one/two/ ' , // expectedURL
429+ '/one/two/ ' , // expectedPath
430+ ],
431+ ];
432+ }
433+
347434 public function invalidPaths ()
348435 {
349436 return [
0 commit comments