This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
symfony/tests/Symfony/Tests/Component/Locale/TestCase.php
Eriksen Costa 69b0e09d6a [Locale] added stub implementations of Locale and NumberFormatter classes
Updated update-data.php script to extract locales, countries names, languages and currencies
from ICU to be used by the stub implementations
2011-02-23 13:26:05 +01:00

82 lines
2.0 KiB
PHP

<?php
namespace Symfony\Tests\Component\Locale;
abstract class TestCase extends \PHPUnit_Framework_TestCase
{
protected static $icuVersion = null;
protected function is32Bit()
{
return PHP_INT_SIZE == 4;
}
protected function is64Bit()
{
return PHP_INT_SIZE == 8;
}
protected function skipIfPhpIsNot32Bit()
{
if (!$this->is32Bit()) {
$this->markTestSkipped('The PHP must be compiled in 32 bit mode to run this test.');
}
}
protected function skipIfPhpIsNot64Bit()
{
if (!$this->is64Bit()) {
$this->markTestSkipped('The PHP must be compiled in 64 bit mode to run this test.');
}
}
protected function isIntlExtensionLoaded()
{
return extension_loaded('intl');
}
protected function skipIfIntlExtensionIsNotLoaded()
{
if (!$this->isIntlExtensionLoaded()) {
$this->markTestSkipped('The intl extension is not available.');
}
}
protected function isGreaterOrEqualThanIcuVersion($version)
{
$version = $this->normalizeIcuVersion($version);
$icuVersion = $this->normalizeIcuVersion($this->getIntlExtensionIcuVersion());
return $icuVersion >= $version;
}
protected function isLowerThanIcuVersion($version)
{
$version = $this->normalizeIcuVersion($version);
$icuVersion = $this->normalizeIcuVersion($this->getIntlExtensionIcuVersion());
return $icuVersion < $version;
}
protected function normalizeIcuVersion($version)
{
return ((float) $version) * 100;
}
protected function getIntlExtensionIcuVersion()
{
if (isset(self::$icuVersion)) {
return self::$icuVersion;
}
ob_start();
phpinfo(INFO_MODULES);
$output = ob_get_clean();
preg_match('/^ICU version => (.*)$/m', $output, $matches);
self::$icuVersion = $matches[1];
return self::$icuVersion;
}
}