2011-01-25 00:48:04 +00:00
|
|
|
<?php
|
|
|
|
|
2011-02-20 17:45:29 +00:00
|
|
|
/*
|
|
|
|
* This file is part of the Symfony package.
|
|
|
|
*
|
2011-03-14 00:22:11 +00:00
|
|
|
* (c) Fabien Potencier <fabien@symfony.com>
|
2011-02-20 17:45:29 +00:00
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
2011-01-25 00:48:04 +00:00
|
|
|
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 isIntlExtensionLoaded()
|
|
|
|
{
|
|
|
|
return extension_loaded('intl');
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function skipIfIntlExtensionIsNotLoaded()
|
|
|
|
{
|
|
|
|
if (!$this->isIntlExtensionLoaded()) {
|
|
|
|
$this->markTestSkipped('The intl extension is not available.');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-02 14:17:16 +01:00
|
|
|
protected function skipIfICUVersionIsTooOld()
|
|
|
|
{
|
|
|
|
if ($this->isLowerThanIcuVersion('4.0')) {
|
2011-04-26 15:22:22 +01:00
|
|
|
$this->markTestSkipped('Please upgrade ICU version to 4+');
|
2011-04-02 14:17:16 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-11 16:45:39 +00:00
|
|
|
protected function skipIfNot32Bit()
|
|
|
|
{
|
|
|
|
if (!$this->is32Bit()) {
|
|
|
|
$this->markTestSkipped('PHP must be compiled in 32 bit mode to run this test');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function skipIfNot64Bit()
|
|
|
|
{
|
|
|
|
if (!$this->is64Bit()) {
|
|
|
|
$this->markTestSkipped('PHP must be compiled in 64 bit mode to run this test');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-15 19:32:40 +01:00
|
|
|
protected function isGreaterOrEqualThanPhpVersion($version)
|
|
|
|
{
|
|
|
|
return version_compare(\PHP_VERSION, $version, '>=');
|
|
|
|
}
|
|
|
|
|
2011-01-25 00:48:04 +00:00
|
|
|
protected function isGreaterOrEqualThanIcuVersion($version)
|
|
|
|
{
|
|
|
|
$version = $this->normalizeIcuVersion($version);
|
|
|
|
$icuVersion = $this->normalizeIcuVersion($this->getIntlExtensionIcuVersion());
|
|
|
|
|
|
|
|
return $icuVersion >= $version;
|
|
|
|
}
|
|
|
|
|
2012-12-05 12:49:46 +00:00
|
|
|
protected function isSameAsIcuVersion($version)
|
|
|
|
{
|
|
|
|
$version = $this->normalizeIcuVersion($version);
|
|
|
|
$icuVersion = $this->normalizeIcuVersion($this->getIntlExtensionIcuVersion());
|
|
|
|
|
|
|
|
return $icuVersion === $version;
|
|
|
|
}
|
|
|
|
|
2011-01-25 00:48:04 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2011-02-23 13:38:05 +00:00
|
|
|
if (!$this->isIntlExtensionLoaded()) {
|
|
|
|
throw new \RuntimeException('The intl extension is not available');
|
|
|
|
}
|
|
|
|
|
2011-06-16 10:31:09 +01:00
|
|
|
if (defined('INTL_ICU_VERSION')) {
|
2011-06-16 10:20:05 +01:00
|
|
|
return INTL_ICU_VERSION;
|
|
|
|
}
|
|
|
|
|
|
|
|
$reflector = new \ReflectionExtension('intl');
|
|
|
|
|
2011-01-25 00:48:04 +00:00
|
|
|
ob_start();
|
2011-06-16 10:20:05 +01:00
|
|
|
$reflector->info();
|
2011-01-25 00:48:04 +00:00
|
|
|
$output = ob_get_clean();
|
|
|
|
|
|
|
|
preg_match('/^ICU version => (.*)$/m', $output, $matches);
|
|
|
|
self::$icuVersion = $matches[1];
|
|
|
|
|
|
|
|
return self::$icuVersion;
|
|
|
|
}
|
|
|
|
}
|