1
|
|
|
<?php |
2
|
|
|
namespace tests\DevBoardLib\GithubObjectApiFacade\Repo; |
3
|
|
|
|
4
|
|
|
use DevBoardLib\GithubObjectApiFacade\Repo\Issue\Converter\GithubIssueConverter; |
5
|
|
|
use DevBoardLib\GithubObjectApiFacade\Repo\Milestone\Converter\GithubMilestoneConverter; |
6
|
|
|
use DevBoardLib\GithubObjectApiFacade\Repo\SimpleRepoFacade; |
7
|
|
|
use Mockery as m; |
8
|
|
|
use tests\DevBoardLib\GithubObjectApiFacade\SampleDataProvider; |
9
|
|
|
|
10
|
|
|
class SimpleRepoFacadeTest extends \PHPUnit_Framework_TestCase |
11
|
|
|
{ |
12
|
|
View Code Duplication |
public function testFetchAllMilestones() |
|
|
|
|
13
|
|
|
{ |
14
|
|
|
$wrapped = m::mock('DevBoardLib\GithubApiFacade\Repo\RepoFacade'); |
15
|
|
|
$wrapped->shouldReceive('fetchAllMilestones') |
16
|
|
|
->andReturn($this->getDataProvider()->getAllMilestones()); |
17
|
|
|
|
18
|
|
|
$target = new SimpleRepoFacade( |
19
|
|
|
$wrapped, |
20
|
|
|
new GithubIssueConverter($this->provideTestRepo()), |
21
|
|
|
new GithubMilestoneConverter($this->provideTestRepo()) |
22
|
|
|
); |
23
|
|
|
|
24
|
|
|
$milestones = $target->fetchAllMilestones(); |
25
|
|
|
|
26
|
|
|
foreach ($milestones as $milestone) { |
27
|
|
|
self::assertInstanceOf( |
28
|
|
|
'DevBoardLib\GithubObjectApiFacade\Repo\Milestone\GithubMilestoneSource', |
29
|
|
|
$milestone |
30
|
|
|
); |
31
|
|
|
} |
32
|
|
|
} |
33
|
|
|
|
34
|
|
View Code Duplication |
public function testFetchAllIssues() |
|
|
|
|
35
|
|
|
{ |
36
|
|
|
$wrapped = m::mock('DevBoardLib\GithubApiFacade\Repo\RepoFacade'); |
37
|
|
|
|
38
|
|
|
$wrapped->shouldReceive('fetchAllIssues') |
39
|
|
|
->andReturn($this->getDataProvider()->getAllIssues()); |
40
|
|
|
|
41
|
|
|
$target = new SimpleRepoFacade( |
42
|
|
|
$wrapped, |
43
|
|
|
new GithubIssueConverter($this->provideTestRepo()), |
44
|
|
|
new GithubMilestoneConverter($this->provideTestRepo()) |
45
|
|
|
); |
46
|
|
|
|
47
|
|
|
$issues = $target->fetchAllIssues(); |
48
|
|
|
|
49
|
|
|
foreach ($issues as $issue) { |
50
|
|
|
self::assertInstanceOf( |
51
|
|
|
'DevBoardLib\GithubObjectApiFacade\Repo\Issue\GithubIssueSource', |
52
|
|
|
$issue |
53
|
|
|
); |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
protected function getDataProvider() |
58
|
|
|
{ |
59
|
|
|
return new SampleDataProvider(); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
protected function provideTestRepo() |
63
|
|
|
{ |
64
|
|
|
return m::mock('DevBoardLib\GithubCore\Repo\GithubRepo'); |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|
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.