1
|
|
|
<?php |
2
|
|
|
namespace tests\DevBoardLib\GithubApiFacade\Repo; |
3
|
|
|
|
4
|
|
|
use DevBoardLib\GithubApiFacade\Client\KnpLabsClientFactory; |
5
|
|
|
use DevBoardLib\GithubApiFacade\Repo\PaginatedKnpLabsRepoFacade; |
6
|
|
|
use Mockery as m; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Class PaginatedKnpLabsRepoFacadeTest. |
10
|
|
|
*/ |
11
|
|
|
class PaginatedKnpLabsRepoFacadeTest extends \PHPUnit_Framework_TestCase |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* @group GithubIntegration |
15
|
|
|
* @group Live |
16
|
|
|
*/ |
17
|
|
|
public function testFetchAllMilestones() |
18
|
|
|
{ |
19
|
|
|
$target = new PaginatedKnpLabsRepoFacade( |
20
|
|
|
$this->getTokenAuthenticatedApiClient(), |
21
|
|
|
$this->provideTestRepo() |
22
|
|
|
); |
23
|
|
|
|
24
|
|
|
self::assertCount(4, $target->fetchAllMilestones()); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @group GithubIntegration |
29
|
|
|
* @group Live |
30
|
|
|
* @group wip |
31
|
|
|
*/ |
32
|
|
|
public function testFetchAllIssues() |
33
|
|
|
{ |
34
|
|
|
$target = new PaginatedKnpLabsRepoFacade( |
35
|
|
|
$this->getTokenAuthenticatedApiClient(), |
36
|
|
|
$this->provideTestRepo() |
37
|
|
|
); |
38
|
|
|
|
39
|
|
|
self::assertCount(10, $target->fetchAllIssues()); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @group GithubIntegration |
44
|
|
|
* @group Live |
45
|
|
|
* @group wip |
46
|
|
|
*/ |
47
|
|
|
public function testFetchAllIssuesAndPullRequests() |
48
|
|
|
{ |
49
|
|
|
$target = new PaginatedKnpLabsRepoFacade( |
50
|
|
|
$this->getTokenAuthenticatedApiClient(), |
51
|
|
|
$this->provideTestRepo() |
52
|
|
|
); |
53
|
|
|
|
54
|
|
|
self::assertCount(12, $target->fetchAllIssuesAndPullRequests()); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @return \Github\Client |
59
|
|
|
*/ |
60
|
|
|
private function getTokenAuthenticatedApiClient() |
61
|
|
|
{ |
62
|
|
|
$factory = new KnpLabsClientFactory(); |
63
|
|
|
|
64
|
|
|
return $factory->createTokenAuthenticatedClient($this->provideTestUser()); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @return m\MockInterface |
69
|
|
|
*/ |
70
|
|
View Code Duplication |
private function provideTestRepo() |
|
|
|
|
71
|
|
|
{ |
72
|
|
|
$githubRepo = m::mock('DevBoardLib\GithubCore\Repo\GithubRepo'); |
73
|
|
|
$githubRepo->shouldReceive('getOwner')->andReturn('devboard'); |
74
|
|
|
$githubRepo->shouldReceive('getName')->andReturn('test-hitman'); |
75
|
|
|
|
76
|
|
|
return $githubRepo; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @return m\MockInterface |
81
|
|
|
*/ |
82
|
|
|
private function provideTestUser() |
83
|
|
|
{ |
84
|
|
|
$user = m::mock('DevBoardLib\GithubApiFacade\Auth\GithubAccessToken'); |
85
|
|
|
$user->shouldReceive('getGithubAccessToken')->andReturn(getenv('GITHUB_ACCESS_TOKEN')); |
86
|
|
|
|
87
|
|
|
return $user; |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.