1<?php declare(strict_types=1);
2
3namespace PhpParser;
4
5class PhpVersionTest extends \PHPUnit\Framework\TestCase {
6    public function testConstruction() {
7        $version = PhpVersion::fromComponents(8, 2);
8        $this->assertSame(80200, $version->id);
9
10        $version = PhpVersion::fromString('8.2');
11        $this->assertSame(80200, $version->id);
12
13        $version = PhpVersion::fromString('8.2.14');
14        $this->assertSame(80200, $version->id);
15
16        $version = PhpVersion::fromString('8.2.14rc1');
17        $this->assertSame(80200, $version->id);
18    }
19
20    public function testInvalidVersion() {
21        $this->expectException(\LogicException::class);
22        $this->expectExceptionMessage('Invalid PHP version "8"');
23        PhpVersion::fromString('8');
24    }
25
26    public function testEquals() {
27        $php74 = PhpVersion::fromComponents(7, 4);
28        $php81 = PhpVersion::fromComponents(8, 1);
29        $php82 = PhpVersion::fromComponents(8, 2);
30        $this->assertTrue($php81->equals($php81));
31        $this->assertFalse($php81->equals($php82));
32
33        $this->assertTrue($php81->older($php82));
34        $this->assertFalse($php81->older($php81));
35        $this->assertFalse($php81->older($php74));
36
37        $this->assertFalse($php81->newerOrEqual($php82));
38        $this->assertTrue($php81->newerOrEqual($php81));
39        $this->assertTrue($php81->newerOrEqual($php74));
40    }
41}
42