-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVersionTest.php
More file actions
158 lines (140 loc) · 5.72 KB
/
Copy pathVersionTest.php
File metadata and controls
158 lines (140 loc) · 5.72 KB
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
<?php
namespace Tests\Koded\Stdlib;
use PHPUnit\Framework\TestCase;
class VersionTest extends TestCase
{
public function test_get_complete_version_for_version_file()
{
$this->assertSame(
file_get_contents(__DIR__ . '/../VERSION'),
get_complete_version([])[0],
'Should read from VERSION file in the project root'
);
}
/**
* Converts the version array to string.
*
* @dataProvider versions
*/
public function test_version_string($index, $version, $result)
{
$this->assertSame($version, get_version($result), '(array -> string) #' . $index);
}
/**
* Get the version array from VERSION file.
*/
public function test_version_file()
{
$version = get_complete_version([]);
$this->assertCount(3, $version);
}
public function test_major_verison()
{
$major = get_major_version([1, 0, 0]);
$this->assertSame(1, $major);
}
/**
* Converts the string to array version.
*
* @dataProvider versions
*/
public function test_version_array($index, $version, $result)
{
$this->assertSame($result, get_version_array($version), '(string -> array) #' . $index);
}
/**
* Converts the string to array version.
*
* @dataProvider moreVersions
*/
public function test_more_version_array($index, $version, $result)
{
$this->assertSame($result, get_version_array($version), '(string -> array) #' . $index);
}
/**
* @dataProvider invalidVersions
*/
public function test_invalid_versions($index, $version)
{
$this->assertSame(INVALID_VERSION_ARRAY, get_version_array($version), 'Data row #' . $index);
}
/**
* Special case: if pre-build is alpha with no meta, git's latest CHANGESET is appended as metadata
*/
public function test_alpha_pre_release_with_zero_build()
{
if (!file_exists(__DIR__ . '/../VERSION')) {
$this->markTestSkipped('The VERSION file is not provided, test is skipped');
}
$this->assertMatchesRegularExpression('~(3.0.0-alpha)\+[0-9]{14}~', get_version(['3.0.0', 'alpha', '0']));
$this->assertMatchesRegularExpression('~(3.0.0-ALPHA)\+[0-9]{14}~', get_version(['3.0.0', 'ALPHA', '0']));
}
/*
*
* Data providers
*
*/
public function versions()
{
return [
// X.Y.Z
[1, '1.0.0', ['1.0.0', '0', '0']],
[2, '2.11.3', ['2.11.3', '0', '0']],
// with pre-release and (optional) number
[3, '1.10.0-alpha.1', ['1.10.0', 'alpha.1', '0']],
[4, '1.0.0-beta', ['1.0.0', 'beta', '0']],
[5, '1.0.0-rc.5', ['1.0.0', 'rc.5', '0']],
[6, '1.0.0-ALPHA+8', ['1.0.0', 'ALPHA', '8']],
// undefined pre-release with build-metadata
[7, '1.7.0-final', ['1.7.0', 'final', '0']],
[8, '1.0.0+final', ['1.0.0', '0', 'final']],
// weirdos
[9, '4.0.0-beta+exp.sha.5114f85', ['4.0.0', 'beta', 'exp.sha.5114f85']],
[10, '4.0.0-2.3.7.92+7.5.12', ['4.0.0', '2.3.7.92', '7.5.12']],
[11, '1.0.0-alpha.beta+foo', ['1.0.0', 'alpha.beta', 'foo']],
[12, '2.9.2+zdfsg1-4ubuntu0.2', ['2.9.2', '0', 'zdfsg1-4ubuntu0.2']],
];
}
public function moreVersions()
{
return [
[1, '0.0.4', ['0.0.4', '0', '0']],
[2, '1.2.3', ['1.2.3', '0', '0']],
[3, '10.20.30', ['10.20.30', '0', '0']],
[4, '1.1.2-prerelease+meta', ['1.1.2', 'prerelease', 'meta']],
[5, '1.1.2+meta', ['1.1.2', '0', 'meta']],
[6, '1.1.2+meta-valid', ['1.1.2', '0', 'meta-valid']],
[7, '1.0.0-alpha', ['1.0.0', 'alpha', '0']],
[8, '1.0.0-beta', ['1.0.0', 'beta', '0']],
[9, '1.0.0-alpha.beta', ['1.0.0', 'alpha.beta', '0']],
[10, '1.0.0-alpha.beta.1', ['1.0.0', 'alpha.beta.1', '0']],
[11, '1.0.0-alpha.1', ['1.0.0', 'alpha.1', '0']],
[12, '1.0.0-alpha0.valid', ['1.0.0', 'alpha0.valid', '0']],
[13, '1.0.0-alpha.0valid', ['1.0.0', 'alpha.0valid', '0']],
[14, '1.0.0-alpha-a.b-c-somethinglong+build.1-aef.1-its-okay', ['1.0.0', 'alpha-a.b-c-somethinglong', 'build.1-aef.1-its-okay']],
[15, '1.0.0-rc.1+build.1', ['1.0.0', 'rc.1', 'build.1']],
[16, '2.0.0-rc.1+build.123', ['2.0.0', 'rc.1', 'build.123']],
[17, '1.2.3-beta', ['1.2.3', 'beta', '0']],
[18, '10.2.3-DEV-SNAPSHOT', ['10.2.3', 'DEV-SNAPSHOT', '0']],
[19, '1.2.3-SNAPSHOT-123', ['1.2.3', 'SNAPSHOT-123', '0']],
[20, '2.0.0+build.1848', ['2.0.0', '0', 'build.1848']],
[21, '2.0.1-alpha.1227', ['2.0.1', 'alpha.1227', '0']],
[22, '1.2.3----RC-SNAPSHOT.12.9.1--.12+788', ['1.2.3', '---RC-SNAPSHOT.12.9.1--.12', '788']],
[23, '1.2.3----R-S.12.9.1--.12+meta', ['1.2.3', '---R-S.12.9.1--.12', 'meta']],
[24, '1.2.3----RC-SNAPSHOT.12.9.1--.12', ['1.2.3', '---RC-SNAPSHOT.12.9.1--.12', '0']],
[25, '1.0.0+0.build.1-rc.10000aaa-kk-0.1', ['1.0.0', '0', '0.build.1-rc.10000aaa-kk-0.1']],
[26, '99999999999999999999999.999999999999999999.99999999999999999', ['99999999999999999999999.999999999999999999.99999999999999999', '0', '0']],
[27, '1.0.0-0A.is.legal', ['1.0.0', '0A.is.legal', '0']],
];
}
public function invalidVersions()
{
return [
[13, '1.0', INVALID_VERSION_ARRAY],
[14, '2', INVALID_VERSION_ARRAY],
[15, '-1', INVALID_VERSION_ARRAY],
[16, '-2.0.1', INVALID_VERSION_ARRAY],
[17, '2.0.-1', INVALID_VERSION_ARRAY],
];
}
}