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