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

Class GithubTest

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

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected