createStub(HttpClientInterface::class), $username, $token, $baseUrl, $this->createStub(LoggerInterface::class), ); } private function stubResponse(array $data): ResponseInterface { $response = $this->createStub(ResponseInterface::class); $response->method('toArray')->willReturn($data); return $response; } #[Test] public function it_returns_gitea_as_name(): void { $this->assertSame('gitea', $this->makeProvider()->getName()); } #[Test] public function it_is_configured_when_all_credentials_are_set(): void { $this->assertTrue($this->makeProvider()->isConfigured()); } #[Test] public function it_is_not_configured_when_username_is_empty(): void { $this->assertFalse($this->makeProvider(username: '')->isConfigured()); } #[Test] public function it_is_not_configured_when_token_is_empty(): void { $this->assertFalse($this->makeProvider(token: '')->isConfigured()); } #[Test] public function it_is_not_configured_when_base_url_is_empty(): void { $this->assertFalse($this->makeProvider(baseUrl: '')->isConfigured()); } #[Test] public function it_parses_heatmap_entries_into_contributions(): void { $now = time(); $client = $this->createStub(HttpClientInterface::class); $client->method('request')->willReturn($this->stubResponse([ ['timestamp' => $now, 'contributions' => 5], ])); $result = $this->makeProvider(client: $client)->fetch(); $this->assertSame(5, $result[date('Y-m-d', $now)]); } #[Test] public function it_filters_out_entries_older_than_365_days(): void { $old = (new \DateTimeImmutable('-366 days'))->getTimestamp(); $client = $this->createStub(HttpClientInterface::class); $client->method('request')->willReturn($this->stubResponse([ ['timestamp' => $old, 'contributions' => 3], ])); $result = $this->makeProvider(client: $client)->fetch(); $this->assertSame([], $result); } #[Test] public function it_returns_empty_when_response_has_no_entries(): void { $client = $this->createStub(HttpClientInterface::class); $client->method('request')->willReturn($this->stubResponse([])); $result = $this->makeProvider(client: $client)->fetch(); $this->assertSame([], $result); } }