-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBasicTest.php
62 lines (50 loc) · 1.51 KB
/
BasicTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
declare(strict_types=1);
use PHPUnit\Framework\TestCase;
use BrunoRB\SemverPHP;
class BasicTestTest extends TestCase {
static public $data;
static public function setUpBeforeClass() {
self::$data = json_decode(file_get_contents(__DIR__ . '/test.json'), true);
}
public function testIsValid() {
foreach(self::$data['valid'] as $v) {
$this->assertTrue(SemverPHP::isValid($v), "$v should be valid");
}
}
public function testIsInvalid() {
foreach(self::$data['invalid'] as $v) {
$this->assertFalse(SemverPHP::isValid($v), "$v should be invalid");
}
}
public function testSplit() {
foreach(self::$data['split'] as $v => $data) {
$expected = [];
foreach(['major', 'minor', 'patch', 'preRelease', 'buildMetadata'] as $i => $key) {
$expected[$key] = $data[$i];
}
$this->assertEquals($expected, SemverPHP::split($v));
}
}
public function testCompare() {
$compare = self::$data['compare'];
for ($i=0; $i<count($compare); $i++) {
for ($j=$i+1; $j<count($compare); $j++) {
$a = $compare[$i];
$b = $compare[$j];
$this->assertEquals(-1, SemverPHP::compare($a, $b), "$a < $b, should return -1");
}
}
for ($i=count($compare) - 1; $i>=0; $i--) {
for ($j=$i-1; $j>=0; $j--) {
$a = $compare[$i];
$b = $compare[$j];
$this->assertEquals(1, SemverPHP::compare($a, $b), "$a > $b, should return 1");
}
}
for ($i=0; $i<count($compare); $i++) {
$a = $compare[$i];
$this->assertEquals(0, SemverPHP::compare($a, $a), "$a == $a, should return 0");
}
}
}