PHP-Parser/test/PhpParser/PhpVersionTest.php

42 lines
1.4 KiB
PHP
Raw Normal View History

2022-10-30 18:00:30 +01:00
<?php declare(strict_types=1);
namespace PhpParser;
class PhpVersionTest extends \PHPUnit\Framework\TestCase {
2024-05-31 09:32:45 +02:00
public function testConstruction(): void {
2022-10-30 18:00:30 +01:00
$version = PhpVersion::fromComponents(8, 2);
$this->assertSame(80200, $version->id);
$version = PhpVersion::fromString('8.2');
$this->assertSame(80200, $version->id);
$version = PhpVersion::fromString('8.2.14');
$this->assertSame(80200, $version->id);
$version = PhpVersion::fromString('8.2.14rc1');
$this->assertSame(80200, $version->id);
}
2024-05-31 09:32:45 +02:00
public function testInvalidVersion(): void {
2022-10-30 18:00:30 +01:00
$this->expectException(\LogicException::class);
$this->expectExceptionMessage('Invalid PHP version "8"');
PhpVersion::fromString('8');
}
2024-05-31 09:32:45 +02:00
public function testEquals(): void {
2022-10-30 18:00:30 +01:00
$php74 = PhpVersion::fromComponents(7, 4);
$php81 = PhpVersion::fromComponents(8, 1);
$php82 = PhpVersion::fromComponents(8, 2);
$this->assertTrue($php81->equals($php81));
$this->assertFalse($php81->equals($php82));
$this->assertTrue($php81->older($php82));
$this->assertFalse($php81->older($php81));
$this->assertFalse($php81->older($php74));
$this->assertFalse($php81->newerOrEqual($php82));
$this->assertTrue($php81->newerOrEqual($php81));
$this->assertTrue($php81->newerOrEqual($php74));
}
}