|
1 | | -<?php namespace Config; |
| 1 | +<?php |
| 2 | +namespace Config; |
| 3 | + |
| 4 | +use Tests\Support\HTTP\MockResponse; |
2 | 5 |
|
3 | 6 | class ServicesTest extends \CIUnitTestCase |
4 | 7 | { |
@@ -227,4 +230,51 @@ public function testCallStatic() |
227 | 230 | $this->assertInstanceOf(\CodeIgniter\Session\Session::class, $actual); |
228 | 231 | } |
229 | 232 |
|
| 233 | + /** |
| 234 | + * @runInSeparateProcess |
| 235 | + * @preserveGlobalState disabled |
| 236 | + */ |
| 237 | + public function testCallStaticDirectly() |
| 238 | + { |
| 239 | + // $actual = \CodeIgniter\Config\Services::SeSsIoN(null, false); // original |
| 240 | + $actual = \CodeIgniter\Config\Services::__callStatic('SeSsIoN', [null, false]); |
| 241 | + $this->assertInstanceOf(\CodeIgniter\Session\Session::class, $actual); |
| 242 | + } |
| 243 | + |
| 244 | + /** |
| 245 | + * @runInSeparateProcess |
| 246 | + * @preserveGlobalState disabled |
| 247 | + */ |
| 248 | + public function testMockInjection() |
| 249 | + { |
| 250 | + Services::injectMock('response', new MockResponse(new App())); |
| 251 | + $response = service('response'); |
| 252 | + $this->assertInstanceOf(MockResponse::class, $response); |
| 253 | + |
| 254 | + Services::injectMock('response', new MockResponse(new App())); |
| 255 | + $response2 = service('response'); |
| 256 | + $this->assertInstanceOf(MockResponse::class, $response2); |
| 257 | + |
| 258 | + $this->assertEquals($response, $response2); |
| 259 | + } |
| 260 | + |
| 261 | + /** |
| 262 | + * @runInSeparateProcess |
| 263 | + * @preserveGlobalState disabled |
| 264 | + */ |
| 265 | + public function testReset() |
| 266 | + { |
| 267 | + Services::injectMock('response', new MockResponse(new App())); |
| 268 | + $response = service('response'); |
| 269 | + $this->assertInstanceOf(MockResponse::class, $response); |
| 270 | + |
| 271 | + Services::reset(true); // reset mocks & shared instances |
| 272 | + |
| 273 | + Services::injectMock('response', new MockResponse(new App())); |
| 274 | + $response2 = service('response'); |
| 275 | + $this->assertInstanceOf(MockResponse::class, $response2); |
| 276 | + |
| 277 | + $this->assertTrue($response !== $response2); |
| 278 | + } |
| 279 | + |
230 | 280 | } |
0 commit comments