createStub(ProviderInterface::class); $provider->method('probe')->willReturn(new ProviderStatus('test', ProviderStatusType::Ok)); $result = (new ProviderHealthChecker([$provider]))->check(); $this->assertSame('ok', $result['status']); } #[Test] public function it_returns_degraded_when_a_provider_has_an_error(): void { $provider = $this->createStub(ProviderInterface::class); $provider->method('probe')->willReturn( new ProviderStatus('test', ProviderStatusType::Error, ProviderErrorCode::AuthFailed, 'Invalid token'), ); $result = (new ProviderHealthChecker([$provider]))->check(); $this->assertSame('degraded', $result['status']); } #[Test] public function it_does_not_degrade_when_a_provider_is_not_configured(): void { $provider = $this->createStub(ProviderInterface::class); $provider->method('probe')->willReturn(new ProviderStatus('test', ProviderStatusType::NotConfigured)); $result = (new ProviderHealthChecker([$provider]))->check(); $this->assertSame('ok', $result['status']); } #[Test] public function it_indexes_provider_statuses_by_name(): void { $provider = $this->createStub(ProviderInterface::class); $provider->method('probe')->willReturn(new ProviderStatus('github', ProviderStatusType::Ok)); $result = (new ProviderHealthChecker([$provider]))->check(); $this->assertArrayHasKey('github', $result['providers']); } #[Test] public function it_returns_ok_with_no_providers(): void { $result = (new ProviderHealthChecker([]))->check(); $this->assertSame('ok', $result['status']); $this->assertSame([], $result['providers']); } #[Test] public function it_includes_all_provider_statuses_in_output(): void { $github = $this->createStub(ProviderInterface::class); $github->method('probe')->willReturn(new ProviderStatus('github', ProviderStatusType::Ok)); $gitlab = $this->createStub(ProviderInterface::class); $gitlab->method('probe')->willReturn(new ProviderStatus('gitlab', ProviderStatusType::NotConfigured)); $result = (new ProviderHealthChecker([$github, $gitlab]))->check(); $this->assertArrayHasKey('github', $result['providers']); $this->assertArrayHasKey('gitlab', $result['providers']); } }