4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\Intl\Util
;
14 use Symfony\Component\Intl\Intl
;
17 * Helper class for preparing test cases that rely on the Intl component.
19 * Any test that tests functionality relying on either the intl classes or
20 * the resource bundle data should call either of the methods
21 * {@link requireIntl()} or {@link requireFullIntl()}. Calling
22 * {@link requireFullIntl()} is only necessary if you use functionality in the
23 * test that is not provided by the stub intl implementation.
25 * @author Bernhard Schussek <bschussek@gmail.com>
30 * Should be called before tests that work fine with the stub implementation.
32 * @param \PhpUnit_Framework_TestCase $testCase
34 public static function requireIntl(\PhpUnit_Framework_TestCase
$testCase)
36 // We only run tests if the version is *one specific version*.
37 // This condition is satisfied if
39 // * the intl extension is loaded with version Intl::getIcuStubVersion()
40 // * the intl extension is not loaded
42 if (IcuVersion
::compare(Intl
::getIcuVersion(), Intl
::getIcuStubVersion(), '!=', 1)) {
43 $testCase->markTestSkipped('Please change ICU version to ' . Intl
::getIcuStubVersion());
46 if (IcuVersion
::compare(Intl
::getIcuDataVersion(), Intl
::getIcuStubVersion(), '!=', 1)) {
47 $testCase->markTestSkipped('Please change the Icu component to version 1.0.x or 1.' . IcuVersion
::normalize(Intl
::getIcuStubVersion(), 1) . '.x');
50 // Normalize the default locale in case this is not done explicitly
52 \Locale
::setDefault('en');
54 // Consequently, tests will
56 // * run only for one ICU version (see Intl::getIcuStubVersion())
57 // there is no need to add control structures to your tests that
58 // change the test depending on the ICU version.
60 // Tests should only rely on functionality that is implemented in the
65 * Should be called before tests that require a feature-complete intl
68 * @param \PhpUnit_Framework_TestCase $testCase
70 public static function requireFullIntl(\PhpUnit_Framework_TestCase
$testCase)
72 // We only run tests if the intl extension is loaded...
73 if (!Intl
::isExtensionLoaded()) {
74 $testCase->markTestSkipped('The intl extension is not available.');
77 // ... and only if the version is *one specific version* ...
78 if (IcuVersion
::compare(Intl
::getIcuVersion(), Intl
::getIcuStubVersion(), '!=', 1)) {
79 $testCase->markTestSkipped('Please change ICU version to ' . Intl
::getIcuStubVersion());
82 // ... and only if the data in the Icu component matches that version.
83 if (IcuVersion
::compare(Intl
::getIcuDataVersion(), Intl
::getIcuStubVersion(), '!=', 1)) {
84 $testCase->markTestSkipped('Please change the Icu component to version 1.0.x or 1.' . IcuVersion
::normalize(Intl
::getIcuStubVersion(), 1) . '.x');
87 // Normalize the default locale in case this is not done explicitly
89 \Locale
::setDefault('en');
91 // Consequently, tests will
93 // * run only for one ICU version (see Intl::getIcuStubVersion())
94 // there is no need to add control structures to your tests that
95 // change the test depending on the ICU version.
96 // * always use the C intl classes
97 // * always use the binary resource bundles (any locale is allowed)
101 * Skips the test unless the current system has a 32bit architecture.
103 * @param \PhpUnit_Framework_TestCase $testCase
105 public static function require32Bit(\PhpUnit_Framework_TestCase
$testCase)
107 if (4 !== PHP_INT_SIZE
) {
108 $testCase->markTestSkipped('PHP must be compiled in 32 bit mode to run this test');
113 * Skips the test unless the current system has a 64bit architecture.
115 * @param \PhpUnit_Framework_TestCase $testCase
117 public static function require64Bit(\PhpUnit_Framework_TestCase
$testCase)
119 if (8 !== PHP_INT_SIZE
) {
120 $testCase->markTestSkipped('PHP must be compiled in 64 bit mode to run this test');
125 * Must not be instantiated.
127 private function __construct() {}