/** * Should be called before tests that work fine with the stub implementation. */ public static function requireIntl(\PHPUnit_Framework_TestCase $testCase, $minimumIcuVersion = null) { if (null === $minimumIcuVersion) { $minimumIcuVersion = Intl::getIcuStubVersion(); } // We only run tests if the version is *one specific version*. // This condition is satisfied if // // * the intl extension is loaded with version Intl::getIcuStubVersion() // * the intl extension is not loaded if (($minimumIcuVersion || defined('HHVM_VERSION_ID')) && IcuVersion::compare(Intl::getIcuVersion(), $minimumIcuVersion, '!=', 1)) { $testCase->markTestSkipped('ICU version ' . $minimumIcuVersion . ' is required.'); } // Normalize the default locale in case this is not done explicitly // in the test \Locale::setDefault('en'); // Consequently, tests will // // * run only for one ICU version (see Intl::getIcuStubVersion()) // there is no need to add control structures to your tests that // change the test depending on the ICU version. // // Tests should only rely on functionality that is implemented in the // stub classes. }
/** * Should be called before tests that require a feature-complete intl * implementation. * * @param \PhpUnit_Framework_TestCase $testCase */ public static function requireFullIntl(\PhpUnit_Framework_TestCase $testCase) { // We only run tests if the intl extension is loaded... if (!Intl::isExtensionLoaded()) { $testCase->markTestSkipped('The intl extension is not available.'); } // ... and only if the version is *one specific version* ... if (IcuVersion::compare(Intl::getIcuVersion(), Intl::getIcuStubVersion(), '!=', $precision = 1)) { $testCase->markTestSkipped('Please change ICU version to ' . Intl::getIcuStubVersion()); } // ... and only if the data in the Icu component matches that version. if (IcuVersion::compare(Intl::getIcuDataVersion(), Intl::getIcuStubVersion(), '!=', $precision = 1)) { $testCase->markTestSkipped('Please change the Icu component to version 1.0.x or 1.' . IcuVersion::normalize(Intl::getIcuStubVersion(), 1) . '.x'); } // Normalize the default locale in case this is not done explicitly // in the test \Locale::setDefault('en'); // Consequently, tests will // // * run only for one ICU version (see Intl::getIcuStubVersion()) // there is no need to add control structures to your tests that // change the test depending on the ICU version. // * always use the C intl classes // * always use the binary resource bundles (any locale is allowed) }
/** * Should be called before tests that require a feature-complete intl * implementation. * * @param \PhpUnit_Framework_TestCase $testCase */ public static function requireFullIntl(\PHPUnit_Framework_TestCase $testCase) { // We only run tests if the intl extension is loaded... if (!Intl::isExtensionLoaded()) { $testCase->markTestSkipped('Extension intl is required.'); } // ... and only if the version is *one specific version* if (IcuVersion::compare(Intl::getIcuVersion(), Intl::getIcuStubVersion(), '!=', 1)) { $testCase->markTestSkipped('ICU version ' . Intl::getIcuStubVersion() . ' is required.'); } // Normalize the default locale in case this is not done explicitly // in the test \Locale::setDefault('en'); // Consequently, tests will // // * run only for one ICU version (see Intl::getIcuStubVersion()) // there is no need to add control structures to your tests that // change the test depending on the ICU version. // * always use the C intl classes }
} echo LINE; echo centered("ICU Resource Bundle Stub Creation") . "\n"; echo LINE; if (!Intl::isExtensionLoaded()) { bailout('The intl extension for PHP is not installed.'); } if (!class_exists('\\Symfony\\Component\\Icu\\IcuData')) { bailout('You must run "composer update --dev" before running this script.'); } $stubBranch = '1.0.x'; if (IcuData::isStubbed()) { bailout("Please switch to a branch of the Icu component that contains .res files (anything but {$stubBranch})."); } $shortIcuVersionInPhp = strip_minor_versions(Intl::getIcuVersion()); $shortIcuVersionInIntlComponent = strip_minor_versions(Intl::getIcuStubVersion()); $shortIcuVersionInIcuComponent = strip_minor_versions(IcuData::getVersion()); if ($shortIcuVersionInPhp !== $shortIcuVersionInIcuComponent) { bailout("The ICU version of the component ({$shortIcuVersionInIcuComponent}) does not match the ICU version in the intl extension ({$shortIcuVersionInPhp})."); } if ($shortIcuVersionInIntlComponent !== $shortIcuVersionInIcuComponent) { bailout("The ICU version of the component ({$shortIcuVersionInIcuComponent}) does not match the ICU version of the stub classes in the Intl component ({$shortIcuVersionInIntlComponent})."); } echo wordwrap("Make sure that you don't have any ICU development files " . "installed. If the build fails, try to run:\n", LINE_WIDTH); echo "\n sudo apt-get remove libicu-dev\n\n"; $icuVersionInIcuComponent = IcuData::getVersion(); echo "Compiling stubs for ICU version {$icuVersionInIcuComponent}.\n"; echo "Preparing stub creation...\n"; $targetDir = sys_get_temp_dir() . '/icu-stubs'; $context = new StubbingContext(IcuData::getResourceDirectory(), $targetDir, new Filesystem(), $icuVersionInIcuComponent); $transformer = new BundleTransformer();