Completed
Push — master ( 990239...4eaa1e )
by Miro
02:27
created

PaginatedKnpLabsRepoFacadeTest::testFetchBranch()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
rs 9.4285
cc 1
eloc 3
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 testFetchAllTags()
70
    {
71
        self::assertCount(1, $this->facade->fetchAllTags());
72
    }
73
74
    /**
75
     * @group GithubIntegration
76
     * @group Live
77
     */
78
    public function testFetchAllTagNames()
79
    {
80
        self::assertCount(1, $this->facade->fetchAllTagNames());
81
    }
82
83
    /**
84
     * @group GithubIntegration
85
     * @group Live
86
     */
87
    public function testFetchCommit()
88
    {
89
        $result = $this->facade->fetchCommit('db911bd3a3dd8bb2ad9eccbcb0a396595a51491d');
90
91
        self::assertSame('db911bd3a3dd8bb2ad9eccbcb0a396595a51491d', $result['sha']);
92
    }
93
94
    /**
95
     * @group GithubIntegration
96
     * @group Live
97
     */
98
    public function testFetchCommitStatuses()
99
    {
100
        self::assertCount(27, $this->facade->fetchCommitStatuses('db911bd3a3dd8bb2ad9eccbcb0a396595a51491d'));
101
    }
102
103
    /**
104
     * @group GithubIntegration
105
     * @group Live
106
     */
107
    public function testFetchCommitStatus()
108
    {
109
        $result = $this->facade->fetchCommitStatus('db911bd3a3dd8bb2ad9eccbcb0a396595a51491d');
110
        self::assertSame(
111
            'https://api.github.com/repos/devboard/test-hitman/commits/db911bd3a3dd8bb2ad9eccbcb0a396595a51491d',
112
            $result['commit_url']
113
        );
114
    }
115
116
    /**
117
     * @group GithubIntegration
118
     * @group Live
119
     */
120
    public function testFetchAllPullRequests()
121
    {
122
        self::assertCount(2, $this->facade->fetchAllPullRequests());
123
    }
124
125
    /**
126
     * @group GithubIntegration
127
     * @group Live
128
     */
129
    public function testFetchAllMilestones()
130
    {
131
        self::assertCount(4, $this->facade->fetchAllMilestones());
132
    }
133
134
    /**
135
     * @group GithubIntegration
136
     * @group Live
137
     */
138
    public function testFetchAllIssues()
139
    {
140
        self::assertCount(10, $this->facade->fetchAllIssues());
141
    }
142
143
    /**
144
     * @group GithubIntegration
145
     * @group Live
146
     */
147
    public function testFetchAllIssuesAndPullRequests()
148
    {
149
        self::assertCount(12, $this->facade->fetchAllIssuesAndPullRequests());
150
    }
151
152
    /**
153
     * @return \Github\Client
154
     */
155
    private function getTokenAuthenticatedApiClient()
156
    {
157
        $factory = new KnpLabsClientFactory();
158
159
        return $factory->createTokenAuthenticatedClient($this->provideTestUser());
160
    }
161
162
    /**
163
     * @return \DevBoardLib\GithubCore\Repo\GithubRepo
164
     */
165 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...
166
    {
167
        $githubRepo = m::mock('DevBoardLib\GithubCore\Repo\GithubRepo');
168
        $githubRepo->shouldReceive('getOwner')->andReturn('devboard');
169
        $githubRepo->shouldReceive('getName')->andReturn('test-hitman');
170
        $githubRepo->shouldReceive('getFullName')->andReturn('devboard/test-hitman');
171
172
        return $githubRepo;
173
    }
174
175
    /**
176
     * @return \DevBoardLib\GithubApiFacade\Auth\GithubAccessToken
177
     */
178
    private function provideTestUser()
179
    {
180
        $user = m::mock('DevBoardLib\GithubApiFacade\Auth\GithubAccessToken');
181
        $user->shouldReceive('getGithubAccessToken')->andReturn(getenv('GITHUB_ACCESS_TOKEN'));
182
183
        return $user;
184
    }
185
}
186