|
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
|
|
|
verify($res->getMessage())->equals('v1.0.1-RC.1'); |
|
16
|
|
|
$semver->verifyInvoked('dump'); |
|
17
|
|
|
} |
|
18
|
|
|
|
|
19
|
|
|
public function testSemverIncrementMinorAfterIncrementedPatch() |
|
20
|
|
|
{ |
|
21
|
|
|
$semver = test::double('Robo\Task\Development\SemVer', ['dump' => null]); |
|
22
|
|
|
$res = (new \Robo\Task\Development\SemVer()) |
|
23
|
|
|
->increment('patch') |
|
24
|
|
|
->run(); |
|
25
|
|
|
verify($res->getMessage())->equals('v0.0.1'); |
|
26
|
|
|
$res = (new \Robo\Task\Development\SemVer()) |
|
27
|
|
|
->increment('minor') |
|
28
|
|
|
->run(); |
|
29
|
|
|
verify($res->getMessage())->equals('v0.1.0'); |
|
30
|
|
|
$semver->verifyInvoked('dump'); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
public function testSemverIncrementMajorAfterIncrementedMinorAndPatch() |
|
34
|
|
|
{ |
|
35
|
|
|
$semver = test::double('Robo\Task\Development\SemVer', ['dump' => null]); |
|
36
|
|
|
$res = (new \Robo\Task\Development\SemVer()) |
|
37
|
|
|
->increment('patch') |
|
38
|
|
|
->run(); |
|
39
|
|
|
verify($res->getMessage())->equals('v0.0.1'); |
|
40
|
|
|
$res = (new \Robo\Task\Development\SemVer()) |
|
41
|
|
|
->increment('minor') |
|
42
|
|
|
->run(); |
|
43
|
|
|
verify($res->getMessage())->equals('v0.1.0'); |
|
44
|
|
|
$res = (new \Robo\Task\Development\SemVer()) |
|
45
|
|
|
->increment('major') |
|
46
|
|
|
->run(); |
|
47
|
|
|
verify($res->getMessage())->equals('v1.0.0'); |
|
48
|
|
|
$semver->verifyInvoked('dump'); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
public function testSemverParseFileWithWindowsLineEndings() |
|
52
|
|
|
{ |
|
53
|
|
|
$fixturePath = tempnam(sys_get_temp_dir(), 'semver'); |
|
54
|
|
|
$semverFile = str_replace("\n", "\r\n", file_get_contents(codecept_data_dir().'.semver')); |
|
55
|
|
|
file_put_contents($fixturePath, $semverFile); |
|
56
|
|
|
|
|
57
|
|
|
$res = (new \Robo\Task\Development\SemVer($fixturePath)) |
|
58
|
|
|
->run(); |
|
59
|
|
|
verify($res->getMessage())->equals('v1.0.1-RC.1'); |
|
60
|
|
|
@unlink($fixturePath); |
|
|
|
|
|
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
public function testThrowsExceptionWhenIncrementWithWrongParameter() |
|
64
|
|
|
{ |
|
65
|
|
|
\PHPUnit_Framework_TestCase::setExpectedExceptionRegExp( |
|
|
|
|
|
|
66
|
|
|
'Robo\Exception\TaskException', |
|
67
|
|
|
'/Bad argument, only one of the following is allowed: major, minor, patch/' |
|
68
|
|
|
); |
|
69
|
|
|
$res = (new \Robo\Task\Development\SemVer()) |
|
|
|
|
|
|
70
|
|
|
->increment('wrongParameter'); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
public function testThrowsExceptionWhenSemverFileNotWriteable() |
|
74
|
|
|
{ |
|
75
|
|
|
\PHPUnit_Framework_TestCase::setExpectedExceptionRegExp( |
|
|
|
|
|
|
76
|
|
|
'Robo\Exception\TaskException', |
|
77
|
|
|
'/Failed to write semver file./' |
|
78
|
|
|
); |
|
79
|
|
|
(new \Robo\Task\Development\SemVer('/.semver')) |
|
80
|
|
|
->increment('major') |
|
81
|
|
|
->run(); |
|
82
|
|
|
} |
|
83
|
|
|
} |
|
84
|
|
|
|
Let’s assume that you have a directory layout like this:
. |-- OtherDir | |-- Bar.php | `-- Foo.php `-- SomeDir `-- Foo.phpand let’s assume the following content of
Bar.php:If both files
OtherDir/Foo.phpandSomeDir/Foo.phpare 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.phpHowever, as
OtherDir/Foo.phpdoes 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: