@@ -140,25 +140,28 @@ public function testUriStringAbsolute()
140140 $ _SERVER ['HTTP_HOST ' ] = 'example.com ' ;
141141 $ _SERVER ['REQUEST_URI ' ] = '/assets/image.jpg ' ;
142142
143- $ uri = new URI ('http://example.com/assets/image.jpg ' );
143+ $ uri = 'http://example.com/assets/image.jpg ' ;
144+ $ this ->setService ($ uri );
145+
146+ $ this ->assertSame ('assets/image.jpg ' , uri_string ());
147+ }
148+
149+ private function setService (string $ uri ): void
150+ {
151+ $ uri = new URI ($ uri );
144152 Services::injectMock ('uri ' , $ uri );
145153
146154 $ request = Services::request ($ this ->config );
147155 Services::injectMock ('request ' , $ request );
148-
149- $ this ->assertSame ('assets/image.jpg ' , uri_string ());
150156 }
151157
152158 public function testUriStringRelative ()
153159 {
154160 $ _SERVER ['HTTP_HOST ' ] = 'example.com ' ;
155161 $ _SERVER ['REQUEST_URI ' ] = '/assets/image.jpg ' ;
156162
157- $ uri = new URI ('http://example.com/assets/image.jpg ' );
158- Services::injectMock ('uri ' , $ uri );
159-
160- $ request = Services::request ($ this ->config );
161- Services::injectMock ('request ' , $ request );
163+ $ uri = 'http://example.com/assets/image.jpg ' ;
164+ $ this ->setService ($ uri );
162165
163166 $ this ->assertSame ('assets/image.jpg ' , uri_string (true ));
164167 }
@@ -170,11 +173,8 @@ public function testUriStringNoTrailingSlashAbsolute()
170173
171174 $ this ->config ->baseURL = 'http://example.com ' ;
172175
173- $ uri = new URI ('http://example.com/assets/image.jpg ' );
174- Services::injectMock ('uri ' , $ uri );
175-
176- $ request = Services::request ($ this ->config );
177- Services::injectMock ('request ' , $ request );
176+ $ uri = 'http://example.com/assets/image.jpg ' ;
177+ $ this ->setService ($ uri );
178178
179179 $ this ->assertSame ('assets/image.jpg ' , uri_string ());
180180 }
@@ -186,33 +186,24 @@ public function testUriStringNoTrailingSlashRelative()
186186
187187 $ this ->config ->baseURL = 'http://example.com ' ;
188188
189- $ uri = new URI ('http://example.com/assets/image.jpg ' );
190- Services::injectMock ('uri ' , $ uri );
191-
192- $ request = Services::request ($ this ->config );
193- Services::injectMock ('request ' , $ request );
189+ $ uri = 'http://example.com/assets/image.jpg ' ;
190+ $ this ->setService ($ uri );
194191
195192 $ this ->assertSame ('assets/image.jpg ' , uri_string (true ));
196193 }
197194
198195 public function testUriStringEmptyAbsolute ()
199196 {
200- $ uri = new URI ('http://example.com/ ' );
201- Services::injectMock ('uri ' , $ uri );
202-
203- $ request = Services::request ($ this ->config );
204- Services::injectMock ('request ' , $ request );
197+ $ uri = 'http://example.com/ ' ;
198+ $ this ->setService ($ uri );
205199
206200 $ this ->assertSame ('/ ' , uri_string ());
207201 }
208202
209203 public function testUriStringEmptyRelative ()
210204 {
211- $ uri = new URI ('http://example.com/ ' );
212- Services::injectMock ('uri ' , $ uri );
213-
214- $ request = Services::request ($ this ->config );
215- Services::injectMock ('request ' , $ request );
205+ $ uri = 'http://example.com/ ' ;
206+ $ this ->setService ($ uri );
216207
217208 $ this ->assertSame ('' , uri_string (true ));
218209 }
@@ -224,11 +215,8 @@ public function testUriStringSubfolderAbsolute()
224215
225216 $ this ->config ->baseURL = 'http://example.com/subfolder/ ' ;
226217
227- $ uri = new URI ('http://example.com/subfolder/assets/image.jpg ' );
228- Services::injectMock ('uri ' , $ uri );
229-
230- $ request = Services::request ($ this ->config );
231- Services::injectMock ('request ' , $ request );
218+ $ uri = 'http://example.com/subfolder/assets/image.jpg ' ;
219+ $ this ->setService ($ uri );
232220
233221 $ this ->assertSame ('subfolder/assets/image.jpg ' , uri_string ());
234222 }
@@ -241,12 +229,8 @@ public function testUriStringSubfolderRelative()
241229
242230 $ this ->config ->baseURL = 'http://example.com/subfolder/ ' ;
243231
244- $ uri = new URI ('http://example.com/subfolder/assets/image.jpg ' );
245- Services::injectMock ('uri ' , $ uri );
246-
247- $ request = Services::request ($ this ->config );
248-
249- Services::injectMock ('request ' , $ request );
232+ $ uri = 'http://example.com/subfolder/assets/image.jpg ' ;
233+ $ this ->setService ($ uri );
250234
251235 $ this ->assertSame ('assets/image.jpg ' , uri_string (true ));
252236 }
@@ -300,11 +284,8 @@ public function testUrlIs(string $currentPath, string $testPath, bool $expected)
300284 $ _SERVER ['HTTP_HOST ' ] = 'example.com ' ;
301285 $ _SERVER ['REQUEST_URI ' ] = '/ ' . $ currentPath ;
302286
303- $ uri = new URI ('http://example.com/ ' . $ currentPath );
304- Services::injectMock ('uri ' , $ uri );
305-
306- $ request = Services::request ();
307- Services::injectMock ('request ' , $ request );
287+ $ uri = 'http://example.com/ ' . $ currentPath ;
288+ $ this ->setService ($ uri );
308289
309290 $ this ->assertSame ($ expected , url_is ($ testPath ));
310291 }
@@ -319,11 +300,8 @@ public function testUrlIsNoIndex(string $currentPath, string $testPath, bool $ex
319300
320301 $ this ->config ->indexPage = '' ;
321302
322- $ uri = new URI ('http://example.com/ ' . $ currentPath );
323- Services::injectMock ('uri ' , $ uri );
324-
325- $ request = Services::request ($ this ->config );
326- Services::injectMock ('request ' , $ request );
303+ $ uri = 'http://example.com/ ' . $ currentPath ;
304+ $ this ->setService ($ uri );
327305
328306 $ this ->assertSame ($ expected , url_is ($ testPath ));
329307 }
@@ -339,11 +317,8 @@ public function testUrlIsWithSubfolder(string $currentPath, string $testPath, bo
339317
340318 $ this ->config ->baseURL = 'http://example.com/subfolder/ ' ;
341319
342- $ uri = new URI ('http://example.com/subfolder/ ' . $ currentPath );
343- Services::injectMock ('uri ' , $ uri );
344-
345- $ request = Services::request ($ this ->config );
346- Services::injectMock ('request ' , $ request );
320+ $ uri = 'http://example.com/subfolder/ ' . $ currentPath ;
321+ $ this ->setService ($ uri );
347322
348323 $ this ->assertSame ($ expected , url_is ($ testPath ));
349324 }
0 commit comments