TestCase.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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\Locale;
  11. abstract class TestCase extends \PHPUnit_Framework_TestCase
  12. {
  13. protected static $icuVersion = null;
  14. protected function is32Bit()
  15. {
  16. return PHP_INT_SIZE == 4;
  17. }
  18. protected function is64Bit()
  19. {
  20. return PHP_INT_SIZE == 8;
  21. }
  22. protected function isIntlExtensionLoaded()
  23. {
  24. return extension_loaded('intl');
  25. }
  26. protected function skipIfIntlExtensionIsNotLoaded()
  27. {
  28. if (!$this->isIntlExtensionLoaded()) {
  29. $this->markTestSkipped('The intl extension is not available.');
  30. }
  31. }
  32. protected function isGreaterOrEqualThanIcuVersion($version)
  33. {
  34. $version = $this->normalizeIcuVersion($version);
  35. $icuVersion = $this->normalizeIcuVersion($this->getIntlExtensionIcuVersion());
  36. return $icuVersion >= $version;
  37. }
  38. protected function isLowerThanIcuVersion($version)
  39. {
  40. $version = $this->normalizeIcuVersion($version);
  41. $icuVersion = $this->normalizeIcuVersion($this->getIntlExtensionIcuVersion());
  42. return $icuVersion < $version;
  43. }
  44. protected function normalizeIcuVersion($version)
  45. {
  46. return ((float) $version) * 100;
  47. }
  48. protected function getIntlExtensionIcuVersion()
  49. {
  50. if (isset(self::$icuVersion)) {
  51. return self::$icuVersion;
  52. }
  53. if (!$this->isIntlExtensionLoaded()) {
  54. throw new \RuntimeException('The intl extension is not available');
  55. }
  56. ob_start();
  57. phpinfo(INFO_MODULES);
  58. $output = ob_get_clean();
  59. preg_match('/^ICU version => (.*)$/m', $output, $matches);
  60. self::$icuVersion = $matches[1];
  61. return self::$icuVersion;
  62. }
  63. }