-
Notifications
You must be signed in to change notification settings - Fork 2
/
BranchesTest.php
134 lines (131 loc) · 4.26 KB
/
BranchesTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
<?php
use PHPUnit\Framework\TestCase;
class BranchesTest extends TestCase
{
/**
* @dataProvider provideBranches
*/
public function testBranches(
array $expected,
string $defaultBranch,
string $githubRepository,
string $composerJson = '',
string $branchesJson = '[]',
string $tagsJson = '[]'
) {
$expectException = $expected === ['__exception__'];
if ($expectException) {
$this->expectException(Exception::class);
}
try {
if ($composerJson) {
file_put_contents('__composer.json', $composerJson);
}
file_put_contents('__branches.json', $branchesJson);
file_put_contents('__tags.json', $tagsJson);
$actual = branches(
$defaultBranch,
$githubRepository,
$branchesJson,
$tagsJson
);
if (!$expectException) {
$this->assertSame($expected, $actual);
}
} finally {
if ($composerJson) {
unlink('__composer.json');
}
unlink('__branches.json');
unlink('__tags.json');
}
}
public function provideBranches()
{
// Note: Most scenarios are tested upstream in the supported-modules repo.
// We just need to check here that we're passing stuff through in an expected way
// and any logic/exception unique to this repo
return [
'5.1.0-beta1, CMS 6 branch detected on silverstripe/framework' => [
'expected' => ['4.13', '4', '5.0', '5.1', '5', '6'],
'defaultBranch' => '5',
'githubRepository' => 'lorem/ipsum',
'composerJson' => <<<EOT
{
"require": {
"silverstripe/framework": "^5.0"
}
}
EOT,
'branchesJson' => <<<EOT
[
{"name": "3"},
{"name": "3.6"},
{"name": "3.7"},
{"name": "4"},
{"name": "4.10"},
{"name": "4.11"},
{"name": "4.12"},
{"name": "4.13"},
{"name": "5"},
{"name": "5.0"},
{"name": "5.1"},
{"name": "6"}
]
EOT,
'tagsJson' => <<<EOT
[
{"name": "5.1.0-beta1"},
{"name": "5.0.9"},
{"name": "4.13.11"},
{"name": "4.12.11"},
{"name": "4.11.11"},
{"name": "4.10.11"},
{"name": "3.7.4"}
]
EOT,
],
'More than 6 branches exception' => [
'expected' => ['__exception__'],
'defaultBranch' => '5',
'githubRepository' => 'lorem/ipsum',
'composerJson' => <<<EOT
{
"require": {
"silverstripe/framework": "^5.0"
}
}
EOT,
'branchesJson' => <<<EOT
[
{"name": "3"},
{"name": "3.6"},
{"name": "3.7"},
{"name": "4"},
{"name": "4.10"},
{"name": "4.11"},
{"name": "4.12"},
{"name": "4.13"},
{"name": "5"},
{"name": "5.0"},
{"name": "5.1"},
{"name": "5.2"},
{"name": "6"}
]
EOT,
'tagsJson' => <<<EOT
[
{"name": "5.2.0-beta1"},
{"name": "5.1.0-beta1"},
{"name": "5.0.9"},
{"name": "4.13.11"},
{"name": "4.12.11"},
{"name": "4.11.11"},
{"name": "4.10.11"},
{"name": "3.7.4"}
]
EOT,
],
];
}
}