These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
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); |
||
0 ignored issues
–
show
|
|||
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 |
If you suppress an error, we recommend checking for the error condition explicitly: