PaginatedKnpLabsRepoFacadeTest::setUp()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 9
rs 9.6666
cc 1
eloc 5
nc 1
nop 0
1
<?php
2
3
namespace tests\DevBoardLib\GithubApiFacade\Repo;
4
5
use DevBoardLib\GithubApiFacade\Client\KnpLabsClientFactory;
6
use DevBoardLib\GithubApiFacade\Repo\PaginatedKnpLabsRepoFacade;
7
use Mockery as m;
8
9
/**
10
 * Class PaginatedKnpLabsRepoFacadeTest.
11
 */
12
class PaginatedKnpLabsRepoFacadeTest extends \PHPUnit_Framework_TestCase
13
{
14
    private $facade;
15
16
    public function setUp()
17
    {
18
        parent::setUp();
19
20
        $this->facade = new PaginatedKnpLabsRepoFacade(
21
            $this->getTokenAuthenticatedApiClient(),
22
            $this->provideTestRepo()
23
        );
24
    }
25
26
    /**
27
     * @group GithubIntegration
28
     * @group Live
29
     */
30
    public function testFetchRepoDetails()
31
    {
32
        $result = $this->facade->fetchDetails();
33
34
        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...
35
    }
36
37
    /**
38
     * @group GithubIntegration
39
     * @group Live
40
     */
41
    public function testFetchBranch()
42
    {
43
        $result = $this->facade->fetchBranch('master');
44
45
        self::assertSame('master', $result['name']);
46
    }
47
48
    /**
49
     * @group GithubIntegration
50
     * @group Live
51
     */
52
    public function testFetchAllBranches()
53
    {
54
        self::assertCount(7, $this->facade->fetchAllBranches());
55
    }
56
57
    /**
58
     * @group GithubIntegration
59
     * @group Live
60
     */
61
    public function testFetchAllBranchNames()
62
    {
63
        self::assertCount(7, $this->facade->fetchAllBranchNames());
64
    }
65
66
    /**
67
     * @group GithubIntegration
68
     * @group Live
69
     */
70
    public function testFetchAllTags()
71
    {
72
        self::assertCount(1, $this->facade->fetchAllTags());
73
    }
74
75
    /**
76
     * @group GithubIntegration
77
     * @group Live
78
     */
79
    public function testFetchAllTagNames()
80
    {
81
        self::assertCount(1, $this->facade->fetchAllTagNames());
82
    }
83
84
    /**
85
     * @group GithubIntegration
86
     * @group Live
87
     */
88
    public function testFetchCommit()
89
    {
90
        $result = $this->facade->fetchCommit('db911bd3a3dd8bb2ad9eccbcb0a396595a51491d');
91
92
        self::assertSame('db911bd3a3dd8bb2ad9eccbcb0a396595a51491d', $result['sha']);
93
    }
94
95
    /**
96
     * @group GithubIntegration
97
     * @group Live
98
     */
99
    public function testFetchCommitStatuses()
100
    {
101
        self::assertCount(27, $this->facade->fetchCommitStatuses('db911bd3a3dd8bb2ad9eccbcb0a396595a51491d'));
102
    }
103
104
    /**
105
     * @group GithubIntegration
106
     * @group Live
107
     */
108
    public function testFetchCommitStatus()
109
    {
110
        $result = $this->facade->fetchCommitStatus('db911bd3a3dd8bb2ad9eccbcb0a396595a51491d');
111
        self::assertSame(
112
            'https://api.github.com/repos/devboard/test-hitman/commits/db911bd3a3dd8bb2ad9eccbcb0a396595a51491d',
113
            $result['commit_url']
114
        );
115
    }
116
117
    /**
118
     * @group GithubIntegration
119
     * @group Live
120
     */
121
    public function testFetchAllPullRequests()
122
    {
123
        self::assertCount(2, $this->facade->fetchAllPullRequests());
124
    }
125
126
    /**
127
     * @group GithubIntegration
128
     * @group Live
129
     */
130
    public function testFetchAllMilestones()
131
    {
132
        self::assertCount(4, $this->facade->fetchAllMilestones());
133
    }
134
135
    /**
136
     * @group GithubIntegration
137
     * @group Live
138
     */
139
    public function testFetchAllIssues()
140
    {
141
        self::assertCount(10, $this->facade->fetchAllIssues());
142
    }
143
144
    /**
145
     * @group GithubIntegration
146
     * @group Live
147
     */
148
    public function testFetchAllIssuesAndPullRequests()
149
    {
150
        self::assertCount(12, $this->facade->fetchAllIssuesAndPullRequests());
151
    }
152
153
    /**
154
     * @return \Github\Client
155
     */
156
    private function getTokenAuthenticatedApiClient()
157
    {
158
        $factory = new KnpLabsClientFactory();
159
160
        return $factory->createTokenAuthenticatedClient($this->provideTestUser());
161
    }
162
163
    /**
164
     * @return \DevBoardLib\GithubCore\Repo\GithubRepo
165
     */
166 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...
167
    {
168
        $githubRepo = m::mock('DevBoardLib\GithubCore\Repo\GithubRepo');
169
        $githubRepo->shouldReceive('getOwner')->andReturn('devboard');
170
        $githubRepo->shouldReceive('getName')->andReturn('test-hitman');
171
        $githubRepo->shouldReceive('getFullName')->andReturn('devboard/test-hitman');
172
173
        return $githubRepo;
174
    }
175
176
    /**
177
     * @return \DevBoardLib\GithubApiFacade\Auth\GithubAccessToken
178
     */
179
    private function provideTestUser()
180
    {
181
        $user = m::mock('DevBoardLib\GithubApiFacade\Auth\GithubAccessToken');
182
        $user->shouldReceive('getGithubAccessToken')->andReturn(getenv('GITHUB_ACCESS_TOKEN'));
183
184
        return $user;
185
    }
186
}
187