1
|
|
|
<?php |
2
|
|
|
namespace tests\DevBoardLib\GithubObjectApiFacade\Repo\CommitStatus\Converter; |
3
|
|
|
|
4
|
|
|
use DevBoardLib\GithubObjectApiFacade\Repo\CommitStatus\Converter\GithubCommitStatusConverter; |
5
|
|
|
use Mockery as m; |
6
|
|
|
use tests\DevBoardLib\GithubObjectApiFacade\SampleDataProvider; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Class GithubCommitStatusConverterTest. |
10
|
|
|
*/ |
11
|
|
|
class GithubCommitStatusConverterTest extends \PHPUnit_Framework_TestCase |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* @dataProvider provideConversionData |
15
|
|
|
* |
16
|
|
|
* @param $repoData |
17
|
|
|
*/ |
18
|
|
|
public function testConvert($repoData) |
19
|
|
|
{ |
20
|
|
|
$repo = $this->provideTestRepo(); |
21
|
|
|
|
22
|
|
|
$target = new GithubCommitStatusConverter($repo); |
23
|
|
|
|
24
|
|
|
self::assertInstanceOf( |
25
|
|
|
'DevBoardLib\GithubCore\CommitStatus\GithubCommitStatusSource', |
26
|
|
|
$target->convert($repoData) |
27
|
|
|
); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @return array |
32
|
|
|
*/ |
33
|
|
|
public function provideConversionData() |
34
|
|
|
{ |
35
|
|
|
$results = []; |
36
|
|
|
$data = $this->getDataProvider()->getCommitStatus(); |
37
|
|
|
|
38
|
|
|
foreach ($data['statuses'] as $status) { |
39
|
|
|
$results[] = [ |
40
|
|
|
array_merge($status, ['sha' => $data['sha']]), |
41
|
|
|
]; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
return $results; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @dataProvider provideConversionDataFromMultipleStatuses |
49
|
|
|
* |
50
|
|
|
* @param $repoData |
51
|
|
|
*/ |
52
|
|
|
public function testConvertFromMultipleStatuses($repoData) |
53
|
|
|
{ |
54
|
|
|
$repo = $this->provideTestRepo(); |
55
|
|
|
|
56
|
|
|
$target = new GithubCommitStatusConverter($repo); |
57
|
|
|
|
58
|
|
|
self::assertInstanceOf( |
59
|
|
|
'DevBoardLib\GithubCore\CommitStatus\GithubCommitStatusSource', |
60
|
|
|
$target->convert($repoData) |
61
|
|
|
); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @return array |
66
|
|
|
*/ |
67
|
|
|
public function provideConversionDataFromMultipleStatuses() |
68
|
|
|
{ |
69
|
|
|
$testData = []; |
70
|
|
|
|
71
|
|
|
foreach ($this->getDataProvider()->getCommitStatuses() as $item) { |
72
|
|
|
$testData[] = [ |
73
|
|
|
array_merge($item, ['sha' => '@todo']), |
74
|
|
|
]; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
return $testData; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @return m\MockInterface |
82
|
|
|
*/ |
83
|
|
|
protected function provideTestRepo() |
84
|
|
|
{ |
85
|
|
|
$repo = m::mock('DevBoardLib\GithubCore\Repo\GithubRepo'); |
86
|
|
|
$repoId = m::mock('DevBoardLib\GithubCore\Repo\GithubRepoId'); |
87
|
|
|
|
88
|
|
|
$repo->shouldReceive('getId')->andReturn($repoId); |
89
|
|
|
|
90
|
|
|
return $repo; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @return SampleDataProvider |
95
|
|
|
*/ |
96
|
|
|
protected function getDataProvider() |
97
|
|
|
{ |
98
|
|
|
return new SampleDataProvider(); |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
|