MCPcopy Create free account
hub / github.com/Rello/analytics / GithubTest

Class GithubTest

tests/Datasource/GithubTest.php:10–170  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

8use Psr\Log\NullLogger;
9
10class 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

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected