Completed
Pull Request — master (#8)
by Miro
03:40
created

SimpleRepoFacadeTest::testFetchDetails()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 13
rs 9.4285
cc 1
eloc 8
nc 1
nop 0
1
<?php
2
namespace tests\DevBoardLib\GithubObjectApiFacade\Repo;
3
4
use DevBoardLib\GithubObjectApiFacade\Repo\Branch\Converter\GithubBranchConverter;
5
use DevBoardLib\GithubObjectApiFacade\Repo\Commit\Converter\GithubCommitConverter;
6
use DevBoardLib\GithubObjectApiFacade\Repo\CommitStatus\Converter\GithubCommitStatusConverter;
7
use DevBoardLib\GithubObjectApiFacade\Repo\Issue\Converter\GithubIssueConverter;
8
use DevBoardLib\GithubObjectApiFacade\Repo\Milestone\Converter\GithubMilestoneConverter;
9
use DevBoardLib\GithubObjectApiFacade\Repo\PullRequest\Converter\GithubPullRequestConverter;
10
use DevBoardLib\GithubObjectApiFacade\Repo\Repo\Converter\GithubRepoConverter;
11
use DevBoardLib\GithubObjectApiFacade\Repo\SimpleRepoFacade;
12
use DevBoardLib\GithubObjectApiFacade\Repo\Tag\Converter\GithubTagConverter;
13
use Mockery as m;
14
use tests\DevBoardLib\GithubObjectApiFacade\SampleDataProvider;
15
16
/**
17
 * Class SimpleRepoFacadeTest.
18
 *
19
 * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
20
 */
21
class SimpleRepoFacadeTest extends \PHPUnit_Framework_TestCase
22
{
23
    public function testFetchDetails()
24
    {
25
        $wrapped = m::mock('DevBoardLib\GithubApiFacade\Repo\RepoFacade');
26
        $wrapped->shouldReceive('fetchDetails')
27
            ->andReturn($this->getDataProvider()->getRepoDetails());
28
29
        $target = $this->createFacade($wrapped);
30
31
        self::assertInstanceOf(
32
            'DevBoardLib\GithubCore\Repo\GithubRepoSource',
33
            $target->fetchDetails()
34
        );
35
    }
36
37 View Code Duplication
    public function testFetchBranch()
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...
38
    {
39
        $wrapped = m::mock('DevBoardLib\GithubApiFacade\Repo\RepoFacade');
40
        $wrapped->shouldReceive('fetchBranch')
41
            ->with('master')
42
            ->andReturn($this->getDataProvider()->getBranch());
43
44
        $target = $this->createFacade($wrapped);
45
46
        self::assertInstanceOf(
47
            'DevBoardLib\GithubCore\Branch\GithubBranchSource',
48
            $target->fetchBranch('master')
49
        );
50
    }
51
52 View Code Duplication
    public function testFetchAllBranches()
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...
53
    {
54
        $wrapped = m::mock('DevBoardLib\GithubApiFacade\Repo\RepoFacade');
55
        $wrapped->shouldReceive('fetchAllBranches')
56
            ->andReturn($this->getDataProvider()->getAllBranches());
57
58
        $target   = $this->createFacade($wrapped);
59
        $branches = $target->fetchAllBranches();
60
61
        foreach ($branches as $branch) {
62
            self::assertInstanceOf(
63
                'DevBoardLib\GithubCore\Branch\GithubBranchSource',
64
                $branch
65
            );
66
        }
67
    }
68
69 View Code Duplication
    public function testFetchAllTags()
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...
70
    {
71
        $wrapped = m::mock('DevBoardLib\GithubApiFacade\Repo\RepoFacade');
72
        $wrapped->shouldReceive('fetchAllTags')
73
            ->andReturn($this->getDataProvider()->getAllTagNames());
74
75
        $target   = $this->createFacade($wrapped);
76
        $branches = $target->fetchAllTags();
77
78
        foreach ($branches as $branch) {
79
            self::assertInstanceOf(
80
                'DevBoardLib\GithubCore\Tag\GithubTagSource',
81
                $branch
82
            );
83
        }
84
    }
85
86 View Code Duplication
    public function testFetchCommit()
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...
87
    {
88
        $wrapped = m::mock('DevBoardLib\GithubApiFacade\Repo\RepoFacade');
89
        $wrapped->shouldReceive('fetchCommit')
90
            ->with('sha123')
91
            ->andReturn($this->getDataProvider()->getCommit());
92
93
        $target = $this->createFacade($wrapped);
94
95
        self::assertInstanceOf(
96
            'DevBoardLib\GithubCore\Commit\GithubCommitSource',
97
            $target->fetchCommit('sha123')
98
        );
99
    }
100
101
    /**
102
     */
103 View Code Duplication
    public function testFetchCommitStatus()
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...
104
    {
105
        $wrapped = m::mock('DevBoardLib\GithubApiFacade\Repo\RepoFacade');
106
        $wrapped->shouldReceive('fetchCommitStatus')
107
            ->with('sha123')
108
            ->andReturn($this->getDataProvider()->getCommitStatus());
109
110
        $target = $this->createFacade($wrapped);
111
112
        foreach ($target->fetchCommitStatus('sha123') as $status) {
113
            self::assertInstanceOf(
114
                'DevBoardLib\GithubCore\CommitStatus\GithubCommitStatusSource',
115
                $status
116
            );
117
        }
118
    }
119
120 View Code Duplication
    public function testFetchCommitStatuses()
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...
121
    {
122
        $wrapped = m::mock('DevBoardLib\GithubApiFacade\Repo\RepoFacade');
123
        $wrapped->shouldReceive('fetchCommitStatuses')
124
            ->with('sha123')
125
            ->andReturn($this->getDataProvider()->getCommitStatuses());
126
127
        $target = $this->createFacade($wrapped);
128
129
        foreach ($target->fetchCommitStatuses('sha123') as $status) {
130
            self::assertInstanceOf(
131
                'DevBoardLib\GithubCore\CommitStatus\GithubCommitStatusSource',
132
                $status
133
            );
134
        }
135
    }
136
    //
137
    //
138
    //
139
    //
140
141 View Code Duplication
    public function testFetchAllPullRequests()
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...
142
    {
143
        $wrapped = m::mock('DevBoardLib\GithubApiFacade\Repo\RepoFacade');
144
        $wrapped->shouldReceive('fetchAllPullRequests')
145
            ->andReturn($this->getDataProvider()->getAllPullRequests());
146
147
        $target       = $this->createFacade($wrapped);
148
        $pullRequests = $target->fetchAllPullRequests();
149
150
        foreach ($pullRequests as $pullRequest) {
151
            self::assertInstanceOf(
152
                'DevBoardLib\GithubCore\PullRequest\GithubPullRequestSource',
153
                $pullRequest
154
            );
155
        }
156
    }
157
158 View Code Duplication
    public function testFetchAllMilestones()
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...
159
    {
160
        $wrapped = m::mock('DevBoardLib\GithubApiFacade\Repo\RepoFacade');
161
        $wrapped->shouldReceive('fetchAllMilestones')
162
            ->andReturn($this->getDataProvider()->getAllMilestones());
163
164
        $target = $this->createFacade($wrapped);
165
166
        $milestones = $target->fetchAllMilestones();
167
168
        foreach ($milestones as $milestone) {
169
            self::assertInstanceOf(
170
                'DevBoardLib\GithubCore\Milestone\GithubMilestoneSource',
171
                $milestone
172
            );
173
        }
174
    }
175
176 View Code Duplication
    public function testFetchAllIssues()
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...
177
    {
178
        $wrapped = m::mock('DevBoardLib\GithubApiFacade\Repo\RepoFacade');
179
180
        $wrapped->shouldReceive('fetchAllIssues')
181
            ->andReturn($this->getDataProvider()->getAllIssues());
182
183
        $target = $this->createFacade($wrapped);
184
185
        $issues = $target->fetchAllIssues();
186
187
        foreach ($issues as $issue) {
188
            self::assertInstanceOf(
189
                'DevBoardLib\GithubCore\Issue\GithubIssueSource',
190
                $issue
191
            );
192
        }
193
    }
194
195
    /**
196
     * @param $wrapped
197
     *
198
     * @return SimpleRepoFacade
199
     */
200
    protected function createFacade($wrapped)
201
    {
202
        return new SimpleRepoFacade(
203
            $wrapped,
204
            new GithubRepoConverter($this->provideTestRepo()),
205
            new GithubBranchConverter($this->provideTestRepo()),
206
            new GithubTagConverter($this->provideTestRepo()),
207
            new GithubPullRequestConverter($this->provideTestRepo()),
208
            new GithubCommitConverter($this->provideTestRepo()),
209
            new GithubCommitStatusConverter($this->provideTestRepo()),
210
            new GithubIssueConverter($this->provideTestRepo()),
211
            new GithubMilestoneConverter($this->provideTestRepo())
212
        );
213
    }
214
215
    /**
216
     * @return SampleDataProvider
217
     */
218
    protected function getDataProvider()
219
    {
220
        return new SampleDataProvider();
221
    }
222
223
    /**
224
     * @return m\MockInterface
225
     */
226
    protected function provideTestRepo()
227
    {
228
        $repo   = m::mock('DevBoardLib\GithubCore\Repo\GithubRepo');
229
        $repoId = m::mock('DevBoardLib\GithubCore\Repo\GithubRepoId');
230
231
        $repo->shouldReceive('getId')->andReturn($repoId);
232
233
        return $repo;
234
    }
235
}
236