Skip to content

Commit ab89815

Browse files
committed
Added and updated tests.
1 parent a63ce1a commit ab89815

4 files changed

Lines changed: 421 additions & 18 deletions

File tree

tests/testsuites/HigherLowerTest.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,11 @@ public function test_higher(): void
5454
$version = VersionParser::create($test['version']);
5555
$compare = VersionParser::create($test['compareWith']);
5656

57-
$label = $test['label'] . PHP_EOL .
58-
'Version......: ' . $version->getBuildNumberInt() . ' (' . $test['version'] . ')' . PHP_EOL .
59-
'Higher than..: ' . $compare->getBuildNumberInt() . ' (' . $test['compareWith'] . ')';
57+
$label = $test['label'].PHP_EOL.
58+
'Version......: '.$version->getBuildNumberInt().' ('.$test['version'].')'.PHP_EOL.
59+
'Higher than..: '.$compare->getBuildNumberInt().' ('.$test['compareWith'].')'.PHP_EOL.
60+
print_r($version->toArray(), true).PHP_EOL.
61+
print_r($compare->toArray(), true);
6062

6163
$this->assertSame($test['higher'] === true, $version->isHigherThan($compare), $label);
6264
$this->assertSame($test['higher'] !== true, $version->isLowerThan($compare), $label);

tests/testsuites/ParseTest.php

