1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use AspectMock\Test as test; |
|
|
|
|
4
|
|
|
|
5
|
|
|
class SemVerTest extends \Codeception\TestCase\Test |
6
|
|
|
{ |
7
|
|
|
public function testSemver() |
8
|
|
|
{ |
9
|
|
|
$semver = test::double('Robo\Task\Development\SemVer', ['dump' => null]); |
10
|
|
|
$res = (new \Robo\Task\Development\SemVer()) |
11
|
|
|
->increment('major') |
12
|
|
|
->prerelease('RC') |
13
|
|
|
->increment('patch') |
14
|
|
|
->run(); |
15
|
|
|
$this->assertEquals( |
16
|
|
|
'v1.0.1-RC.1', |
17
|
|
|
$res->getMessage()); |
18
|
|
|
$semver->verifyInvoked('dump'); |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
public function testSemverIncrementMinorAfterIncrementedPatch() |
22
|
|
|
{ |
23
|
|
|
$semver = test::double('Robo\Task\Development\SemVer', ['dump' => null]); |
24
|
|
|
$res = (new \Robo\Task\Development\SemVer()) |
25
|
|
|
->increment('patch') |
26
|
|
|
->run(); |
27
|
|
|
$this->assertEquals( |
28
|
|
|
'v0.0.1', |
29
|
|
|
$res->getMessage()); |
30
|
|
|
$res = (new \Robo\Task\Development\SemVer()) |
31
|
|
|
->increment('minor') |
32
|
|
|
->run(); |
33
|
|
|
$this->assertEquals( |
34
|
|
|
'v0.1.0', |
35
|
|
|
$res->getMessage()); |
36
|
|
|
$semver->verifyInvoked('dump'); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function testSemverIncrementMajorAfterIncrementedMinorAndPatch() |
40
|
|
|
{ |
41
|
|
|
$semver = test::double('Robo\Task\Development\SemVer', ['dump' => null]); |
42
|
|
|
$res = (new \Robo\Task\Development\SemVer()) |
43
|
|
|
->increment('patch') |
44
|
|
|
->run(); |
45
|
|
|
$this->assertEquals( |
46
|
|
|
'v0.0.1', |
47
|
|
|
$res->getMessage()); |
48
|
|
|
$res = (new \Robo\Task\Development\SemVer()) |
49
|
|
|
->increment('minor') |
50
|
|
|
->run(); |
51
|
|
|
$this->assertEquals( |
52
|
|
|
'v0.1.0', |
53
|
|
|
$res->getMessage()); |
54
|
|
|
$res = (new \Robo\Task\Development\SemVer()) |
55
|
|
|
->increment('major') |
56
|
|
|
->run(); |
57
|
|
|
$this->assertEquals( |
58
|
|
|
'v1.0.0', |
59
|
|
|
$res->getMessage()); |
60
|
|
|
$semver->verifyInvoked('dump'); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
public function testSemverParseFileWithWindowsLineEndings() |
64
|
|
|
{ |
65
|
|
|
$fixturePath = tempnam(sys_get_temp_dir(), 'semver'); |
66
|
|
|
$semverFile = str_replace("\n", "\r\n", file_get_contents(codecept_data_dir().'.semver')); |
67
|
|
|
file_put_contents($fixturePath, $semverFile); |
68
|
|
|
|
69
|
|
|
$res = (new \Robo\Task\Development\SemVer($fixturePath)) |
70
|
|
|
->run(); |
71
|
|
|
$this->assertEquals( |
72
|
|
|
'v1.0.1-RC.1', |
73
|
|
|
$res->getMessage()); |
74
|
|
|
@unlink($fixturePath); |
|
|
|
|
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
public function testThrowsExceptionWhenIncrementWithWrongParameter() |
78
|
|
|
{ |
79
|
|
|
$this->expectException('Robo\Exception\TaskException'); |
80
|
|
|
$this->expectExceptionMessageRegExp( |
81
|
|
|
'/Bad argument, only one of the following is allowed: major, minor, patch/' |
82
|
|
|
); |
83
|
|
|
$res = (new \Robo\Task\Development\SemVer()) |
84
|
|
|
->increment('wrongParameter'); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
public function testThrowsExceptionWhenSemverFileNotWriteable() |
88
|
|
|
{ |
89
|
|
|
$this->expectException('Robo\Exception\TaskException'); |
90
|
|
|
$this->expectExceptionMessageRegExp( |
91
|
|
|
'/Failed to write semver file./' |
92
|
|
|
); |
93
|
|
|
(new \Robo\Task\Development\SemVer('/.semver')) |
94
|
|
|
->increment('major') |
95
|
|
|
->run(); |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
|
Let’s assume that you have a directory layout like this:
and let’s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/Foo.php
are loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as
OtherDir/Foo.php
does not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php
, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: