ILIAS  trunk Revision v11.0_alpha-1689-g66c127b4ae8
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
VersionTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 use ILIAS\Data;
23 
24 class VersionTest extends TestCase
25 {
26  protected Data\Factory $f;
27 
28  protected function setUp(): void
29  {
30  $this->f = new Data\Factory();
31  }
32 
33  public function testSmoke(): void
34  {
35  $v = $this->f->version("0.1.0");
36 
37  $this->assertEquals("0.1.0", (string) $v);
38  }
39 
40  public function testMajorOnly(): void
41  {
42  $v = $this->f->version("1");
43 
44  $this->assertEquals("1.0.0", (string) $v);
45  }
46 
47  public function testNoPatchVersion(): void
48  {
49  $v = $this->f->version("1.2");
50 
51  $this->assertEquals("1.2.0", (string) $v);
52  }
53 
54  public function testSubVersions(): void
55  {
56  $v = $this->f->version("1.2.3");
57 
58  $this->assertEquals(1, $v->getMajor());
59  $this->assertEquals(2, $v->getMinor());
60  $this->assertEquals(3, $v->getPatch());
61  }
62 
66  public function testGreaterThan(Data\Version $l, Data\Version $r): void
67  {
68  $this->assertTrue($l->isGreaterThan($r));
69  $this->assertFalse($l->isSmallerThan($r));
70  $this->assertTrue($r->isSmallerThan($l));
71  $this->assertFalse($r->isGreaterThan($l));
72  $this->assertTrue($l->isGreaterThanOrEquals($r));
73  $this->assertFalse($l->isSmallerThanOrEquals($r));
74  $this->assertTrue($r->isSmallerThanOrEquals($l));
75  $this->assertFalse($r->isGreaterThanOrEquals($l));
76  $this->assertFalse($l->equals($r));
77  $this->assertFalse($r->equals($l));
78  }
79 
80  public static function greaterThanProvider(): array
81  {
82  $f = new Data\Factory();
83  return [
84  'Patch version is greater (2>1), major and minor versions are equal (0)' => [$f->version("0.0.2"), $f->version("0.0.1")],
85  'Minor version is greater (2>1), major and patch versions are equal (0)' => [$f->version("0.2.0"), $f->version("0.1.0")],
86  'Major version is greater (2>1), minor and patch versions are equal (0)' => [$f->version("2.0.0"), $f->version("1.0.0")],
87  'Patch version is greater (3>2), major (1) and minor (2) versions are equal' => [$f->version("1.2.3"), $f->version("1.2.2")],
88  'Minor version is greater (2>1), major (1) and patch (3) versions are equal' => [$f->version("1.2.3"), $f->version("1.1.3")],
89  'Major version is greater (1>0), minor (2) and patch (3) versions are equal' => [$f->version("1.2.3"), $f->version("0.2.3")],
90  'Minor version is greater (5>1), patch is smaller (0<1), minor version is equal (1)' => [$f->version("1.5.0"), $f->version("1.1.1")],
91  ];
92  }
93 
97  public function testEquals(Data\Version $l, Data\Version $r): void
98  {
99  $this->assertFalse($l->isGreaterThan($r));
100  $this->assertFalse($r->isSmallerThan($l));
101  $this->assertTrue($l->isGreaterThanOrEquals($r));
102  $this->assertTrue($l->isSmallerThanOrEquals($r));
103  $this->assertTrue($r->isSmallerThanOrEquals($l));
104  $this->assertTrue($r->isGreaterThanOrEquals($l));
105  $this->assertTrue($l->equals($r));
106  $this->assertTrue($r->equals($l));
107  }
108 
109  public static function equalsProvider(): array
110  {
111  $f = new Data\Factory();
112  return [
113  [$f->version("0.0.1"), $f->version("0.0.1")],
114  [$f->version("0.1.0"), $f->version("0.1.0")],
115  [$f->version("1.0.0"), $f->version("1.0.0")],
116  [$f->version("1.0.3"), $f->version("1.0.3")],
117  [$f->version("1.2.0"), $f->version("1.2.0")],
118  [$f->version("1.2.3"), $f->version("1.2.3")]
119  ];
120  }
121 }
static greaterThanProvider()
Definition: VersionTest.php:80
testGreaterThan(Data\Version $l, Data\Version $r)
greaterThanProvider
Definition: VersionTest.php:66
testEquals(Data\Version $l, Data\Version $r)
equalsProvider
Definition: VersionTest.php:97
Data Factory $f
Definition: VersionTest.php:26
testNoPatchVersion()
Definition: VersionTest.php:47
A version number that consists of three numbers (major, minor, patch).
Definition: Version.php:26
static equalsProvider()
$r