TestCase.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien.potencier@symfony-project.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 skipIfPhpIsNot32Bit()
  23. {
  24. if (!$this->is32Bit()) {
  25. $this->markTestSkipped('The PHP must be compiled in 32 bit mode to run this test.');
  26. }
  27. }
  28. protected function skipIfPhpIsNot64Bit()
  29. {
  30. if (!$this->is64Bit()) {
  31. $this->markTestSkipped('The PHP must be compiled in 64 bit mode to run this test.');
  32. }
  33. }
  34. protected function isIntlExtensionLoaded()
  35. {
  36. return extension_loaded('intl');
  37. }
  38. protected function skipIfIntlExtensionIsNotLoaded()
  39. {
  40. if (!$this->isIntlExtensionLoaded()) {
  41. $this->markTestSkipped('The intl extension is not available.');
  42. }
  43. }
  44. protected function isGreaterOrEqualThanIcuVersion($version)
  45. {
  46. $version = $this->normalizeIcuVersion($version);
  47. $icuVersion = $this->normalizeIcuVersion($this->getIntlExtensionIcuVersion());
  48. return $icuVersion >= $version;
  49. }
  50. protected function isLowerThanIcuVersion($version)
  51. {
  52. $version = $this->normalizeIcuVersion($version);
  53. $icuVersion = $this->normalizeIcuVersion($this->getIntlExtensionIcuVersion());
  54. return $icuVersion < $version;
  55. }
  56. protected function normalizeIcuVersion($version)
  57. {
  58. return ((float) $version) * 100;
  59. }
  60. protected function getIntlExtensionIcuVersion()
  61. {
  62. if (isset(self::$icuVersion)) {
  63. return self::$icuVersion;
  64. }
  65. ob_start();
  66. phpinfo(INFO_MODULES);
  67. $output = ob_get_clean();
  68. preg_match('/^ICU version => (.*)$/m', $output, $matches);
  69. self::$icuVersion = $matches[1];
  70. return self::$icuVersion;
  71. }
  72. }