|
51 | 51 | use Config\Exceptions; |
52 | 52 | use Config\Security as SecurityConfig; |
53 | 53 | use Config\Session as ConfigSession; |
| 54 | +use Config\WorkerMode; |
54 | 55 | use InvalidArgumentException; |
55 | 56 | use PHPUnit\Framework\Attributes\DataProvider; |
56 | 57 | use PHPUnit\Framework\Attributes\Group; |
@@ -500,4 +501,64 @@ public function testServiceInstance(): void |
500 | 501 | $this->assertInstanceOf(\Config\Services::class, new \Config\Services()); |
501 | 502 | rename(COMPOSER_PATH . '.backup', COMPOSER_PATH); |
502 | 503 | } |
| 504 | + |
| 505 | + public function testHas(): void |
| 506 | + { |
| 507 | + $this->assertFalse(Services::has('timer')); |
| 508 | + |
| 509 | + Services::timer(); |
| 510 | + |
| 511 | + $this->assertTrue(Services::has('timer')); |
| 512 | + } |
| 513 | + |
| 514 | + public function testHasReturnsFalseForNonExistentService(): void |
| 515 | + { |
| 516 | + $this->assertFalse(Services::has('nonexistent')); |
| 517 | + } |
| 518 | + |
| 519 | + #[PreserveGlobalState(false)] |
| 520 | + #[RunInSeparateProcess] |
| 521 | + public function testResetForWorkerModeWithKeepAliveStrategy(): void |
| 522 | + { |
| 523 | + $config = new WorkerMode(); |
| 524 | + $config->cacheStrategy = 'keep-alive'; |
| 525 | + $config->persistentServices = ['timer']; |
| 526 | + |
| 527 | + Services::cache(); |
| 528 | + Services::timer(); |
| 529 | + Services::typography(); |
| 530 | + |
| 531 | + $this->assertTrue(Services::has('cache')); |
| 532 | + $this->assertTrue(Services::has('timer')); |
| 533 | + $this->assertTrue(Services::has('typography')); |
| 534 | + |
| 535 | + Services::resetForWorkerMode($config); |
| 536 | + |
| 537 | + $this->assertTrue(Services::has('cache')); |
| 538 | + $this->assertTrue(Services::has('timer')); |
| 539 | + $this->assertFalse(Services::has('typography')); |
| 540 | + } |
| 541 | + |
| 542 | + #[PreserveGlobalState(false)] |
| 543 | + #[RunInSeparateProcess] |
| 544 | + public function testResetForWorkerModeWithReconnectStrategy(): void |
| 545 | + { |
| 546 | + $config = new WorkerMode(); |
| 547 | + $config->cacheStrategy = 'reconnect'; |
| 548 | + $config->persistentServices = ['timer']; |
| 549 | + |
| 550 | + Services::cache(); |
| 551 | + Services::timer(); |
| 552 | + Services::typography(); |
| 553 | + |
| 554 | + $this->assertTrue(Services::has('cache')); |
| 555 | + $this->assertTrue(Services::has('timer')); |
| 556 | + $this->assertTrue(Services::has('typography')); |
| 557 | + |
| 558 | + Services::resetForWorkerMode($config); |
| 559 | + |
| 560 | + $this->assertFalse(Services::has('cache')); |
| 561 | + $this->assertTrue(Services::has('timer')); |
| 562 | + $this->assertFalse(Services::has('typography')); |
| 563 | + } |
503 | 564 | } |
0 commit comments