configured; } public function getName(): string { return 'test'; } public function ping(): void { ($this->ping)(); } public function fetch(): array { return []; } }; } #[Test] public function it_returns_not_configured_when_provider_is_not_configured(): void { $provider = $this->makeProvider(false, fn() => null); $status = $provider->probe(); $this->assertSame(ProviderStatusType::NotConfigured, $status->status); $this->assertNull($status->error); } #[Test] public function it_returns_ok_when_ping_succeeds(): void { $provider = $this->makeProvider(true, fn() => null); $status = $provider->probe(); $this->assertSame(ProviderStatusType::Ok, $status->status); $this->assertNull($status->error); } #[Test] public function it_returns_url_unreachable_on_transport_failure(): void { $exception = $this->createStub(TransportExceptionInterface::class); $provider = $this->makeProvider(true, fn() => throw $exception); $status = $provider->probe(); $this->assertSame(ProviderStatusType::Error, $status->status); $this->assertSame(ProviderErrorCode::UrlUnreachable, $status->error); } #[Test] public function it_returns_auth_failed_on_401(): void { $response = $this->createStub(ResponseInterface::class); $response->method('getStatusCode')->willReturn(401); $exception = $this->createStub(ClientExceptionInterface::class); $exception->method('getResponse')->willReturn($response); $status = $this->makeProvider(true, fn() => throw $exception)->probe(); $this->assertSame(ProviderStatusType::Error, $status->status); $this->assertSame(ProviderErrorCode::AuthFailed, $status->error); } #[Test] public function it_returns_auth_failed_on_403(): void { $response = $this->createStub(ResponseInterface::class); $response->method('getStatusCode')->willReturn(403); $exception = $this->createStub(ClientExceptionInterface::class); $exception->method('getResponse')->willReturn($response); $status = $this->makeProvider(true, fn() => throw $exception)->probe(); $this->assertSame(ProviderStatusType::Error, $status->status); $this->assertSame(ProviderErrorCode::AuthFailed, $status->error); } #[Test] public function it_returns_url_unreachable_on_404(): void { $response = $this->createStub(ResponseInterface::class); $response->method('getStatusCode')->willReturn(404); $exception = $this->createStub(ClientExceptionInterface::class); $exception->method('getResponse')->willReturn($response); $status = $this->makeProvider(true, fn() => throw $exception)->probe(); $this->assertSame(ProviderStatusType::Error, $status->status); $this->assertSame(ProviderErrorCode::UrlUnreachable, $status->error); } #[Test] public function it_returns_unknown_error_on_unexpected_exception(): void { $provider = $this->makeProvider(true, fn() => throw new \RuntimeException('Something went wrong')); $status = $provider->probe(); $this->assertSame(ProviderStatusType::Error, $status->status); $this->assertSame(ProviderErrorCode::Unknown, $status->error); $this->assertSame('Something went wrong', $status->message); } }