[Intl] Simplified tests
This commit is contained in:
parent
c55c4a26fe
commit
9d9c38996c
@ -13,14 +13,13 @@ namespace Symfony\Component\Intl\Tests\Collator;
|
||||
|
||||
use Symfony\Component\Intl\Collator\StubCollator;
|
||||
use Symfony\Component\Intl\Locale;
|
||||
use Symfony\Component\Intl\Tests\IntlTestCase;
|
||||
|
||||
/**
|
||||
* Test case for Collator implementations.
|
||||
*
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*/
|
||||
abstract class AbstractCollatorTest extends IntlTestCase
|
||||
abstract class AbstractCollatorTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider asortProvider
|
||||
|
@ -13,6 +13,7 @@ namespace Symfony\Component\Intl\Tests\Collator\Verification;
|
||||
|
||||
use Symfony\Component\Intl\Locale;
|
||||
use Symfony\Component\Intl\Tests\Collator\AbstractCollatorTest;
|
||||
use Symfony\Component\Intl\Util\IntlTestHelper;
|
||||
|
||||
/**
|
||||
* Verifies that {@link AbstractCollatorTest} matches the behavior of the
|
||||
@ -24,7 +25,7 @@ class CollatorTest extends AbstractCollatorTest
|
||||
{
|
||||
protected function setUp()
|
||||
{
|
||||
$this->skipIfIntlExtensionNotLoaded();
|
||||
IntlTestHelper::requireFullIntl($this);
|
||||
|
||||
parent::setUp();
|
||||
}
|
||||
|
@ -14,7 +14,6 @@ namespace Symfony\Component\Intl\Tests\DateFormatter;
|
||||
use Symfony\Component\Intl\DateFormatter\StubIntlDateFormatter;
|
||||
use Symfony\Component\Intl\Globals\StubIntlGlobals;
|
||||
use Symfony\Component\Intl\Intl;
|
||||
use Symfony\Component\Intl\Tests\IntlTestCase;
|
||||
use Symfony\Component\Intl\Util\IcuVersion;
|
||||
use Symfony\Component\Intl\Util\Version;
|
||||
|
||||
@ -23,7 +22,7 @@ use Symfony\Component\Intl\Util\Version;
|
||||
*
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*/
|
||||
abstract class AbstractIntlDateFormatterTest extends IntlTestCase
|
||||
abstract class AbstractIntlDateFormatterTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* When a time zone is not specified, it uses the system default however it returns null in the getter method
|
||||
|
@ -13,6 +13,7 @@ namespace Symfony\Component\Intl\Tests\DateFormatter\Verification;
|
||||
|
||||
use Symfony\Component\Intl\DateFormatter\StubIntlDateFormatter;
|
||||
use Symfony\Component\Intl\Tests\DateFormatter\AbstractIntlDateFormatterTest;
|
||||
use Symfony\Component\Intl\Util\IntlTestHelper;
|
||||
|
||||
/**
|
||||
* Verifies that {@link AbstractIntlDateFormatterTest} matches the behavior of
|
||||
@ -24,7 +25,7 @@ class IntlDateFormatterTest extends AbstractIntlDateFormatterTest
|
||||
{
|
||||
protected function setUp()
|
||||
{
|
||||
$this->skipIfIntlExtensionNotLoaded();
|
||||
IntlTestHelper::requireFullIntl($this);
|
||||
|
||||
parent::setUp();
|
||||
}
|
||||
|
@ -11,14 +11,13 @@
|
||||
|
||||
namespace Symfony\Component\Intl\Tests\Globals;
|
||||
|
||||
use Symfony\Component\Intl\Tests\IntlTestCase;
|
||||
|
||||
/**
|
||||
* Test case for intl function implementations.
|
||||
*
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*/
|
||||
abstract class AbstractIntlGlobalsTest extends IntlTestCase
|
||||
abstract class AbstractIntlGlobalsTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function errorNameProvider()
|
||||
{
|
||||
|
@ -12,6 +12,7 @@
|
||||
namespace Symfony\Component\Intl\Tests\Globals\Verification;
|
||||
|
||||
use Symfony\Component\Intl\Tests\Globals\AbstractIntlGlobalsTest;
|
||||
use Symfony\Component\Intl\Util\IntlTestHelper;
|
||||
|
||||
/**
|
||||
* Verifies that {@link AbstractIntlGlobalsTest} matches the behavior of the
|
||||
@ -23,7 +24,7 @@ class IntlGlobalsTest extends AbstractIntlGlobalsTest
|
||||
{
|
||||
protected function setUp()
|
||||
{
|
||||
$this->skipIfIntlExtensionNotLoaded();
|
||||
IntlTestHelper::requireFullIntl($this);
|
||||
|
||||
parent::setUp();
|
||||
}
|
||||
|
@ -1,59 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Intl\Tests;
|
||||
|
||||
use Symfony\Component\Intl\Intl;
|
||||
use Symfony\Component\Intl\Util\IcuVersion;
|
||||
use Symfony\Component\Intl\Util\Version;
|
||||
|
||||
/**
|
||||
* Base test case for the Intl component.
|
||||
*
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*/
|
||||
abstract class IntlTestCase extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
protected function is32Bit()
|
||||
{
|
||||
return PHP_INT_SIZE == 4;
|
||||
}
|
||||
|
||||
protected function is64Bit()
|
||||
{
|
||||
return PHP_INT_SIZE == 8;
|
||||
}
|
||||
|
||||
protected function skipIfIntlExtensionNotLoaded()
|
||||
{
|
||||
if (!Intl::isExtensionLoaded()) {
|
||||
$this->markTestSkipped('The intl extension is not available.');
|
||||
}
|
||||
|
||||
if (IcuVersion::compare(Intl::getIcuVersion(), Intl::getIcuStubVersion(), '!=', $precision = 1)) {
|
||||
$this->markTestSkipped('Please change ICU version to ' . Intl::getIcuStubVersion());
|
||||
}
|
||||
}
|
||||
|
||||
protected function skipIfNot32Bit()
|
||||
{
|
||||
if (!$this->is32Bit()) {
|
||||
$this->markTestSkipped('PHP must be compiled in 32 bit mode to run this test');
|
||||
}
|
||||
}
|
||||
|
||||
protected function skipIfNot64Bit()
|
||||
{
|
||||
if (!$this->is64Bit()) {
|
||||
$this->markTestSkipped('PHP must be compiled in 64 bit mode to run this test');
|
||||
}
|
||||
}
|
||||
}
|
@ -12,14 +12,13 @@
|
||||
namespace Symfony\Component\Intl\Tests\Locale;
|
||||
|
||||
use Symfony\Component\Intl\Stub\StubLocale;
|
||||
use Symfony\Component\Intl\Tests\IntlTestCase;
|
||||
|
||||
/**
|
||||
* Test case for Locale implementations.
|
||||
*
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*/
|
||||
abstract class AbstractLocaleTest extends IntlTestCase
|
||||
abstract class AbstractLocaleTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testSetDefault()
|
||||
{
|
||||
|
@ -12,6 +12,7 @@
|
||||
namespace Symfony\Component\Intl\Tests\Locale\Verification;
|
||||
|
||||
use Symfony\Component\Intl\Tests\Locale\AbstractLocaleTest;
|
||||
use Symfony\Component\Intl\Util\IntlTestHelper;
|
||||
|
||||
/**
|
||||
* Verifies that {@link AbstractLocaleTest} matches the behavior of the
|
||||
@ -23,7 +24,7 @@ class LocaleTest extends AbstractLocaleTest
|
||||
{
|
||||
protected function setUp()
|
||||
{
|
||||
$this->skipIfIntlExtensionNotLoaded();
|
||||
IntlTestHelper::requireFullIntl($this);
|
||||
|
||||
parent::setUp();
|
||||
}
|
||||
|
@ -15,14 +15,14 @@ use Symfony\Component\Intl\Globals\StubIntlGlobals;
|
||||
use Symfony\Component\Intl\Intl;
|
||||
use Symfony\Component\Intl\Locale;
|
||||
use Symfony\Component\Intl\NumberFormatter\StubNumberFormatter;
|
||||
use Symfony\Component\Intl\Tests\IntlTestCase;
|
||||
use Symfony\Component\Intl\Util\IcuVersion;
|
||||
use Symfony\Component\Intl\Util\IntlTestHelper;
|
||||
|
||||
/**
|
||||
* Note that there are some values written like -2147483647 - 1. This is the lower 32bit int max and is a known
|
||||
* behavior of PHP.
|
||||
*/
|
||||
abstract class AbstractNumberFormatterTest extends IntlTestCase
|
||||
abstract class AbstractNumberFormatterTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider formatCurrencyWithDecimalStyleProvider
|
||||
@ -547,7 +547,7 @@ abstract class AbstractNumberFormatterTest extends IntlTestCase
|
||||
|
||||
public function testParseTypeInt64With32BitIntegerInPhp32Bit()
|
||||
{
|
||||
$this->skipIfNot32Bit();
|
||||
IntlTestHelper::require32Bit($this);
|
||||
|
||||
$formatter = $this->getNumberFormatter('en', StubNumberFormatter::DECIMAL);
|
||||
|
||||
@ -573,7 +573,7 @@ abstract class AbstractNumberFormatterTest extends IntlTestCase
|
||||
|
||||
public function testParseTypeInt64With32BitIntegerInPhp64Bit()
|
||||
{
|
||||
$this->skipIfNot64Bit();
|
||||
IntlTestHelper::require64Bit($this);
|
||||
|
||||
$formatter = $this->getNumberFormatter('en', StubNumberFormatter::DECIMAL);
|
||||
|
||||
@ -591,7 +591,7 @@ abstract class AbstractNumberFormatterTest extends IntlTestCase
|
||||
*/
|
||||
public function testParseTypeInt64With64BitIntegerInPhp32Bit()
|
||||
{
|
||||
$this->skipIfNot32Bit();
|
||||
IntlTestHelper::require32Bit($this);
|
||||
|
||||
$formatter = $this->getNumberFormatter('en', StubNumberFormatter::DECIMAL);
|
||||
|
||||
@ -610,7 +610,7 @@ abstract class AbstractNumberFormatterTest extends IntlTestCase
|
||||
*/
|
||||
public function testParseTypeInt64With64BitIntegerInPhp64Bit()
|
||||
{
|
||||
$this->skipIfNot64Bit();
|
||||
IntlTestHelper::require64Bit($this);
|
||||
|
||||
$formatter = $this->getNumberFormatter('en', StubNumberFormatter::DECIMAL);
|
||||
|
||||
|
@ -12,6 +12,7 @@
|
||||
namespace Symfony\Component\Intl\Tests\NumberFormatter\Verification;
|
||||
|
||||
use Symfony\Component\Intl\Tests\NumberFormatter\AbstractNumberFormatterTest;
|
||||
use Symfony\Component\Intl\Util\IntlTestHelper;
|
||||
|
||||
/**
|
||||
* Note that there are some values written like -2147483647 - 1. This is the lower 32bit int max and is a known
|
||||
@ -21,7 +22,7 @@ class NumberFormatterTest extends AbstractNumberFormatterTest
|
||||
{
|
||||
protected function setUp()
|
||||
{
|
||||
$this->skipIfIntlExtensionNotLoaded();
|
||||
IntlTestHelper::requireFullIntl($this);
|
||||
|
||||
parent::setUp();
|
||||
}
|
||||
|
@ -12,12 +12,12 @@
|
||||
namespace Symfony\Component\Intl\Tests\ResourceBundle\Reader;
|
||||
|
||||
use Symfony\Component\Intl\ResourceBundle\Reader\BinaryBundleReader;
|
||||
use Symfony\Component\Intl\Tests\IntlTestCase;
|
||||
use Symfony\Component\Intl\Util\IntlTestHelper;
|
||||
|
||||
/**
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*/
|
||||
class BinaryBundleReaderTest extends IntlTestCase
|
||||
class BinaryBundleReaderTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @var BinaryBundleReader
|
||||
@ -26,7 +26,7 @@ class BinaryBundleReaderTest extends IntlTestCase
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->skipIfIntlExtensionNotLoaded();
|
||||
IntlTestHelper::requireFullIntl($this);
|
||||
|
||||
$this->reader = new BinaryBundleReader();
|
||||
}
|
||||
|
@ -16,29 +16,102 @@ use Symfony\Component\Intl\Intl;
|
||||
/**
|
||||
* Helper class for preparing test cases that rely on the Intl component.
|
||||
*
|
||||
* Any test that tests functionality relying on either the intl classes or
|
||||
* the resource bundle data should call either of the methods
|
||||
* {@link requireIntl()} or {@link requireFullIntl()}. Calling
|
||||
* {@link requireFullIntl()} is only necessary if you use functionality in the
|
||||
* test that is not provided by the stub intl implementation.
|
||||
*
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*/
|
||||
class IntlTestHelper
|
||||
{
|
||||
/**
|
||||
* Prepares the given test case to use the Intl component.
|
||||
* Should be called before tests that work fine with the stub implementation.
|
||||
*
|
||||
* @param \PhpUnit_Framework_TestCase $testCase
|
||||
*/
|
||||
public static function setUp(\PhpUnit_Framework_TestCase $testCase)
|
||||
public static function requireIntl(\PhpUnit_Framework_TestCase $testCase)
|
||||
{
|
||||
if (!Intl::isExtensionLoaded()) {
|
||||
$testCase->markTestSkipped('The intl extension is not available.');
|
||||
}
|
||||
// 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 (IcuVersion::compare(Intl::getIcuVersion(), Intl::getIcuStubVersion(), '!=', $precision = 1)) {
|
||||
$testCase->markTestSkipped('Please change ICU version to ' . Intl::getIcuStubVersion());
|
||||
}
|
||||
|
||||
Intl::setDataSource(Intl::STUB);
|
||||
|
||||
// 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());
|
||||
}
|
||||
|
||||
// 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)
|
||||
}
|
||||
|
||||
/**
|
||||
* Skips the test unless the current system has a 32bit architecture.
|
||||
*
|
||||
* @param \PhpUnit_Framework_TestCase $testCase
|
||||
*/
|
||||
public static function require32Bit(\PhpUnit_Framework_TestCase $testCase)
|
||||
{
|
||||
if (4 !== PHP_INT_SIZE) {
|
||||
$testCase->markTestSkipped('PHP must be compiled in 32 bit mode to run this test');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Skips the test unless the current system has a 64bit architecture.
|
||||
*
|
||||
* @param \PhpUnit_Framework_TestCase $testCase
|
||||
*/
|
||||
public static function require64Bit(\PhpUnit_Framework_TestCase $testCase)
|
||||
{
|
||||
if (8 !== PHP_INT_SIZE) {
|
||||
$testCase->markTestSkipped('PHP must be compiled in 64 bit mode to run this test');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Must not be instantiated.
|
||||
*/
|
||||
|
Reference in New Issue
Block a user