PageRenderTime 56ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/Symfony/Tests/Component/Form/Extension/Core/DataTransformer/LocalizedTestCase.php

http://github.com/symfony/symfony
PHP | 70 lines | 46 code | 16 blank | 8 comment | 4 complexity | 888de796cf9ed3e058df8e23fedb9b2c MD5 | raw file
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Tests\Component\Form\Extension\Core\DataTransformer;
  11. class LocalizedTestCase extends \PHPUnit_Framework_TestCase
  12. {
  13. protected static $icuVersion = null;
  14. protected function setUp()
  15. {
  16. parent::setUp();
  17. if (!$this->isIntlExtensionLoaded()) {
  18. $this->markTestSkipped('The "intl" extension is not available');
  19. }
  20. }
  21. protected function isIntlExtensionLoaded()
  22. {
  23. return extension_loaded('intl');
  24. }
  25. protected function isLowerThanIcuVersion($version)
  26. {
  27. $version = $this->normalizeIcuVersion($version);
  28. $icuVersion = $this->normalizeIcuVersion($this->getIntlExtensionIcuVersion());
  29. return $icuVersion < $version;
  30. }
  31. protected function normalizeIcuVersion($version)
  32. {
  33. return ((float) $version) * 100;
  34. }
  35. protected function getIntlExtensionIcuVersion()
  36. {
  37. if (isset(self::$icuVersion)) {
  38. return self::$icuVersion;
  39. }
  40. if (!$this->isIntlExtensionLoaded()) {
  41. throw new \RuntimeException('The intl extension is not available');
  42. }
  43. if (defined('INTL_ICU_VERSION')) {
  44. return INTL_ICU_VERSION;
  45. }
  46. $reflector = new \ReflectionExtension('intl');
  47. ob_start();
  48. $reflector->info();
  49. $output = ob_get_clean();
  50. preg_match('/^ICU version => (.*)$/m', $output, $matches);
  51. self::$icuVersion = $matches[1];
  52. return self::$icuVersion;
  53. }
  54. }