TestCase.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. namespace Symfony\Tests\Component\Locale;
  3. abstract class TestCase extends \PHPUnit_Framework_TestCase
  4. {
  5. protected static $icuVersion = null;
  6. protected function is32Bit()
  7. {
  8. return PHP_INT_SIZE == 4;
  9. }
  10. protected function is64Bit()
  11. {
  12. return PHP_INT_SIZE == 8;
  13. }
  14. protected function skipIfPhpIsNot32Bit()
  15. {
  16. if (!$this->is32Bit()) {
  17. $this->markTestSkipped('The PHP must be compiled in 32 bit mode to run this test.');
  18. }
  19. }
  20. protected function skipIfPhpIsNot64Bit()
  21. {
  22. if (!$this->is64Bit()) {
  23. $this->markTestSkipped('The PHP must be compiled in 64 bit mode to run this test.');
  24. }
  25. }
  26. protected function isIntlExtensionLoaded()
  27. {
  28. return extension_loaded('intl');
  29. }
  30. protected function skipIfIntlExtensionIsNotLoaded()
  31. {
  32. if (!$this->isIntlExtensionLoaded()) {
  33. $this->markTestSkipped('The intl extension is not available.');
  34. }
  35. }
  36. protected function isGreaterOrEqualThanIcuVersion($version)
  37. {
  38. $version = $this->normalizeIcuVersion($version);
  39. $icuVersion = $this->normalizeIcuVersion($this->getIntlExtensionIcuVersion());
  40. return $icuVersion >= $version;
  41. }
  42. protected function isLowerThanIcuVersion($version)
  43. {
  44. $version = $this->normalizeIcuVersion($version);
  45. $icuVersion = $this->normalizeIcuVersion($this->getIntlExtensionIcuVersion());
  46. return $icuVersion < $version;
  47. }
  48. protected function normalizeIcuVersion($version)
  49. {
  50. return ((float) $version) * 100;
  51. }
  52. protected function getIntlExtensionIcuVersion()
  53. {
  54. if (isset(self::$icuVersion)) {
  55. return self::$icuVersion;
  56. }
  57. ob_start();
  58. phpinfo(INFO_MODULES);
  59. $output = ob_get_clean();
  60. preg_match('/^ICU version => (.*)$/m', $output, $matches);
  61. self::$icuVersion = $matches[1];
  62. return self::$icuVersion;
  63. }
  64. }