]> git.immae.eu Git - github/wallabag/wallabag.git/blob - vendor/symfony/intl/Symfony/Component/Intl/Util/IntlTestHelper.php
twig implementation
[github/wallabag/wallabag.git] / vendor / symfony / intl / Symfony / Component / Intl / Util / IntlTestHelper.php
1 <?php
2
3 /*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <fabien@symfony.com>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12 namespace Symfony\Component\Intl\Util;
13
14 use Symfony\Component\Intl\Intl;
15
16 /**
17 * Helper class for preparing test cases that rely on the Intl component.
18 *
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.
24 *
25 * @author Bernhard Schussek <bschussek@gmail.com>
26 */
27 class IntlTestHelper
28 {
29 /**
30 * Should be called before tests that work fine with the stub implementation.
31 *
32 * @param \PhpUnit_Framework_TestCase $testCase
33 */
34 public static function requireIntl(\PhpUnit_Framework_TestCase $testCase)
35 {
36 // We only run tests if the version is *one specific version*.
37 // This condition is satisfied if
38 //
39 // * the intl extension is loaded with version Intl::getIcuStubVersion()
40 // * the intl extension is not loaded
41
42 if (IcuVersion::compare(Intl::getIcuVersion(), Intl::getIcuStubVersion(), '!=', 1)) {
43 $testCase->markTestSkipped('Please change ICU version to ' . Intl::getIcuStubVersion());
44 }
45
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');
48 }
49
50 // Normalize the default locale in case this is not done explicitly
51 // in the test
52 \Locale::setDefault('en');
53
54 // Consequently, tests will
55 //
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.
59 //
60 // Tests should only rely on functionality that is implemented in the
61 // stub classes.
62 }
63
64 /**
65 * Should be called before tests that require a feature-complete intl
66 * implementation.
67 *
68 * @param \PhpUnit_Framework_TestCase $testCase
69 */
70 public static function requireFullIntl(\PhpUnit_Framework_TestCase $testCase)
71 {
72 // We only run tests if the intl extension is loaded...
73 if (!Intl::isExtensionLoaded()) {
74 $testCase->markTestSkipped('The intl extension is not available.');
75 }
76
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());
80 }
81
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');
85 }
86
87 // Normalize the default locale in case this is not done explicitly
88 // in the test
89 \Locale::setDefault('en');
90
91 // Consequently, tests will
92 //
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)
98 }
99
100 /**
101 * Skips the test unless the current system has a 32bit architecture.
102 *
103 * @param \PhpUnit_Framework_TestCase $testCase
104 */
105 public static function require32Bit(\PhpUnit_Framework_TestCase $testCase)
106 {
107 if (4 !== PHP_INT_SIZE) {
108 $testCase->markTestSkipped('PHP must be compiled in 32 bit mode to run this test');
109 }
110 }
111
112 /**
113 * Skips the test unless the current system has a 64bit architecture.
114 *
115 * @param \PhpUnit_Framework_TestCase $testCase
116 */
117 public static function require64Bit(\PhpUnit_Framework_TestCase $testCase)
118 {
119 if (8 !== PHP_INT_SIZE) {
120 $testCase->markTestSkipped('PHP must be compiled in 64 bit mode to run this test');
121 }
122 }
123
124 /**
125 * Must not be instantiated.
126 */
127 private function __construct() {}
128 }