index/tests/EnvironmentTest.php

52 lines
1.7 KiB
PHP

<?php
// EnvironmentTest.php
// Created: 2021-05-02
// Updated: 2023-01-01
declare(strict_types=1);
use PHPUnit\Framework\TestCase;
use Index\AString;
use Index\Environment;
use Index\Version;
/**
* @covers Environment
*/
final class EnvironmentTest extends TestCase {
public function testEnvVars(): void {
$varName = 'NDX_TEST_VAR_DO_NOT_DEFINE';
$this->assertEmpty(Environment::getVariable($varName));
Environment::setVariable($varName, 'the');
$varValue = Environment::getVariable($varName);
$this->assertEquals('the', $varValue);
Environment::removeVariable($varName);
$this->assertEmpty(Environment::getVariable($varName));
}
public function testIndexVersion(): void {
$strVersion = trim(file_get_contents(__DIR__ . '/../VERSION'));
$rawVersion = explode('.', $strVersion);
$version = Environment::getIndexVersion();
$this->assertEquals((int)$rawVersion[0], $version->getMajor());
$this->assertEquals((int)$rawVersion[1], $version->getMinor());
$this->assertEquals((int)$rawVersion[2], $version->getPatch());
$this->assertEquals($strVersion, (string)$version);
}
public function testPHPAndExtVersion(): void {
$version = Environment::getPHPVersion();
$extVersion = Environment::getPHPExtensionVersion('Core');
$this->assertEquals(PHP_MAJOR_VERSION, $version->getMajor());
$this->assertEquals(PHP_MINOR_VERSION, $version->getMinor());
$this->assertEquals(PHP_RELEASE_VERSION, $version->getPatch());
$this->assertTrue($version->equals($extVersion));
}
// not really sure how you would test the platform and sapi functions, so i won't
}