Lines changed: 142 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,27 @@ public function test_parse(): void
6161
'int' => 999999000201,
6262
'normalized' => '1.0.0'
6363
),
64+
array(
65+
'label' => 'With beta tag, numbered 2, with dot separator',
66+
'version' => '1.0.0-beta.2',
67+
'expected' => 999999.000201,
68+
'int' => 999999000201,
69+
'normalized' => '1.0.0'
70+
),
71+
array(
72+
'label' => 'With beta tag, numbered 2, with hyphen separator',
73+
'version' => '1.0.0-beta-2',
74+
'expected' => 999999.000201,
75+
'int' => 999999000201,
76+
'normalized' => '1.0.0'
77+
),
78+
array(
79+
'label' => 'With beta tag, numbered 2, with underscore separator',
80+
'version' => '1.0.0-beta_2',
81+
'expected' => 999999.000201,
82+
'int' => 999999000201,
83+
'normalized' => '1.0.0'
84+
),
6485
array(
6586
'label' => 'With alpha tag',
6687
'version' => '1.0.0-alpha',
@@ -101,7 +122,7 @@ public function test_parse(): void
101122
foreach ($tests as $test) {
102123
$version = VersionParser::create($test['version']);
103124

104-
$this->assertEquals($test['expected'], $version->getBuildNumber(), $test['label']);
125+
$this->assertEquals($test['expected'], $version->getBuildNumber(), $test['label'].print_r($version->toArray(), true));
105126
$this->assertEquals($test['int'], $version->getBuildNumberInt(), $test['label']);
106127
$this->assertEquals($test['normalized'], $version->getVersion(), $test['label']);
107128
}
@@ -203,7 +224,7 @@ public function test_getTag(): void
203224
foreach ($tests as $test) {
204225
$version = VersionParser::create($test['version']);
205226

206-
$label = $test['label'] . ' (' . $test['version'] . ')';
227+
$label = $test['label'].' ('.$test['version'].')'.PHP_EOL.print_r($version->toArray(), true);
207228

208229
$this->assertEquals($test['expected'], $version->getTag(), $label);
209230
$this->assertEquals($test['type'], $version->getTagType(), $label);
@@ -215,23 +236,25 @@ public function test_no_tag(): void
215236
{
216237
$version = VersionParser::create('1.0');
217238

218-
$this->assertFalse($version->isAlpha());
219-
$this->assertFalse($version->isBeta());
220-
$this->assertFalse($version->isReleaseCandidate());
221239
$this->assertFalse($version->hasTag());
222-
$this->assertFalse($version->isSnapshot());
223240
}
224241

225-
public function test_tag_beta(): void
242+
public function test_tag_info() : void
226243
{
227-
$version = VersionParser::create('1.0-beta2');
244+
$version = VersionParser::create('1.0-beta11');
228245

229-
$this->assertTrue($version->isBeta());
230-
$this->assertFalse($version->isAlpha());
231-
$this->assertFalse($version->isReleaseCandidate());
246+
$tag = $version->getTagInfo();
247+
$this->assertNotNull($tag);
248+
249+
$testLabel = print_r($version->toArray(), true);
250+
251+
$this->assertTrue($tag->isBeta(), $testLabel);
252+
$this->assertFalse($tag->isAlpha(), $testLabel);
253+
$this->assertFalse($tag->isReleaseCandidate(), $testLabel);
254+
$this->assertSame(11, $tag->getNumber(), $testLabel);
232255
}
233256

234-
public function test_tag_alpha(): void
257+
public function test_tag_alpha() : void
235258
{
236259
$version = VersionParser::create('1.0-alpha2');
237260

@@ -264,7 +287,54 @@ public function test_tag_hyphen(): void
264287
$this->assertEquals('rc2', $version->getTag());
265288
}
266289

267-
public function test_tooManyDots(): void
290+
public function test_tag_dot() : void
291+
{
292+
$version = VersionParser::create('1.0-rc.2');
293+
294+
$this->assertTrue($version->isReleaseCandidate());
295+
$this->assertEquals('rc2', $version->getTag());
296+
}
297+
298+
public function test_tag_underscore() : void
299+
{
300+
$version = VersionParser::create('1.0-rc_2');
301+
302+
$this->assertTrue($version->isReleaseCandidate());
303+
$this->assertEquals('rc2', $version->getTag());
304+
}
305+
306+
public function test_tag_and_branch() : void
307+
{
308+
$version = VersionParser::create('1.0-BranchName-RC');
309+
310+
$this->assertTrue($version->isReleaseCandidate());
311+
$this->assertEquals('BranchName-rc', $version->getTag());
312+
$this->assertEquals('BranchName', $version->getBranchName(), print_r($version->toArray(), true));
313+
}
314+
315+
public function test_branchCanS0tartWithNumber() : void
316+
{
317+
$version = VersionParser::create('1.0-42BranchName-RC');
318+
319+
$testLabel = print_r($version->toArray(), true);
320+
321+
$this->assertEquals('1.0.0', $version->getVersion(), $testLabel);
322+
$this->assertTrue($version->isReleaseCandidate(), $testLabel);
323+
$this->assertEquals('42BranchName-rc', $version->getTag(), $testLabel);
324+
$this->assertEquals('42BranchName', $version->getBranchName(), $testLabel);
325+
}
326+
327+
public function test_branchCanContainSpecialChars() : void
328+
{
329+
$version = VersionParser::create('1.5.2 "Foobar/42"');
330+
331+
$testLabel = print_r($version->toArray(), true);
332+
333+
$this->assertEquals('1.5.2', $version->getVersion(), $testLabel);
334+
$this->assertEquals('Foobar/42', $version->getBranchName(), $testLabel);
335+
}
336+
337+
public function test_tooManyDots() : void
268338
{
269339
$version = VersionParser::create('1.2.3.4');
270340

@@ -279,6 +349,63 @@ public function test_stripSpaces(): void
279349
$this->assertEquals('1.2.3', $version->getVersion());
280350
}
281351

352+
public function test_preserveSpacesInTag(): void
353+
{
354+
$version = VersionParser::create('1 . 2 . 3 BranchName RC');
355+
356+
$testLabel = print_r($version->toArray(), true);
357+
358+
$this->assertEquals('1.2.3', $version->getVersion(), $testLabel);
359+
$this->assertEquals('BranchName', $version->getBranchName(), $testLabel);
360+
$this->assertEquals('rc', $version->getTagType(), $testLabel);
361+
}
362+
363+
public function test_stripSpecialChars() : void
364+
{
365+
$version = VersionParser::create('1.2 (BranchName) / Alpha2');
366+
367+
$testLabel = print_r($version->toArray(), true);
368+
369+
$this->assertEquals('1.2.0', $version->getVersion(), $testLabel);
370+
$this->assertEquals('BranchName', $version->getBranchName(), $testLabel);
371+
$this->assertEquals('alpha', $version->getTagType(), $testLabel);
372+
}
373+
374+
public function test_preserveOriginalCharsInBranch() : void
375+
{
376+
$version = VersionParser::create('1.2 "Super:branch"');
377+
378+
$testLabel = print_r($version->toArray(), true);
379+
380+
$this->assertEquals('1.2.0', $version->getVersion(), $testLabel);
381+
$this->assertEquals('Super:branch', $version->getBranchName(), $testLabel);
382+
}
383+
384+
public function test_branchNameAfterTag() : void
385+
{
386+
$version = VersionParser::create('1.2-beta2 "Super branch"');
387+
388+
$testLabel = print_r($version->toArray(), true);
389+
390+
$this->assertEquals('1.2.0', $version->getVersion(), $testLabel);
391+
$this->assertEquals('beta', $version->getTagType(), $testLabel);
392+
$this->assertEquals('Super branch', $version->getBranchName(), $testLabel);
393+
}
394+
395+
public function test_branchNameBeforeAndAfterTag() : void
396+
{
397+
$version = VersionParser::create('1.2 Super beta branch');
398+
399+
$testLabel = print_r($version->toArray(), true);
400+
401+
$this->assertEquals('1.2.0', $version->getVersion(), $testLabel);
402+
$this->assertEquals('beta', $version->getTagType(), $testLabel);
403+
404+
// This cannot be resolved back to the original branch name,
405+
// because the tag qualifier is in the middle of it.
406+
$this->assertEquals('Super-branch', $version->getBranchName(), $testLabel);
407+
}
408+
282409
public function test_getBranchName(): void
283410
{
284411
$tests = array(
@@ -305,7 +432,7 @@ public function test_getBranchName(): void
305432
foreach ($tests as $test) {
306433
$version = VersionParser::create($test['version']);
307434

308-
$label = $test['label'] . ' (' . $test['version'] . ')';
435+
$label = $test['label'].' ('.$test['version'].')'.PHP_EOL.print_r($version->toArray(), true);
309436

310437
$this->assertEquals($test['name'], $version->getBranchName(), $label);
311438
$this->assertEquals($test['hasBranch'], $version->hasBranch(), $label);
@@ -357,7 +484,7 @@ public function test_normalizeUppercase(): void
357484
{
358485
$version = VersionParser::create('1-BranchName-beta');
359486

360-
$this->assertEquals('1.0.0-BranchName-BETA', $version->setUppercase()->getTagVersion());
487+
$this->assertEquals('1.0.0-BranchName-BETA', $version->setTagUppercase()->getTagVersion(), print_r($version->toArray(), true));
361488
}
362489

363490
public function test_setSeparator(): void
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Mistralys\VersionParser;
6+
7+
use Mistralys\VersionParserTests\TestClasses\VersionParserTestCase;
8+
9+
final class QualifierTests extends VersionParserTestCase
10+
{
11+
public function test_no_tag(): void
12+
{
13+
$version = VersionParser::create('1');
14+
15+
$this->assertTrue($version->isStable());
16+
$this->assertFalse($version->isAlpha());
17+
$this->assertFalse($version->isBeta());
18+
$this->assertFalse($version->isReleaseCandidate());
19+
$this->assertFalse($version->isSnapshot());
20+
$this->assertFalse($version->isDev());
21+
$this->assertFalse($version->isPatch());
22+
}
23+
24+
public function test_stable(): void
25+
{
26+
$version = VersionParser::create('1-stable');
27+
28+
$this->assertTrue($version->isStable());
29+
$this->assertFalse($version->isAlpha());
30+
$this->assertFalse($version->isBeta());
31+
$this->assertFalse($version->isReleaseCandidate());
32+
$this->assertFalse($version->isSnapshot());
33+
$this->assertFalse($version->isDev());
34+
$this->assertFalse($version->isPatch());
35+
}
36+
37+
public function test_tag_beta(): void
38+
{
39+
$version = VersionParser::create('1-beta');
40+
41+
$this->assertFalse($version->isStable());
42+
$this->assertTrue($version->isBeta());
43+
$this->assertFalse($version->isAlpha());
44+
$this->assertFalse($version->isReleaseCandidate());
45+
$this->assertFalse($version->isSnapshot());
46+
$this->assertFalse($version->isDev());
47+
$this->assertFalse($version->isPatch());
48+
}
49+
50+
public function test_tag_alpha(): void
51+
{
52+
$version = VersionParser::create('1-alpha');
53+
54+
$this->assertFalse($version->isStable());
55+
$this->assertFalse($version->isBeta());
56+
$this->assertTrue($version->isAlpha());
57+
$this->assertFalse($version->isReleaseCandidate());
58+
$this->assertFalse($version->isSnapshot());
59+
$this->assertFalse($version->isDev());
60+
$this->assertFalse($version->isPatch());
61+
}
62+
63+
public function test_tag_releaseCandidate(): void
64+
{
65+
$version = VersionParser::create('1-rc');
66+
67+
$this->assertFalse($version->isStable());
68+
$this->assertFalse($version->isBeta());
69+
$this->assertFalse($version->isAlpha());
70+
$this->assertTrue($version->isReleaseCandidate());
71+
$this->assertFalse($version->isSnapshot());
72+
$this->assertFalse($version->isDev());
73+
$this->assertFalse($version->isPatch());
74+
}
75+
76+
public function test_tag_snapshot(): void
77+
{
78+
$version = VersionParser::create('1-snapshot');
79+
80+
$this->assertFalse($version->isStable());
81+
$this->assertFalse($version->isBeta());
82+
$this->assertFalse($version->isAlpha());
83+
$this->assertFalse($version->isReleaseCandidate());
84+
$this->assertTrue($version->isSnapshot());
85+
$this->assertFalse($version->isDev());
86+
$this->assertFalse($version->isPatch());
87+
}
88+
89+
public function test_tag_dev(): void
90+
{
91+
$version = VersionParser::create('1-dev');
92+
93+
$this->assertFalse($version->isStable());
94+
$this->assertFalse($version->isBeta());
95+
$this->assertFalse($version->isAlpha());
96+
$this->assertFalse($version->isReleaseCandidate());
97+
$this->assertFalse($version->isSnapshot());
98+
$this->assertTrue($version->isDev());
99+
$this->assertFalse($version->isPatch());
100+
}
101+
102+
public function test_tag_patch(): void
103+
{
104+
$version = VersionParser::create('1-patch');
105+
106+
$this->assertFalse($version->isStable());
107+
$this->assertFalse($version->isBeta());
108+
$this->assertFalse($version->isAlpha());
109+
$this->assertFalse($version->isReleaseCandidate());
110+
$this->assertFalse($version->isSnapshot());
111+
$this->assertFalse($version->isDev());
112+
$this->assertTrue($version->isPatch());
113+
}
114+
}

0 commit comments

Comments
 (0)