. */ namespace App\Tests\Services\InfoProviderSystem; use App\Services\InfoProviderSystem\ProviderRegistry; use App\Services\InfoProviderSystem\Providers\InfoProviderInterface; use PHPUnit\Framework\TestCase; class ProviderRegistryTest extends TestCase { /** @var InfoProviderInterface[] */ private array $providers = []; public function setUp(): void { //Create some mock providers $this->providers = [ $this->getMockProvider('test1'), $this->getMockProvider('test2'), $this->getMockProvider('test3', false), ]; } public function getMockProvider(string $key, bool $active = true): InfoProviderInterface { $mock = $this->createMock(InfoProviderInterface::class); $mock->method('getProviderKey')->willReturn($key); $mock->method('isActive')->willReturn($active); return $mock; } public function testGetProviders(): void { $registry = new ProviderRegistry($this->providers); $this->assertEquals( [ 'test1' => $this->providers[0], 'test2' => $this->providers[1], 'test3' => $this->providers[2], ], $registry->getProviders()); } public function testGetDisabledProviders(): void { $registry = new ProviderRegistry($this->providers); $this->assertEquals( [ 'test3' => $this->providers[2], ], $registry->getDisabledProviders()); } public function testGetActiveProviders(): void { $registry = new ProviderRegistry($this->providers); $this->assertEquals( [ 'test1' => $this->providers[0], 'test2' => $this->providers[1], ], $registry->getActiveProviders()); } public function testGetProviderByKey(): void { $registry = new ProviderRegistry($this->providers); $this->assertEquals( $this->providers[0], $registry->getProviderByKey('test1') ); } public function testThrowOnDuplicateKeyOfProviders(): void { $this->expectException(\LogicException::class); $registry = new ProviderRegistry([ $this->getMockProvider('test1'), $this->getMockProvider('test2'), $this->getMockProvider('test1'), ]); $registry->getProviders(); } }