44
55namespace Syntatis \Tests \Commands ;
66
7+ use Syntatis \Tests \Commands \CommandTestCase ;
78use PHPUnit \Framework \TestCase ;
89use Symfony \Component \Console \Tester \CommandTester ;
910use Syntatis \Version \CLI \Commander ;
1011
1112use function sprintf ;
1213
13- class IncrementCommandTest extends TestCase
14+ class IncrementCommandTest extends CommandTestCase
1415{
1516 private Commander $ commander ;
1617 private CommandTester $ tester ;
@@ -30,7 +31,7 @@ public function testInvalidVersionArgument(string $version): void
3031
3132 self ::assertStringContainsString (
3233 sprintf ("[ERROR] Version string '%s' is not valid and cannot be parsed " , $ version ),
33- $ this ->tester ->getDisplay (),
34+ self :: normalizeOutput ( $ this ->tester ->getDisplay () ),
3435 );
3536 }
3637
@@ -40,7 +41,7 @@ public function testIncrementPatch(): void
4041
4142 self ::assertStringContainsString (
4243 '1.0.1 ' ,
43- $ this ->tester ->getDisplay (),
44+ self :: normalizeOutput ( $ this ->tester ->getDisplay () ),
4445 );
4546 }
4647
@@ -50,7 +51,7 @@ public function testIncrementMinor(): void
5051
5152 self ::assertStringContainsString (
5253 '1.1.0 ' ,
53- $ this ->tester ->getDisplay (),
54+ self :: normalizeOutput ( $ this ->tester ->getDisplay () ),
5455 );
5556 }
5657
@@ -60,7 +61,7 @@ public function testIncrementMajor(): void
6061
6162 self ::assertStringContainsString (
6263 '2.0.0 ' ,
63- $ this ->tester ->getDisplay (),
64+ self :: normalizeOutput ( $ this ->tester ->getDisplay () ),
6465 );
6566 }
6667
@@ -70,7 +71,7 @@ public function testIncrementWithBuildMetadata(): void
7071
7172 self ::assertStringContainsString (
7273 '1.0.1+123 ' ,
73- $ this ->tester ->getDisplay (),
74+ self :: normalizeOutput ( $ this ->tester ->getDisplay () ),
7475 );
7576 }
7677
@@ -80,7 +81,46 @@ public function testIncrementWithPreRelease(): void
8081
8182 self ::assertStringContainsString (
8283 '1.0.1-beta ' ,
83- $ this ->tester ->getDisplay (),
84+ self ::normalizeOutput ($ this ->tester ->getDisplay ()),
85+ );
86+ }
87+
88+ /**
89+ * @dataProvider dataIncrementPrerelease
90+ */
91+ public function testIncrementPrerelease (string $ version , string $ expect ): void
92+ {
93+ $ this ->tester ->execute (['version ' => $ version , '--part ' => 'prerelease ' ]);
94+
95+ self ::assertStringContainsString (
96+ $ expect ,
97+ self ::normalizeOutput ($ this ->tester ->getDisplay ()),
98+ );
99+ }
100+
101+ public static function dataIncrementPrerelease (): iterable
102+ {
103+ yield ['1.0.0-beta ' , '1.0.0-beta.1 ' ];
104+ yield ['1.0.0-alpha.1 ' , '1.0.0-alpha.2 ' ];
105+ }
106+
107+ public function testIncrementPrereleaseWithPreTag (): void
108+ {
109+ $ this ->tester ->execute (['version ' => '1.0.0-beta ' , '--part ' => 'prerelease ' , '--pre ' => 'rc ' ]);
110+
111+ self ::assertStringContainsString (
112+ "[ERROR] Specifying a prerelease tag when incrementing the prerelease part is not allowed. " ,
113+ self ::normalizeOutput ($ this ->tester ->getDisplay ()),
114+ );
115+ }
116+
117+ public function testIncrementPrereleaseWithoutReleaseTag (): void
118+ {
119+ $ this ->tester ->execute (['version ' => '1.0.0 ' , '--part ' => 'prerelease ' ]);
120+
121+ self ::assertStringContainsString (
122+ "[ERROR] Unable to increment prerelease on a version without a prerelease tag. " ,
123+ self ::normalizeOutput ($ this ->tester ->getDisplay ()),
84124 );
85125 }
86126
0 commit comments