8000 [Intl] Simplified tests · symfony/symfony@9d9c389 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9d9c389

Browse files
committed
[Intl] Simplified tests
1 parent c55c4a2 commit 9d9c389

File tree

13 files changed

+100
-85
lines changed

13 files changed

+100
-85
lines changed

src/Symfony/Component/Intl/Tests/Collator/AbstractCollatorTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,13 @@
1313

1414
use Symfony\Component\Intl\Collator\StubCollator;
1515
use Symfony\Component\Intl\Locale;
16-
use Symfony\Component\Intl\Tests\IntlTestCase;
1716

1817
/**
1918
* Test case for Collator implementations.
2019
*
2120
* @author Bernhard Schussek <bschussek@gmail.com>
2221
*/
23-
abstract class AbstractCollatorTest extends IntlTestCase
22+
abstract class AbstractCollatorTest extends \PHPUnit_Framework_TestCase
2423
{
2524
/**
2625
* @dataProvider asortProvider

src/Symfony/Component/Intl/Tests/Collator/Verification/CollatorTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Symfony\Component\Intl\Locale;
1515
use Symfony\Component\Intl\Tests\Collator\AbstractCollatorTest;
16+
use Symfony\Component\Intl\Util\IntlTestHelper;
1617

1718
/**
1819
* Verifies that {@link AbstractCollatorTest} matches the behavior of the
@@ -24,7 +25,7 @@ class CollatorTest extends AbstractCollatorTest
2425
{
2526
protected function setUp()
2627
{
27-
$this->skipIfIntlExtensionNotLoaded();
28+
IntlTestHelper::requireFullIntl($this);
2829

2930
parent::setUp();
3031
}

src/Symfony/Component/Intl/Tests/DateFormatter/AbstractIntlDateFormatterTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
use Symfony\Component\Intl\DateFormatter\StubIntlDateFormatter;
1515
use Symfony\Component\Intl\Globals\StubIntlGlobals;
1616
use Symfony\Component\Intl\Intl;
17-
use Symfony\Component\Intl\Tests\IntlTestCase;
1817
use Symfony\Component\Intl\Util\IcuVersion;
1918
use Symfony\Component\Intl\Util\Version;
2019

@@ -23,7 +22,7 @@
2322
*
2423
* @author Bernhard Schussek <bschussek@gmail.com>
2524
*/
26-
abstract class AbstractIntlDateFormatterTest extends IntlTestCase
25+
abstract class AbstractIntlDateFormatterTest extends \PHPUnit_Framework_TestCase
2726
{
2827
/**
2928
* When a time zone is not specified, it uses the system default however it returns null in the getter method

src/Symfony/Component/Intl/Tests/DateFormatter/Verification/IntlDateFormatterTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Symfony\Component\Intl\DateFormatter\StubIntlDateFormatter;
1515
use Symfony\Component\Intl\Tests\DateFormatter\AbstractIntlDateFormatterTest;
16+
use Symfony\Component\Intl\Util\IntlTestHelper;
1617

1718
/**
1819
* Verifies that {@link AbstractIntlDateFormatterTest} matches the behavior of
@@ -24,7 +25,7 @@ class IntlDateFormatterTest extends AbstractIntlDateFormatterTest
2425
{
2526
protected function setUp()
2627
{
27-
$this->skipIfIntlExtensionNotLoaded();
28+
IntlTestHelper::requireFullIntl($this);
2829

2930
parent::setUp();
3031
}

src/Symfony/Component/Intl/Tests/Globals/AbstractIntlGlobalsTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,13 @@
1111

1212
namespace Symfony\Component\Intl\Tests\Globals;
1313

14-
use Symfony\Component\Intl\Tests\IntlTestCase;
1514

1615
/**
1716
* Test case for intl function implementations.
1817
*
1918
* @author Bernhard Schussek <bschussek@gmail.com>
2019
*/
21-
abstract class AbstractIntlGlobalsTest extends IntlTestCase
20+
abstract class AbstractIntlGlobalsTest extends \PHPUnit_Framework_TestCase
2221
{
2322
public function errorNameProvider()
2423
{

src/Symfony/Component/Intl/Tests/Globals/Verification/IntlGlobalsTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\Intl\Tests\Globals\Verification;
1313

1414
use Symfony\Component\Intl\Tests\Globals\AbstractIntlGlobalsTest;
15+
use Symfony\Component\Intl\Util\IntlTestHelper;
1516

1617
/**
1718
* Verifies that {@link AbstractIntlGlobalsTest} matches the behavior of the
@@ -23,7 +24,7 @@ class IntlGlobalsTest extends AbstractIntlGlobalsTest
2324
{
2425
protected function setUp()
2526
{
26-
$this->skipIfIntlExtensionNotLoaded();
27+
IntlTestHelper::requireFullIntl($this);
2728

2829
parent::setUp();
2930
}

src/Symfony/Component/Intl/Tests/IntlTestCase.php

Lines changed: 0 additions & 59 deletions
This file was deleted.

src/Symfony/Component/Intl/Tests/Locale/AbstractLocaleTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,13 @@
1212
namespace Symfony\Component\Intl\Tests\Locale;
1313

1414
use Symfony\Component\Intl\Stub\StubLocale;
15-
use Symfony\Component\Intl\Tests\IntlTestCase;
1615

1716
/**
1817
* Test case for Locale implementations.
1918
*
2019
* @author Bernhard Schussek <bschussek@gmail.com>
2120
*/
22-
abstract class AbstractLocaleTest extends IntlTestCase
21+
abstract class AbstractLocaleTest extends \PHPUnit_Framework_TestCase
2322
{
2423
public function testSetDefault()
2524
{

src/Symfony/Component/Intl/Tests/Locale/Verification/LocaleTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\Intl\Tests\Locale\Verification;
1313

1414
use Symfony\Component\Intl\Tests\Locale\AbstractLocaleTest;
15+
use Symfony\Component\Intl\Util\IntlTestHelper;
1516

1617
/**
1718
* Verifies that {@link AbstractLocaleTest} matches the behavior of the
@@ -23,7 +24,7 @@ class LocaleTest extends AbstractLocaleTest
2324
{
2425
protected function setUp()
2526
{
26-
$this->skipIfIntlExtensionNotLoaded();
27+
IntlTestHelper::requireFullIntl($this);
2728

2829
parent::setUp();
2930
}

src/Symfony/Component/Intl/Tests/NumberFormatter/AbstractNumberFormatterTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@
1515
use Symfony\Component\Intl\Intl;
1616
use Symfony\Component\Intl\Locale;
1717
use Symfony\Component\Intl\NumberFormatter\StubNumberFormatter;
18-
use Symfony\Component\Intl\Tests\IntlTestCase;
1918
use Symfony\Component\Intl\Util\IcuVersion;
19+
use Symfony\Component\Intl\Util\IntlTestHelper;
2020

2121
/**
2222
* Note that there are some values written like -2147483647 - 1. This is the lower 32bit int max and is a known
2323
* behavior of PHP.
2424
*/
25-
abstract class AbstractNumberFormatterTest extends IntlTestCase
25+
abstract class AbstractNumberFormatterTest extends \PHPUnit_Framework_TestCase
2626
{
2727
/**
2828
* @dataProvider formatCurrencyWithDecimalStyleProvider
@@ -547,7 +547,7 @@ public function parseTypeInt32Provider()
547547

548548
public function testParseTypeInt64With32BitIntegerInPhp32Bit()
549549
{
550-
$this->skipIfNot32Bit();
550+
IntlTestHelper::require32Bit($this);
551551

552552
$formatter = $this->getNumberFormatter('en', StubNumberFormatter::DECIMAL);
553553

@@ -573,7 +573,7 @@ public function testParseTypeInt64With32BitIntegerInPhp32Bit()
573573

574574
public function testParseTypeInt64With32BitIntegerInPhp64Bit()
575575
{
576-
$this->skipIfNot64Bit();
576+
IntlTestHelper::require64Bit($this);
577577

578578
$formatter = $this->getNumberFormatter('en', StubNumberFormatter::DECIMAL);
579579

@@ -591,7 +591,7 @@ public function testParseTypeInt64With32BitIntegerInPhp64Bit()
591591
*/
592592
public function testParseTypeInt64With64BitIntegerInPhp32Bit()
593593
{
594-
$this->skipIfNot32Bit();
594+
IntlTestHelper::require32Bit($this);
595595

596596
$formatter = $this->getNumberFormatter('en', StubNumberFormatter::DECIMAL);
597597

@@ -610,7 +610,7 @@ public function testParseTypeInt64With64BitIntegerInPhp32Bit()
610610
*/
611611
public function testParseTypeInt64With64BitIntegerInPhp64Bit()
612612
{
613-
$this->skipIfNot64Bit();
613+
IntlTestHelper::require64Bit($this);
614614

615615
$formatter = $this->getNumberFormatter('en', StubNumberFormatter::DECIMAL);
616616

src/Symfony/Component/Intl/Tests/NumberFormatter/Verification/NumberFormatterTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\Intl\Tests\NumberFormatter\Verification;
1313

1414
use Symfony\Component\Intl\Tests\NumberFormatter\AbstractNumberFormatterTest;
15+
use Symfony\Component\Intl\Util\IntlTestHelper;
1516

1617
/**
1718
* 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
2122
{
2223
protected function setUp()
2324
{
24-
$this->skipIfIntlExtensionNotLoaded();
25+
IntlTestHelper::requireFullIntl($this);
2526

2627
parent::setUp();
2728
}

src/Symfony/Component/Intl/Tests/ResourceBundle/Reader/BinaryBundleReaderTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212
namespace Symfony\Component\Intl\Tests\ResourceBundle\Reader;
1313

1414
use Symfony\Component\Intl\ResourceBundle\Reader\BinaryBundleReader;
15-
use Symfony\Component\Intl\Tests\IntlTestCase;
15+
use Symfony\Component\Intl\Util\IntlTestHelper;
1616

1717
/**
1818
* @author Bernhard Schussek <bschussek@gmail.com>
1919
*/
20-
class BinaryBundleReaderTest extends IntlTestCase
20+
class BinaryBundleReaderTest extends \PHPUnit_Framework_TestCase
2121
{
2222
/**
2323
* @var BinaryBundleReader
@@ -26,7 +26,7 @@ class BinaryBundleReaderTest extends IntlTestCase
2626

2727
protected function setUp()
2828
{
29-
$this->skipIfIntlExtensionNotLoaded();
29+
IntlTestHelper::requireFullIntl($this);
3030

3131
$this->reader = new BinaryBundleReader();
3232
}

src/Symfony/Component/Intl/Util/IntlTestHelper.php

Lines changed: 77 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,29 +16,102 @@
1616
/**
1717
* Helper class for preparing test cases that rely on the Intl component.
1818
*
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+
*
1925
* @author Bernhard Schussek <bschussek@gmail.com>
2026
*/
2127
class IntlTestHelper
2228
{
2329
/**
24-
* Prepares the given test case to use the Intl component.
30+
* Should be called before tests that work fine with the stub implementation.
2531
*
2632
* @param \PhpUnit_Framework_TestCase $testCase
2733
*/
28-
public static function setUp(\PhpUnit_Framework_TestCase $testCase)
34+
public static function requireIntl(\PhpUnit_Framework_TestCase $testCase)
2935
{
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(), '!=', $precision = 1)) {
43+
$testCase->markTestSkipped('Please change ICU version to ' . Intl::getIcuStubVersion());
44+
}
45+
46+
// Normalize the default locale in case this is not done explicitly
47+
// in the test
48+
\Locale::setDefault('en');
49+
50+
// Consequently, tests will
51+
//
52+
// * run only for one ICU version (see Intl::getIcuStubVersion())
53+
// there is no need to add control structures to your tests that
54+
// change the test depending on the ICU version.
55+
//
56+
// Tests should only rely on functionality that is implemented in the
57+
// stub classes.
58+
}
59+
60+
/**
61+
* Should be called before tests that require a feature-complete intl
62+
* implementation.
63+
*
64+
* @param \PhpUnit_Framework_TestCase $testCase
65+
*/
66+
public static function requireFullIntl(\PhpUnit_Framework_TestCase $testCase)
67+
{
68+
// We only run tests if the intl extension is loaded...
3069
if (!Intl::isExtensionLoaded()) {
3170
$testCase->markTestSkipped('The intl extension is not available.');
3271
}
3372

73+
// ... and only if the version is *one specific version*.
3474
if (IcuVersion::compare(Intl::getIcuVersion(), Intl::getIcuStubVersion(), '!=', $precision = 1)) {
3575
$testCase->markTestSkipped('Please change ICU version to ' . Intl::getIcuStubVersion());
3676
}
3777

38-
Intl::setDataSource(Intl::STUB);
39-
78+
// Normalize the default locale in case this is not done explicitly
79+
// in the test
4080
\Locale::setDefault('en');
81+
82+
// Consequently, tests will
83+
//
84+
// * run only for one ICU version (see Intl::getIcuStubVersion())
85+
// there is no need to add control structures to your tests that
86+
// change the test depending on the ICU version.
87+
// * always use the C intl classes
88+
// * always use the binary resource bundles (any locale is allowed)
4189
}
90+
91+
/**
92+
* Skips the test unless the current system has a 32bit architecture.
93+
*
94+
* @param \PhpUnit_Framework_TestCase $testCase
95+
*/
96+
public static function require32Bit(\PhpUnit_Framework_TestCase $testCase)
97+
{
98+
if (4 !== PHP_INT_SIZE) {
99+
$testCase->markTestSkipped('PHP must be compiled in 32 bit mode to run this test');
100+
}
101+
}
102+
103+
/**
104+
* Skips the test unless the current system has a 64bit architecture.
105+
*
106+
* @param \PhpUnit_Framework_TestCase $testCase
107+
*/
108+
public static function require64Bit(\PhpUnit_Framework_TestCase $testCase)
109+
{
110+
if (8 !== PHP_INT_SIZE) {
111+
$testCase->markTestSkipped('PHP must be compiled in 64 bit mode to run this test');
112+
}
113+
}
114+
42115
/**
43116
* Must not be instantiated.
44117
*/

0 commit comments

Comments
 (0)
0