@@ -140,23 +140,28 @@ public function testUriStringAbsolute()
140140 $ _SERVER ['HTTP_HOST ' ] = 'example.com ' ;
141141 $ _SERVER ['REQUEST_URI ' ] = '/assets/image.jpg ' ;
142142
143- $ request = Services:: request ( $ this -> config ) ;
144- $ request -> uri = new URI ( ' http://example.com/assets/image.jpg ' );
143+ $ uri = ' http://example.com/assets/image.jpg ' ;
144+ $ this -> setService ( $ uri );
145145
146- Services::injectMock ('request ' , $ request );
146+ $ this ->assertSame ('assets/image.jpg ' , uri_string ());
147+ }
148+
149+ private function setService (string $ uri ): void
150+ {
151+ $ uri = new URI ($ uri );
152+ Services::injectMock ('uri ' , $ uri );
147153
148- $ this ->assertSame ('/assets/image.jpg ' , uri_string ());
154+ $ request = Services::request ($ this ->config );
155+ Services::injectMock ('request ' , $ request );
149156 }
150157
151158 public function testUriStringRelative ()
152159 {
153160 $ _SERVER ['HTTP_HOST ' ] = 'example.com ' ;
154161 $ _SERVER ['REQUEST_URI ' ] = '/assets/image.jpg ' ;
155162
156- $ request = Services::request ($ this ->config );
157- $ request ->uri = new URI ('http://example.com/assets/image.jpg ' );
158-
159- Services::injectMock ('request ' , $ request );
163+ $ uri = 'http://example.com/assets/image.jpg ' ;
164+ $ this ->setService ($ uri );
160165
161166 $ this ->assertSame ('assets/image.jpg ' , uri_string (true ));
162167 }
@@ -167,12 +172,11 @@ public function testUriStringNoTrailingSlashAbsolute()
167172 $ _SERVER ['REQUEST_URI ' ] = '/assets/image.jpg ' ;
168173
169174 $ this ->config ->baseURL = 'http://example.com ' ;
170- $ request = Services::request ($ this ->config );
171- $ request ->uri = new URI ('http://example.com/assets/image.jpg ' );
172175
173- Services::injectMock ('request ' , $ request );
176+ $ uri = 'http://example.com/assets/image.jpg ' ;
177+ $ this ->setService ($ uri );
174178
175- $ this ->assertSame ('/ assets/image.jpg ' , uri_string ());
179+ $ this ->assertSame ('assets/image.jpg ' , uri_string ());
176180 }
177181
178182 public function testUriStringNoTrailingSlashRelative ()
@@ -181,30 +185,25 @@ public function testUriStringNoTrailingSlashRelative()
181185 $ _SERVER ['REQUEST_URI ' ] = '/assets/image.jpg ' ;
182186
183187 $ this ->config ->baseURL = 'http://example.com ' ;
184- $ request = Services::request ($ this ->config );
185- $ request ->uri = new URI ('http://example.com/assets/image.jpg ' );
186188
187- Services::injectMock ('request ' , $ request );
189+ $ uri = 'http://example.com/assets/image.jpg ' ;
190+ $ this ->setService ($ uri );
188191
189192 $ this ->assertSame ('assets/image.jpg ' , uri_string (true ));
190193 }
191194
192195 public function testUriStringEmptyAbsolute ()
193196 {
194- $ request = Services::request ($ this ->config );
195- $ request ->uri = new URI ('http://example.com/ ' );
196-
197- Services::injectMock ('request ' , $ request );
197+ $ uri = 'http://example.com/ ' ;
198+ $ this ->setService ($ uri );
198199
199200 $ this ->assertSame ('/ ' , uri_string ());
200201 }
201202
202203 public function testUriStringEmptyRelative ()
203204 {
204- $ request = Services::request ($ this ->config );
205- $ request ->uri = new URI ('http://example.com/ ' );
206-
207- Services::injectMock ('request ' , $ request );
205+ $ uri = 'http://example.com/ ' ;
206+ $ this ->setService ($ uri );
208207
209208 $ this ->assertSame ('' , uri_string (true ));
210209 }
@@ -215,12 +214,11 @@ public function testUriStringSubfolderAbsolute()
215214 $ _SERVER ['REQUEST_URI ' ] = '/subfolder/assets/image.jpg ' ;
216215
217216 $ this ->config ->baseURL = 'http://example.com/subfolder/ ' ;
218- $ request = Services::request ($ this ->config );
219- $ request ->uri = new URI ('http://example.com/subfolder/assets/image.jpg ' );
220217
221- Services::injectMock ('request ' , $ request );
218+ $ uri = 'http://example.com/subfolder/assets/image.jpg ' ;
219+ $ this ->setService ($ uri );
222220
223- $ this ->assertSame ('/ subfolder/assets/image.jpg ' , uri_string ());
221+ $ this ->assertSame ('subfolder/assets/image.jpg ' , uri_string ());
224222 }
225223
226224 public function testUriStringSubfolderRelative ()
@@ -230,10 +228,9 @@ public function testUriStringSubfolderRelative()
230228 $ _SERVER ['SCRIPT_NAME ' ] = '/subfolder/index.php ' ;
231229
232230 $ this ->config ->baseURL = 'http://example.com/subfolder/ ' ;
233- $ request = Services::request ($ this ->config );
234- $ request ->uri = new URI ('http://example.com/subfolder/assets/image.jpg ' );
235231
236- Services::injectMock ('request ' , $ request );
232+ $ uri = 'http://example.com/subfolder/assets/image.jpg ' ;
233+ $ this ->setService ($ uri );
237234
238235 $ this ->assertSame ('assets/image.jpg ' , uri_string (true ));
239236 }
@@ -287,9 +284,8 @@ public function testUrlIs(string $currentPath, string $testPath, bool $expected)
287284 $ _SERVER ['HTTP_HOST ' ] = 'example.com ' ;
288285 $ _SERVER ['REQUEST_URI ' ] = '/ ' . $ currentPath ;
289286
290- $ request = Services::request ();
291- $ request ->uri = new URI ('http://example.com/ ' . $ currentPath );
292- Services::injectMock ('request ' , $ request );
287+ $ uri = 'http://example.com/ ' . $ currentPath ;
288+ $ this ->setService ($ uri );
293289
294290 $ this ->assertSame ($ expected , url_is ($ testPath ));
295291 }
@@ -299,13 +295,13 @@ public function testUrlIs(string $currentPath, string $testPath, bool $expected)
299295 */
300296 public function testUrlIsNoIndex (string $ currentPath , string $ testPath , bool $ expected )
301297 {
302- $ _SERVER ['HTTP_HOST ' ] = 'example.com ' ;
303- $ _SERVER ['REQUEST_URI ' ] = '/ ' . $ currentPath ;
298+ $ _SERVER ['HTTP_HOST ' ] = 'example.com ' ;
299+ $ _SERVER ['REQUEST_URI ' ] = '/ ' . $ currentPath ;
300+
304301 $ this ->config ->indexPage = '' ;
305302
306- $ request = Services::request ($ this ->config );
307- $ request ->uri = new URI ('http://example.com/ ' . $ currentPath );
308- Services::injectMock ('request ' , $ request );
303+ $ uri = 'http://example.com/ ' . $ currentPath ;
304+ $ this ->setService ($ uri );
309305
310306 $ this ->assertSame ($ expected , url_is ($ testPath ));
311307 }
@@ -318,11 +314,11 @@ public function testUrlIsWithSubfolder(string $currentPath, string $testPath, bo
318314 $ _SERVER ['HTTP_HOST ' ] = 'example.com ' ;
319315 $ _SERVER ['REQUEST_URI ' ] = '/ ' . $ currentPath ;
320316 $ _SERVER ['SCRIPT_NAME ' ] = '/subfolder/index.php ' ;
321- $ this ->config ->baseURL = 'http://example.com/subfolder/ ' ;
322317
323- $ request = Services::request ($ this ->config );
324- $ request ->uri = new URI ('http://example.com/subfolder/ ' . $ currentPath );
325- Services::injectMock ('request ' , $ request );
318+ $ this ->config ->baseURL = 'http://example.com/subfolder/ ' ;
319+
320+ $ uri = 'http://example.com/subfolder/ ' . $ currentPath ;
321+ $ this ->setService ($ uri );
326322
327323 $ this ->assertSame ($ expected , url_is ($ testPath ));
328324 }
0 commit comments