Completed
Pull Request — master (#8)
by Miro
02:13
created

testFetchAllPullRequests()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
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
    private $facade;
14
15
    public function setUp()
16
    {
17
        parent::setUp();
18
19
        $this->facade = new PaginatedKnpLabsRepoFacade(
20
            $this->getTokenAuthenticatedApiClient(),
21
            $this->provideTestRepo()
22
        );
23
    }
24
25
    /**
26
     * @group GithubIntegration
27
     * @group Live
28
     */
29
    public function testFetchRepoDetails()
30
    {
31
        $result = $this->facade->fetchDetails();
32
33
        self::assertSame($this->provideTestRepo()->getFullName(), $result['full_name']);
0 ignored issues
show
Bug introduced by
The method getFullName() does not seem to exist on object<Mockery\MockInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
34
    }
35
36
    /**
37
     * @group GithubIntegration
38
     * @group Live
39
     */
40
    public function testFetchBranch()
41
    {
42
        $result = $this->facade->fetchBranch('master');
43
44
        self::assertSame('master', $result['name']);
45
    }
46
47
    /**
48
     * @group GithubIntegration
49
     * @group Live
50
     */
51
    public function testFetchAllBranches()
52
    {
53
        self::assertCount(7, $this->facade->fetchAllBranches());
54
    }
55
56
    /**
57
     * @group GithubIntegration
58
     * @group Live
59
     */
60
    public function testFetchAllBranchNames()
61
    {
62
        self::assertCount(7, $this->facade->fetchAllBranchNames());
63
    }
64
65
    /**
66
     * @group GithubIntegration
67
     * @group Live
68
     */
69
    public function testFetchAllTagNames()
70
    {
71
        self::assertCount(1, $this->facade->fetchAllTagNames());
72
    }
73
74
    /**
75
     * @group GithubIntegration
76
     * @group Live
77
     */
78
    public function testFetchCommit()
79
    {
80
        $result = $this->facade->fetchCommit('db911bd3a3dd8bb2ad9eccbcb0a396595a51491d');
81
82
        self::assertSame('db911bd3a3dd8bb2ad9eccbcb0a396595a51491d', $result['sha']);
83
    }
84
85
    /**
86
     * @group GithubIntegration
87
     * @group Live
88
     * @group wip
89
     */
90
    public function testFetchCommitStatuses()
91
    {
92
        self::assertCount(27, $this->facade->fetchCommitStatuses('db911bd3a3dd8bb2ad9eccbcb0a396595a51491d'));
93
    }
94
95
    /**
96
     * @group GithubIntegration
97
     * @group Live
98
     * @group wip
99
     */
100
    public function testFetchCommitStatus()
101
    {
102
        $result = $this->facade->fetchCommitStatus('db911bd3a3dd8bb2ad9eccbcb0a396595a51491d');
103
        self::assertSame(
104
            'https://api.github.com/repos/devboard/test-hitman/commits/db911bd3a3dd8bb2ad9eccbcb0a396595a51491d',
105
            $result['commit_url']
106
        );
107
    }
108
109
    /**
110
     * @group GithubIntegration
111
     * @group Live
112
     * @group wip
113
     */
114
    public function testFetchAllPullRequests()
115
    {
116
        self::assertCount(2, $this->facade->fetchAllPullRequests());
117
    }
118
119
    /**
120
     * @group GithubIntegration
121
     * @group Live
122
     */
123
    public function testFetchAllMilestones()
124
    {
125
        self::assertCount(4, $this->facade->fetchAllMilestones());
126
    }
127
128
    /**
129
     * @group GithubIntegration
130
     * @group Live
131
     */
132
    public function testFetchAllIssues()
133
    {
134
        self::assertCount(10, $this->facade->fetchAllIssues());
135
    }
136
137
    /**
138
     * @group GithubIntegration
139
     * @group Live
140
     */
141
    public function testFetchAllIssuesAndPullRequests()
142
    {
143
        self::assertCount(12, $this->facade->fetchAllIssuesAndPullRequests());
144
    }
145
146
    /**
147
     * @return \Github\Client
148
     */
149
    private function getTokenAuthenticatedApiClient()
150
    {
151
        $factory = new KnpLabsClientFactory();
152
153
        return $factory->createTokenAuthenticatedClient($this->provideTestUser());
154
    }
155
156
    /**
157
     * @return \DevBoardLib\GithubCore\Repo\GithubRepo
158
     */
159 View Code Duplication
    private function provideTestRepo()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
160
    {
161
        $githubRepo = m::mock('DevBoardLib\GithubCore\Repo\GithubRepo');
162
        $githubRepo->shouldReceive('getOwner')->andReturn('devboard');
163
        $githubRepo->shouldReceive('getName')->andReturn('test-hitman');
164
        $githubRepo->shouldReceive('getFullName')->andReturn('devboard/test-hitman');
165
166
        return $githubRepo;
167
    }
168
169
    /**
170
     * @return \DevBoardLib\GithubApiFacade\Auth\GithubAccessToken
171
     */
172
    private function provideTestUser()
173
    {
174
        $user = m::mock('DevBoardLib\GithubApiFacade\Auth\GithubAccessToken');
175
        $user->shouldReceive('getGithubAccessToken')->andReturn(getenv('GITHUB_ACCESS_TOKEN'));
176
177
        return $user;
178
    }
179
}
180