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