| 8 | use Psr\Log\NullLogger; |
| 9 | |
| 10 | class GithubTest extends TestCase |
| 11 | { |
| 12 | private Github $github; |
| 13 | |
| 14 | protected function setUp(): void |
| 15 | { |
| 16 | $this->github = new Github(new FakeL10N(), new NullLogger(), $this->createMock(ExternalHttpClient::class)); |
| 17 | } |
| 18 | |
| 19 | public function testBuildHttpErrorResultForUnauthorizedResponse(): void |
| 20 | { |
| 21 | $method = new \ReflectionMethod(Github::class, 'buildHttpErrorResult'); |
| 22 | $method->setAccessible(true); |
| 23 | |
| 24 | $result = $method->invoke( |
| 25 | $this->github, |
| 26 | 401, |
| 27 | ['data' => ['message' => 'Bad credentials'], 'http_code' => 401], |
| 28 | ['cacheable' => true, 'key' => 'k1', 'notModified' => false] |
| 29 | ); |
| 30 | |
| 31 | $this->assertSame('Missing or invalid GitHub access token', $result['error']); |
| 32 | $this->assertSame([], $result['data']); |
| 33 | } |
| 34 | |
| 35 | public function testBuildHttpErrorResultForRateLimitResponse(): void |
| 36 | { |
| 37 | $method = new \ReflectionMethod(Github::class, 'buildHttpErrorResult'); |
| 38 | $method->setAccessible(true); |
| 39 | |
| 40 | $result = $method->invoke( |
| 41 | $this->github, |
| 42 | 403, |
| 43 | ['data' => ['message' => 'API rate limit exceeded'], 'http_code' => 403], |
| 44 | ['cacheable' => true, 'key' => 'k1', 'notModified' => false] |
| 45 | ); |
| 46 | |
| 47 | $this->assertSame('Rate limit exceeded', $result['error']); |
| 48 | $this->assertSame([], $result['data']); |
| 49 | } |
| 50 | |
| 51 | public function testBuildHttpErrorResultForForbiddenPackageAccessResponse(): void |
| 52 | { |
| 53 | $method = new \ReflectionMethod(Github::class, 'buildHttpErrorResult'); |
| 54 | $method->setAccessible(true); |
| 55 | |
| 56 | $result = $method->invoke( |
| 57 | $this->github, |
| 58 | 403, |
| 59 | ['data' => ['message' => 'Resource not accessible by personal access token'], 'http_code' => 403], |
| 60 | ['cacheable' => true, 'key' => 'k1', 'notModified' => false] |
| 61 | ); |
| 62 | |
| 63 | $this->assertSame('GitHub API error: Resource not accessible by personal access token', $result['error']); |
| 64 | $this->assertSame([], $result['data']); |
| 65 | } |
| 66 | |
| 67 | public function testBuildHtmlRequestHeadersIncludesToken(): void |
nothing calls this directly
no outgoing calls
no test coverage detected