Test Failed
Push — master ( 440ce5...0cdbc1 )
by Siad
07:01
created

VersionTaskTest::testPropFile()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php
2
3
/*
4
 *
5
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
6
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
7
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
8
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
9
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
10
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
11
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
12
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
13
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
14
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
15
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
16
 *
17
 * This software consists of voluntary contributions made by many individuals
18
 * and is licensed under the LGPL. For more information please see
19
 * <http://phing.info>.
20
 */
21
22
/**
23
 * @author Michiel Rook <[email protected]>
24
 * @package phing.tasks.ext
25
 */
26
class VersionTaskTest extends BuildFileTest
27
{
28
    public function setUp(): void
29
    {
30
        $this->configureProject(PHING_TEST_BASE . "/etc/tasks/ext/version.xml");
0 ignored issues
show
Bug introduced by
The constant PHING_TEST_BASE was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
31
    }
32
33
    public function tearDown(): void
34
    {
35
        if (file_exists(PHING_TEST_BASE . "/etc/tasks/ext/" . 'build.version')) {
0 ignored issues
show
Bug introduced by
The constant PHING_TEST_BASE was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
36
            unlink(PHING_TEST_BASE . "/etc/tasks/ext/" . 'build.version');
37
        }
38
39
        if (file_exists(PHING_TEST_BASE . "/etc/tasks/ext/" . 'property.version')) {
40
            unlink(PHING_TEST_BASE . "/etc/tasks/ext/" . 'property.version');
41
        }
42
    }
43
44
    public function testBugfix()
45
    {
46
        $this->expectLog("testBugfix", "1.0.1");
47
    }
48
49
    public function testMinor()
50
    {
51
        $this->expectLog("testMinor", "1.1.0");
52
    }
53
54
    public function testMajor()
55
    {
56
        $this->expectLog("testMajor", "2.0.0");
57
    }
58
59
    public function testDefault()
60
    {
61
        $this->executeTarget(__FUNCTION__);
62
        $this->assertPropertyEquals('build.version', '1.0.0');
63
        $this->assertFileExists(PHING_TEST_BASE . "/etc/tasks/ext/" . 'build.version', 'File not found');
0 ignored issues
show
Bug introduced by
The constant PHING_TEST_BASE was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
64
    }
65
66
    public function testPropFile()
67
    {
68
        $this->executeTarget(__FUNCTION__);
69
        $this->assertPropertyEquals('propfile.version', '4.5.5');
70
        $this->assertFileExists(PHING_TEST_BASE . "/etc/tasks/ext/" . 'property.version', 'File not found');
0 ignored issues
show
Bug introduced by
The constant PHING_TEST_BASE was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
71
    }
72
73
    public function testPropFileWithDefaultProperty()
74
    {
75
        $this->executeTarget(__FUNCTION__);
76
        $this->assertPropertyEquals('build.version', '4.5.5');
77
        $this->assertFileExists(PHING_TEST_BASE . "/etc/tasks/ext/" . 'build.version', 'File not found');
0 ignored issues
show
Bug introduced by
The constant PHING_TEST_BASE was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
78
    }
79
80
    public function testWithStartingVersion()
81
    {
82
        $this->executeTarget(__FUNCTION__);
83
        $this->assertPropertyEquals('build.version', '1.0.1');
84
        $this->assertFileExists(PHING_TEST_BASE . "/etc/tasks/ext/" . 'build.version', 'File not found');
0 ignored issues
show
Bug introduced by
The constant PHING_TEST_BASE was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
85
    }
86
87
    /**
88
     * Testing \VersionTask::getVersion
89
     *
90
     * @dataProvider versionProvider
91
     *
92
     */
93
    public function testGetVersionMethod($releaseType, $version, $expectedVersion)
94
    {
95
        $versionTask = new VersionTask();
96
        $versionTask->setReleasetype($releaseType);
97
98
        $reflector = new \ReflectionObject($versionTask);
99
        $method = $reflector->getMethod('getVersion');
100
        $method->setAccessible(true);
101
102
        $newVersion = $method->invoke($versionTask, $version);
103
        $this->assertSame($expectedVersion, $newVersion);
104
    }
105
106
    public function versionProvider()
107
    {
108
        return [
109
            [VersionTask::RELEASETYPE_MAJOR, null, '1.0.0'],
110
            [VersionTask::RELEASETYPE_MAJOR, '', '1.0.0'],
111
            [VersionTask::RELEASETYPE_MAJOR, 'x', '1.0.0'],
112
            [VersionTask::RELEASETYPE_MAJOR, 'v', 'v1.0.0'],
113
            [VersionTask::RELEASETYPE_MAJOR, '0', '1.0.0'],
114
            [VersionTask::RELEASETYPE_MAJOR, 'v0', 'v1.0.0'],
115
            [VersionTask::RELEASETYPE_MAJOR, 'a3', '1.0.0'],
116
            [VersionTask::RELEASETYPE_MAJOR, 'v3', 'v4.0.0'],
117
            [VersionTask::RELEASETYPE_MAJOR, 'qsdf', '1.0.0'],
118
            [VersionTask::RELEASETYPE_MAJOR, 'vvvv', 'v1.0.0'],
119
            [VersionTask::RELEASETYPE_MAJOR, '0.6', '1.0.0'],
120
            [VersionTask::RELEASETYPE_MAJOR, 'v0.6', 'v1.0.0'],
121
            [VersionTask::RELEASETYPE_MAJOR, '5.0', '6.0.0'],
122
            [VersionTask::RELEASETYPE_MAJOR, 'v5.0', 'v6.0.0'],
123
            [VersionTask::RELEASETYPE_MAJOR, '5.5', '6.0.0'],
124
            [VersionTask::RELEASETYPE_MAJOR, 'v5.5', 'v6.0.0'],
125
            [VersionTask::RELEASETYPE_MAJOR, '0.0.0', '1.0.0'],
126
            [VersionTask::RELEASETYPE_MAJOR, 'v0.0.0', 'v1.0.0'],
127
            [VersionTask::RELEASETYPE_MAJOR, '0.0.15', '1.0.0'],
128
            [VersionTask::RELEASETYPE_MAJOR, 'v0.0.15', 'v1.0.0'],
129
            [VersionTask::RELEASETYPE_MAJOR, '0.1.15', '1.0.0'],
130
            [VersionTask::RELEASETYPE_MAJOR, 'v0.1.15', 'v1.0.0'],
131
            [VersionTask::RELEASETYPE_MAJOR, '7.0.15', '8.0.0'],
132
            [VersionTask::RELEASETYPE_MAJOR, 'v7.0.15', 'v8.0.0'],
133
            [VersionTask::RELEASETYPE_MAJOR, '2.3.4', '3.0.0'],
134
            [VersionTask::RELEASETYPE_MAJOR, 'v2.3.4', 'v3.0.0'],
135
            [VersionTask::RELEASETYPE_MAJOR, '2-RC1', '3.0.0'],
136
            [VersionTask::RELEASETYPE_MAJOR, 'v2-RC1', 'v3.0.0'],
137
            [VersionTask::RELEASETYPE_MAJOR, '2.3-RC1', '3.0.0'],
138
            [VersionTask::RELEASETYPE_MAJOR, 'v2.3-RC1', 'v3.0.0'],
139
            [VersionTask::RELEASETYPE_MAJOR, '2.3.4-RC1', '3.0.0'],
140
            [VersionTask::RELEASETYPE_MAJOR, 'v2.3.4-RC1', 'v3.0.0'],
141
            [VersionTask::RELEASETYPE_MAJOR, '2.3v654.4', '3.0.0'],
142
            [VersionTask::RELEASETYPE_MAJOR, 'v2.3v56465.4-RC1', 'v3.0.0'],
143
            [VersionTask::RELEASETYPE_MAJOR, '2.hello.world', '3.0.0'],
144
            [VersionTask::RELEASETYPE_MAJOR, 'v2.hello.world', 'v3.0.0'],
145
            [VersionTask::RELEASETYPE_MAJOR, 'hello.world.3', '1.0.0'],
146
            [VersionTask::RELEASETYPE_MAJOR, 'vhello.world.3', 'v1.0.0'],
147
            [VersionTask::RELEASETYPE_MINOR, null, '0.1.0'],
148
            [VersionTask::RELEASETYPE_MINOR, '', '0.1.0'],
149
            [VersionTask::RELEASETYPE_MINOR, 'x', '0.1.0'],
150
            [VersionTask::RELEASETYPE_MINOR, 'v', 'v0.1.0'],
151
            [VersionTask::RELEASETYPE_MINOR, '0', '0.1.0'],
152
            [VersionTask::RELEASETYPE_MINOR, 'v0', 'v0.1.0'],
153
            [VersionTask::RELEASETYPE_MINOR, 'a3', '0.1.0'],
154
            [VersionTask::RELEASETYPE_MINOR, 'v3', 'v3.1.0'],
155
            [VersionTask::RELEASETYPE_MINOR, 'qsdf', '0.1.0'],
156
            [VersionTask::RELEASETYPE_MINOR, 'vvvv', 'v0.1.0'],
157
            [VersionTask::RELEASETYPE_MINOR, '0.6', '0.7.0'],
158
            [VersionTask::RELEASETYPE_MINOR, 'v0.6', 'v0.7.0'],
159
            [VersionTask::RELEASETYPE_MINOR, '5.0', '5.1.0'],
160
            [VersionTask::RELEASETYPE_MINOR, 'v5.0', 'v5.1.0'],
161
            [VersionTask::RELEASETYPE_MINOR, '5.5', '5.6.0'],
162
            [VersionTask::RELEASETYPE_MINOR, 'v5.5', 'v5.6.0'],
163
            [VersionTask::RELEASETYPE_MINOR, '0.0.0', '0.1.0'],
164
            [VersionTask::RELEASETYPE_MINOR, 'v0.0.0', 'v0.1.0'],
165
            [VersionTask::RELEASETYPE_MINOR, '0.0.15', '0.1.0'],
166
            [VersionTask::RELEASETYPE_MINOR, 'v0.0.15', 'v0.1.0'],
167
            [VersionTask::RELEASETYPE_MINOR, '0.1.15', '0.2.0'],
168
            [VersionTask::RELEASETYPE_MINOR, 'v0.1.15', 'v0.2.0'],
169
            [VersionTask::RELEASETYPE_MINOR, '7.0.15', '7.1.0'],
170
            [VersionTask::RELEASETYPE_MINOR, 'v7.0.15', 'v7.1.0'],
171
            [VersionTask::RELEASETYPE_MINOR, '2.3.4', '2.4.0'],
172
            [VersionTask::RELEASETYPE_MINOR, 'v2.3.4', 'v2.4.0'],
173
            [VersionTask::RELEASETYPE_MINOR, '2-RC1', '2.1.0'],
174
            [VersionTask::RELEASETYPE_MINOR, 'v2-RC1', 'v2.1.0'],
175
            [VersionTask::RELEASETYPE_MINOR, '2.3-RC1', '2.4.0'],
176
            [VersionTask::RELEASETYPE_MINOR, 'v2.3-RC1', 'v2.4.0'],
177
            [VersionTask::RELEASETYPE_MINOR, '2.3.4-RC1', '2.4.0'],
178
            [VersionTask::RELEASETYPE_MINOR, 'v2.3.4-RC1', 'v2.4.0'],
179
            [VersionTask::RELEASETYPE_MINOR, '2.3v654.4', '2.4.0'],
180
            [VersionTask::RELEASETYPE_MINOR, 'v2.3v56465.4-RC1', 'v2.4.0'],
181
            [VersionTask::RELEASETYPE_MINOR, '2.hello.world', '2.1.0'],
182
            [VersionTask::RELEASETYPE_MINOR, 'v2.hello.world', 'v2.1.0'],
183
            [VersionTask::RELEASETYPE_MINOR, 'hello.world.3', '0.1.0'],
184
            [VersionTask::RELEASETYPE_MINOR, 'vhello.world.3', 'v0.1.0'],
185
            [VersionTask::RELEASETYPE_BUGFIX, null, '0.0.1'],
186
            [VersionTask::RELEASETYPE_BUGFIX, '', '0.0.1'],
187
            [VersionTask::RELEASETYPE_BUGFIX, 'x', '0.0.1'],
188
            [VersionTask::RELEASETYPE_BUGFIX, 'v', 'v0.0.1'],
189
            [VersionTask::RELEASETYPE_BUGFIX, '0', '0.0.1'],
190
            [VersionTask::RELEASETYPE_BUGFIX, 'v0', 'v0.0.1'],
191
            [VersionTask::RELEASETYPE_BUGFIX, 'a3', '0.0.1'],
192
            [VersionTask::RELEASETYPE_BUGFIX, 'v3', 'v3.0.1'],
193
            [VersionTask::RELEASETYPE_BUGFIX, 'qsdf', '0.0.1'],
194
            [VersionTask::RELEASETYPE_BUGFIX, 'vvvv', 'v0.0.1'],
195
            [VersionTask::RELEASETYPE_BUGFIX, '0.6', '0.6.1'],
196
            [VersionTask::RELEASETYPE_BUGFIX, 'v0.6', 'v0.6.1'],
197
            [VersionTask::RELEASETYPE_BUGFIX, '5.0', '5.0.1'],
198
            [VersionTask::RELEASETYPE_BUGFIX, 'v5.0', 'v5.0.1'],
199
            [VersionTask::RELEASETYPE_BUGFIX, '5.5', '5.5.1'],
200
            [VersionTask::RELEASETYPE_BUGFIX, 'v5.5', 'v5.5.1'],
201
            [VersionTask::RELEASETYPE_BUGFIX, '0.0.0', '0.0.1'],
202
            [VersionTask::RELEASETYPE_BUGFIX, 'v0.0.0', 'v0.0.1'],
203
            [VersionTask::RELEASETYPE_BUGFIX, '0.0.15', '0.0.16'],
204
            [VersionTask::RELEASETYPE_BUGFIX, 'v0.0.15', 'v0.0.16'],
205
            [VersionTask::RELEASETYPE_BUGFIX, '0.1.15', '0.1.16'],
206
            [VersionTask::RELEASETYPE_BUGFIX, 'v0.1.15', 'v0.1.16'],
207
            [VersionTask::RELEASETYPE_BUGFIX, '7.0.15', '7.0.16'],
208
            [VersionTask::RELEASETYPE_BUGFIX, 'v7.0.15', 'v7.0.16'],
209
            [VersionTask::RELEASETYPE_BUGFIX, '2.3.4', '2.3.5'],
210
            [VersionTask::RELEASETYPE_BUGFIX, 'v2.3.4', 'v2.3.5'],
211
            [VersionTask::RELEASETYPE_BUGFIX, '2-RC1', '2.0.1'],
212
            [VersionTask::RELEASETYPE_BUGFIX, 'v2-RC1', 'v2.0.1'],
213
            [VersionTask::RELEASETYPE_BUGFIX, '2.3-RC1', '2.3.1'],
214
            [VersionTask::RELEASETYPE_BUGFIX, 'v2.3-RC1', 'v2.3.1'],
215
            [VersionTask::RELEASETYPE_BUGFIX, '2.3.4-RC1', '2.3.5'],
216
            [VersionTask::RELEASETYPE_BUGFIX, 'v2.3.4-RC1', 'v2.3.5'],
217
            [VersionTask::RELEASETYPE_BUGFIX, '2.3v654.4', '2.3.1'],
218
            [VersionTask::RELEASETYPE_BUGFIX, 'v2.3v56465.4-RC1', 'v2.3.1'],
219
            [VersionTask::RELEASETYPE_BUGFIX, '2.hello.world', '2.0.1'],
220
            [VersionTask::RELEASETYPE_BUGFIX, 'v2.hello.world', 'v2.0.1'],
221
            [VersionTask::RELEASETYPE_BUGFIX, 'hello.world.3', '0.0.1'],
222
            [VersionTask::RELEASETYPE_BUGFIX, 'vhello.world.3', 'v0.0.1'],
223
        ];
224
    }
225
}
226