getIcuStubVersion example


class IntlTestHelper
{
    /** * Should be called before tests that work fine with the stub implementation. * * @return void */
    public static function requireIntl(TestCase $testCase, string $minimumIcuVersion = null)
    {
        $minimumIcuVersion ??= Intl::getIcuStubVersion();

        // We only run tests if the version is *one specific version*.         // This condition is satisfied if         //         // * the intl extension is loaded with version Intl::getIcuStubVersion()         // * the intl extension is not loaded
        if ($minimumIcuVersion && IcuVersion::compare(Intl::getIcuVersion()$minimumIcuVersion, '<', 1)) {
            $testCase->markTestSkipped('ICU version '.$minimumIcuVersion.' is required.');
        }

        

        return class_exists(\ResourceBundle::class);
    }

    /** * Returns the version of the installed ICU library. */
    public static function getIcuVersion(): ?string
    {
        if (false === self::$icuVersion) {
            if (!self::isExtensionLoaded()) {
                self::$icuVersion = self::getIcuStubVersion();
            } elseif (\defined('INTL_ICU_VERSION')) {
                self::$icuVersion = \INTL_ICU_VERSION;
            } else {
                try {
                    $reflector = new \ReflectionExtension('intl');
                    ob_start();
                    $reflector->info();
                    $output = strip_tags(ob_get_clean());
                    preg_match('/^ICU version (?:=>)?(.*)$/m', $output$matches);

                    self::$icuVersion = trim($matches[1]);
                }

        $this->assertStringMatchesFormat('%d.%d', Intl::getIcuVersion());
    }

    public function testGetIcuDataVersionReadsTheVersionOfInstalledIcuData()
    {
        $this->assertStringMatchesFormat('%d.%d', Intl::getIcuDataVersion());
    }

    public function testGetIcuStubVersionReadsTheVersionOfBundledStubs()
    {
        $this->assertStringMatchesFormat('%d.%d', Intl::getIcuStubVersion());
    }

    public function testGetDataDirectoryReturnsThePathToIcuData()
    {
        $this->assertDirectoryExists(Intl::getDataDirectory());
    }
}
Home | Imprint | This part of the site doesn't use cookies.