Actualización

This commit is contained in:
Xes
2025-04-10 12:24:57 +02:00
parent 8969cc929d
commit 45420b6f0d
39760 changed files with 4303286 additions and 0 deletions

View File

@@ -0,0 +1,62 @@
<?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\Collator;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Intl\Collator\Collator;
/**
* Test case for Collator implementations.
*
* @author Bernhard Schussek <bschussek@gmail.com>
*/
abstract class AbstractCollatorTest extends TestCase
{
/**
* @dataProvider asortProvider
*/
public function testAsort($array, $sortFlag, $expected)
{
$collator = $this->getCollator('en');
$collator->asort($array, $sortFlag);
$this->assertSame($expected, $array);
}
public function asortProvider()
{
return [
/* array, sortFlag, expected */
[
['a', 'b', 'c'],
Collator::SORT_REGULAR,
['a', 'b', 'c'],
],
[
['c', 'b', 'a'],
Collator::SORT_REGULAR,
[2 => 'a', 1 => 'b', 0 => 'c'],
],
[
['b', 'c', 'a'],
Collator::SORT_REGULAR,
[2 => 'a', 0 => 'b', 1 => 'c'],
],
];
}
/**
* @param string $locale
*
* @return \Collator
*/
abstract protected function getCollator($locale);
}

View File

@@ -0,0 +1,101 @@
<?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\Collator;
use Symfony\Component\Intl\Collator\Collator;
use Symfony\Component\Intl\Globals\IntlGlobals;
class CollatorTest extends AbstractCollatorTest
{
public function testConstructorWithUnsupportedLocale()
{
$this->expectException('Symfony\Component\Intl\Exception\MethodArgumentValueNotImplementedException');
new Collator('pt_BR');
}
public function testCompare()
{
$this->expectException('Symfony\Component\Intl\Exception\MethodNotImplementedException');
$collator = $this->getCollator('en');
$collator->compare('a', 'b');
}
public function testGetAttribute()
{
$this->expectException('Symfony\Component\Intl\Exception\MethodNotImplementedException');
$collator = $this->getCollator('en');
$collator->getAttribute(Collator::NUMERIC_COLLATION);
}
public function testGetErrorCode()
{
$collator = $this->getCollator('en');
$this->assertEquals(IntlGlobals::U_ZERO_ERROR, $collator->getErrorCode());
}
public function testGetErrorMessage()
{
$collator = $this->getCollator('en');
$this->assertEquals('U_ZERO_ERROR', $collator->getErrorMessage());
}
public function testGetLocale()
{
$collator = $this->getCollator('en');
$this->assertEquals('en', $collator->getLocale());
}
public function testConstructWithoutLocale()
{
$collator = $this->getCollator(null);
$this->assertInstanceOf('\Symfony\Component\Intl\Collator\Collator', $collator);
}
public function testGetSortKey()
{
$this->expectException('Symfony\Component\Intl\Exception\MethodNotImplementedException');
$collator = $this->getCollator('en');
$collator->getSortKey('Hello');
}
public function testGetStrength()
{
$this->expectException('Symfony\Component\Intl\Exception\MethodNotImplementedException');
$collator = $this->getCollator('en');
$collator->getStrength();
}
public function testSetAttribute()
{
$this->expectException('Symfony\Component\Intl\Exception\MethodNotImplementedException');
$collator = $this->getCollator('en');
$collator->setAttribute(Collator::NUMERIC_COLLATION, Collator::ON);
}
public function testSetStrength()
{
$this->expectException('Symfony\Component\Intl\Exception\MethodNotImplementedException');
$collator = $this->getCollator('en');
$collator->setStrength(Collator::PRIMARY);
}
public function testStaticCreate()
{
$collator = Collator::create('en');
$this->assertInstanceOf('\Symfony\Component\Intl\Collator\Collator', $collator);
}
protected function getCollator($locale)
{
return new Collator($locale);
}
}

View File

@@ -0,0 +1,36 @@
<?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\Collator\Verification;
use Symfony\Component\Intl\Tests\Collator\AbstractCollatorTest;
use Symfony\Component\Intl\Util\IntlTestHelper;
/**
* Verifies that {@link AbstractCollatorTest} matches the behavior of the
* {@link \Collator} class in a specific version of ICU.
*
* @author Bernhard Schussek <bschussek@gmail.com>
*/
class CollatorTest extends AbstractCollatorTest
{
protected function setUp()
{
IntlTestHelper::requireFullIntl($this, false);
parent::setUp();
}
protected function getCollator($locale)
{
return new \Collator($locale);
}
}

View File

@@ -0,0 +1,345 @@
<?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\Data\Bundle\Reader;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Intl\Data\Bundle\Reader\BundleEntryReader;
use Symfony\Component\Intl\Exception\ResourceBundleNotFoundException;
/**
* @author Bernhard Schussek <bschussek@gmail.com>
*/
class BundleEntryReaderTest extends TestCase
{
const RES_DIR = '/res/dir';
/**
* @var BundleEntryReader
*/
private $reader;
/**
* @var MockObject
*/
private $readerImpl;
private static $data = [
'Entries' => [
'Foo' => 'Bar',
'Bar' => 'Baz',
],
'Foo' => 'Bar',
'Version' => '2.0',
];
private static $fallbackData = [
'Entries' => [
'Foo' => 'Foo',
'Bam' => 'Lah',
],
'Baz' => 'Foo',
'Version' => '1.0',
];
private static $mergedData = [
// no recursive merging -> too complicated
'Entries' => [
'Foo' => 'Bar',
'Bar' => 'Baz',
],
'Baz' => 'Foo',
'Version' => '2.0',
'Foo' => 'Bar',
];
protected function setUp()
{
$this->readerImpl = $this->getMockBuilder('Symfony\Component\Intl\Data\Bundle\Reader\BundleEntryReaderInterface')->getMock();
$this->reader = new BundleEntryReader($this->readerImpl);
}
public function testForwardCallToRead()
{
$this->readerImpl->expects($this->once())
->method('read')
->with(self::RES_DIR, 'root')
->willReturn(self::$data);
$this->assertSame(self::$data, $this->reader->read(self::RES_DIR, 'root'));
}
public function testReadEntireDataFileIfNoIndicesGiven()
{
$this->readerImpl->expects($this->exactly(2))
->method('read')
->withConsecutive(
[self::RES_DIR, 'en'],
[self::RES_DIR, 'root']
)
->willReturnOnConsecutiveCalls(self::$data, self::$fallbackData);
$this->assertSame(self::$mergedData, $this->reader->readEntry(self::RES_DIR, 'en', []));
}
public function testReadExistingEntry()
{
$this->readerImpl->expects($this->once())
->method('read')
->with(self::RES_DIR, 'root')
->willReturn(self::$data);
$this->assertSame('Bar', $this->reader->readEntry(self::RES_DIR, 'root', ['Entries', 'Foo']));
}
public function testReadNonExistingEntry()
{
$this->expectException('Symfony\Component\Intl\Exception\MissingResourceException');
$this->readerImpl->expects($this->once())
->method('read')
->with(self::RES_DIR, 'root')
->willReturn(self::$data);
$this->reader->readEntry(self::RES_DIR, 'root', ['Entries', 'NonExisting']);
}
public function testFallbackIfEntryDoesNotExist()
{
$this->readerImpl->expects($this->exactly(2))
->method('read')
->withConsecutive(
[self::RES_DIR, 'en_GB'],
[self::RES_DIR, 'en']
)
->willReturnOnConsecutiveCalls(self::$data, self::$fallbackData);
$this->assertSame('Lah', $this->reader->readEntry(self::RES_DIR, 'en_GB', ['Entries', 'Bam']));
}
public function testDontFallbackIfEntryDoesNotExistAndFallbackDisabled()
{
$this->expectException('Symfony\Component\Intl\Exception\MissingResourceException');
$this->readerImpl->expects($this->once())
->method('read')
->with(self::RES_DIR, 'en_GB')
->willReturn(self::$data);
$this->reader->readEntry(self::RES_DIR, 'en_GB', ['Entries', 'Bam'], false);
}
public function testFallbackIfLocaleDoesNotExist()
{
$this->readerImpl->expects($this->exactly(2))
->method('read')
->withConsecutive(
[self::RES_DIR, 'en_GB'],
[self::RES_DIR, 'en']
)
->willReturnOnConsecutiveCalls(
$this->throwException(new ResourceBundleNotFoundException()),
self::$fallbackData
);
$this->assertSame('Lah', $this->reader->readEntry(self::RES_DIR, 'en_GB', ['Entries', 'Bam']));
}
public function testDontFallbackIfLocaleDoesNotExistAndFallbackDisabled()
{
$this->expectException('Symfony\Component\Intl\Exception\MissingResourceException');
$this->readerImpl->expects($this->once())
->method('read')
->with(self::RES_DIR, 'en_GB')
->willThrowException(new ResourceBundleNotFoundException());
$this->reader->readEntry(self::RES_DIR, 'en_GB', ['Entries', 'Bam'], false);
}
public function provideMergeableValues()
{
return [
['foo', null, 'foo'],
[null, 'foo', 'foo'],
[['foo', 'bar'], null, ['foo', 'bar']],
[['foo', 'bar'], [], ['foo', 'bar']],
[null, ['baz'], ['baz']],
[[], ['baz'], ['baz']],
[['foo', 'bar'], ['baz'], ['baz', 'foo', 'bar']],
];
}
/**
* @dataProvider provideMergeableValues
*/
public function testMergeDataWithFallbackData($childData, $parentData, $result)
{
if (null === $childData || \is_array($childData)) {
$this->readerImpl->expects($this->exactly(2))
->method('read')
->withConsecutive(
[self::RES_DIR, 'en'],
[self::RES_DIR, 'root']
)
->willReturnOnConsecutiveCalls($childData, $parentData);
} else {
$this->readerImpl->expects($this->once())
->method('read')
->with(self::RES_DIR, 'en')
->willReturn($childData);
}
$this->assertSame($result, $this->reader->readEntry(self::RES_DIR, 'en', [], true));
}
/**
* @dataProvider provideMergeableValues
*/
public function testDontMergeDataIfFallbackDisabled($childData, $parentData, $result)
{
$this->readerImpl->expects($this->once())
->method('read')
->with(self::RES_DIR, 'en_GB')
->willReturn($childData);
$this->assertSame($childData, $this->reader->readEntry(self::RES_DIR, 'en_GB', [], false));
}
/**
* @dataProvider provideMergeableValues
*/
public function testMergeExistingEntryWithExistingFallbackEntry($childData, $parentData, $result)
{
if (null === $childData || \is_array($childData)) {
$this->readerImpl->expects($this->exactly(2))
->method('read')
->withConsecutive(
[self::RES_DIR, 'en'],
[self::RES_DIR, 'root']
)
->willReturnOnConsecutiveCalls(
['Foo' => ['Bar' => $childData]],
['Foo' => ['Bar' => $parentData]]
);
} else {
$this->readerImpl->expects($this->once())
->method('read')
->with(self::RES_DIR, 'en')
->willReturn(['Foo' => ['Bar' => $childData]]);
}
$this->assertSame($result, $this->reader->readEntry(self::RES_DIR, 'en', ['Foo', 'Bar'], true));
}
/**
* @dataProvider provideMergeableValues
*/
public function testMergeNonExistingEntryWithExistingFallbackEntry($childData, $parentData, $result)
{
$this->readerImpl
->method('read')
->withConsecutive(
[self::RES_DIR, 'en_GB'],
[self::RES_DIR, 'en']
)
->willReturnOnConsecutiveCalls(['Foo' => 'Baz'], ['Foo' => ['Bar' => $parentData]]);
$this->assertSame($parentData, $this->reader->readEntry(self::RES_DIR, 'en_GB', ['Foo', 'Bar'], true));
}
/**
* @dataProvider provideMergeableValues
*/
public function testMergeExistingEntryWithNonExistingFallbackEntry($childData, $parentData, $result)
{
if (null === $childData || \is_array($childData)) {
$this->readerImpl
->method('read')
->withConsecutive(
[self::RES_DIR, 'en_GB'],
[self::RES_DIR, 'en']
)
->willReturnOnConsecutiveCalls(['Foo' => ['Bar' => $childData]], ['Foo' => 'Bar']);
} else {
$this->readerImpl->expects($this->once())
->method('read')
->with(self::RES_DIR, 'en_GB')
->willReturn(['Foo' => ['Bar' => $childData]]);
}
$this->assertSame($childData, $this->reader->readEntry(self::RES_DIR, 'en_GB', ['Foo', 'Bar'], true));
}
public function testFailIfEntryFoundNeitherInParentNorChild()
{
$this->expectException('Symfony\Component\Intl\Exception\MissingResourceException');
$this->readerImpl
->method('read')
->withConsecutive(
[self::RES_DIR, 'en_GB'],
[self::RES_DIR, 'en']
)
->willReturnOnConsecutiveCalls(['Foo' => 'Baz'], ['Foo' => 'Bar']);
$this->reader->readEntry(self::RES_DIR, 'en_GB', ['Foo', 'Bar'], true);
}
/**
* @dataProvider provideMergeableValues
*/
public function testMergeTraversables($childData, $parentData, $result)
{
$parentData = \is_array($parentData) ? new \ArrayObject($parentData) : $parentData;
$childData = \is_array($childData) ? new \ArrayObject($childData) : $childData;
if (null === $childData || $childData instanceof \ArrayObject) {
$this->readerImpl
->method('read')
->withConsecutive(
[self::RES_DIR, 'en_GB'],
[self::RES_DIR, 'en']
)
->willReturnOnConsecutiveCalls(['Foo' => ['Bar' => $childData]], ['Foo' => ['Bar' => $parentData]]);
} else {
$this->readerImpl->expects($this->once())
->method('read')
->with(self::RES_DIR, 'en_GB')
->willReturn(['Foo' => ['Bar' => $childData]]);
}
$this->assertSame($result, $this->reader->readEntry(self::RES_DIR, 'en_GB', ['Foo', 'Bar'], true));
}
/**
* @dataProvider provideMergeableValues
*/
public function testFollowLocaleAliases($childData, $parentData, $result)
{
$this->reader->setLocaleAliases(['mo' => 'ro_MD']);
if (null === $childData || \is_array($childData)) {
$this->readerImpl
->method('read')
->withConsecutive(
[self::RES_DIR, 'ro_MD'],
// Read fallback locale of aliased locale ("ro_MD" -> "ro")
[self::RES_DIR, 'ro']
)
->willReturnOnConsecutiveCalls(['Foo' => ['Bar' => $childData]], ['Foo' => ['Bar' => $parentData]]);
} else {
$this->readerImpl->expects($this->once())
->method('read')
->with(self::RES_DIR, 'ro_MD')
->willReturn(['Foo' => ['Bar' => $childData]]);
}
$this->assertSame($result, $this->reader->readEntry(self::RES_DIR, 'mo', ['Foo', 'Bar'], true));
}
}

View File

@@ -0,0 +1,17 @@
#!/bin/bash
if [ -z "$ICU_BUILD_DIR" ]; then
echo "Please set the ICU_BUILD_DIR environment variable"
exit
fi
if [ ! -d "$ICU_BUILD_DIR" ]; then
echo "The directory $ICU_BUILD_DIR pointed at by ICU_BUILD_DIR does not exist"
exit
fi
DIR=`dirname $0`
rm $DIR/res/*.res
LD_LIBRARY_PATH=$ICU_BUILD_DIR/lib $ICU_BUILD_DIR/bin/genrb -d $DIR/res $DIR/txt/*.txt

View File

@@ -0,0 +1,14 @@
<?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.
*/
return [
'Foo' => 'Bar',
];

Binary file not shown.

View File

@@ -0,0 +1,3 @@
en{
Foo{"Bar"}
}

View File

@@ -0,0 +1 @@
{"Foo":"Bar"}

View File

@@ -0,0 +1,14 @@
<?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.
*/
return [
'Foo' => 'Bar',
];

View File

@@ -0,0 +1 @@
{"Foo":"Bar"}

View File

@@ -0,0 +1 @@
{"Foobar"}

View File

@@ -0,0 +1,14 @@
<?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.
*/
return [
'Foo' => 'Bar',
];

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,3 @@
alias{
"%%ALIAS"{"ro"}
}

View File

@@ -0,0 +1,3 @@
mo{
"%%ALIAS"{"ro_MD"}
}

View File

@@ -0,0 +1,3 @@
ro{
Foo{"Bar"}
}

View File

@@ -0,0 +1,3 @@
ro_MD{
Baz{"Bam"}
}

View File

@@ -0,0 +1,6 @@
root{
/**
* so genrb doesn't issue warnings
*/
___{""}
}

View File

@@ -0,0 +1,101 @@
<?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\Data\Bundle\Reader;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Intl\Data\Bundle\Reader\IntlBundleReader;
/**
* @author Bernhard Schussek <bschussek@gmail.com>
* @requires extension intl
*/
class IntlBundleReaderTest extends TestCase
{
/**
* @var IntlBundleReader
*/
private $reader;
protected function setUp()
{
$this->reader = new IntlBundleReader();
}
public function testReadReturnsArrayAccess()
{
$data = $this->reader->read(__DIR__.'/Fixtures/res', 'ro');
$this->assertInstanceOf('\ArrayAccess', $data);
$this->assertSame('Bar', $data['Foo']);
$this->assertArrayNotHasKey('ExistsNot', $data);
}
public function testReadFollowsAlias()
{
// "alias" = "ro"
$data = $this->reader->read(__DIR__.'/Fixtures/res', 'alias');
$this->assertInstanceOf('\ArrayAccess', $data);
$this->assertSame('Bar', $data['Foo']);
$this->assertArrayNotHasKey('ExistsNot', $data);
}
public function testReadDoesNotFollowFallback()
{
if (\defined('HHVM_VERSION')) {
$this->markTestSkipped('ResourceBundle does not support disabling fallback properly on HHVM.');
}
// "ro_MD" -> "ro"
$data = $this->reader->read(__DIR__.'/Fixtures/res', 'ro_MD');
$this->assertInstanceOf('\ArrayAccess', $data);
$this->assertSame('Bam', $data['Baz']);
$this->assertArrayNotHasKey('Foo', $data);
$this->assertNull($data['Foo']);
$this->assertArrayNotHasKey('ExistsNot', $data);
}
public function testReadDoesNotFollowFallbackAlias()
{
if (\defined('HHVM_VERSION')) {
$this->markTestSkipped('ResourceBundle does not support disabling fallback properly on HHVM.');
}
// "mo" = "ro_MD" -> "ro"
$data = $this->reader->read(__DIR__.'/Fixtures/res', 'mo');
$this->assertInstanceOf('\ArrayAccess', $data);
$this->assertSame('Bam', $data['Baz'], 'data from the aliased locale can be accessed');
$this->assertArrayNotHasKey('Foo', $data);
$this->assertNull($data['Foo']);
$this->assertArrayNotHasKey('ExistsNot', $data);
}
public function testReadFailsIfNonExistingLocale()
{
$this->expectException('Symfony\Component\Intl\Exception\ResourceBundleNotFoundException');
$this->reader->read(__DIR__.'/Fixtures/res', 'foo');
}
public function testReadFailsIfNonExistingFallbackLocale()
{
$this->expectException('Symfony\Component\Intl\Exception\ResourceBundleNotFoundException');
$this->reader->read(__DIR__.'/Fixtures/res', 'ro_AT');
}
public function testReadFailsIfNonExistingDirectory()
{
$this->expectException('Symfony\Component\Intl\Exception\RuntimeException');
$this->reader->read(__DIR__.'/foo', 'ro');
}
}

View File

@@ -0,0 +1,70 @@
<?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\Data\Bundle\Reader;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Intl\Data\Bundle\Reader\JsonBundleReader;
/**
* @author Bernhard Schussek <bschussek@gmail.com>
*/
class JsonBundleReaderTest extends TestCase
{
/**
* @var JsonBundleReader
*/
private $reader;
protected function setUp()
{
$this->reader = new JsonBundleReader();
}
public function testReadReturnsArray()
{
$data = $this->reader->read(__DIR__.'/Fixtures/json', 'en');
$this->assertIsArray($data);
$this->assertSame('Bar', $data['Foo']);
$this->assertArrayNotHasKey('ExistsNot', $data);
}
public function testReadFailsIfNonExistingLocale()
{
$this->expectException('Symfony\Component\Intl\Exception\ResourceBundleNotFoundException');
$this->reader->read(__DIR__.'/Fixtures/json', 'foo');
}
public function testReadFailsIfNonExistingDirectory()
{
$this->expectException('Symfony\Component\Intl\Exception\RuntimeException');
$this->reader->read(__DIR__.'/foo', 'en');
}
public function testReadFailsIfNotAFile()
{
$this->expectException('Symfony\Component\Intl\Exception\RuntimeException');
$this->reader->read(__DIR__.'/Fixtures/NotAFile', 'en');
}
public function testReadFailsIfInvalidJson()
{
$this->expectException('Symfony\Component\Intl\Exception\RuntimeException');
$this->reader->read(__DIR__.'/Fixtures/json', 'en_Invalid');
}
public function testReaderDoesNotBreakOutOfGivenPath()
{
$this->expectException('Symfony\Component\Intl\Exception\ResourceBundleNotFoundException');
$this->reader->read(__DIR__.'/Fixtures/json', '../invalid_directory/en');
}
}

View File

@@ -0,0 +1,64 @@
<?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\Data\Bundle\Reader;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Intl\Data\Bundle\Reader\PhpBundleReader;
/**
* @author Bernhard Schussek <bschussek@gmail.com>
*/
class PhpBundleReaderTest extends TestCase
{
/**
* @var PhpBundleReader
*/
private $reader;
protected function setUp()
{
$this->reader = new PhpBundleReader();
}
public function testReadReturnsArray()
{
$data = $this->reader->read(__DIR__.'/Fixtures/php', 'en');
$this->assertIsArray($data);
$this->assertSame('Bar', $data['Foo']);
$this->assertArrayNotHasKey('ExistsNot', $data);
}
public function testReadFailsIfNonExistingLocale()
{
$this->expectException('Symfony\Component\Intl\Exception\ResourceBundleNotFoundException');
$this->reader->read(__DIR__.'/Fixtures/php', 'foo');
}
public function testReadFailsIfNonExistingDirectory()
{
$this->expectException('Symfony\Component\Intl\Exception\RuntimeException');
$this->reader->read(__DIR__.'/foo', 'en');
}
public function testReadFailsIfNotAFile()
{
$this->expectException('Symfony\Component\Intl\Exception\RuntimeException');
$this->reader->read(__DIR__.'/Fixtures/NotAFile', 'en');
}
public function testReaderDoesNotBreakOutOfGivenPath()
{
$this->expectException('Symfony\Component\Intl\Exception\ResourceBundleNotFoundException');
$this->reader->read(__DIR__.'/Fixtures/php', '../invalid_directory/en');
}
}

View File

@@ -0,0 +1,15 @@
{
"Entry1": {
"Array": [
"foo",
"bar"
],
"Integer": 5,
"Boolean": false,
"Float": 1.23
},
"Entry2": "String",
"Traversable": {
"Foo": "Bar"
}
}

View File

@@ -0,0 +1,17 @@
<?php
return [
'Entry1' => [
'Array' => [
0 => 'foo',
1 => 'bar',
],
'Integer' => 5,
'Boolean' => false,
'Float' => 1.23,
],
'Entry2' => 'String',
'Traversable' => [
'Foo' => 'Bar',
],
];

Binary file not shown.

View File

@@ -0,0 +1,39 @@
en{
Entry1{
Array{
"foo",
"bar",
{
Key{"value"}
},
}
Integer:int{5}
IntVector:intvector{
0,
1,
2,
3,
}
NotAnIntVector{
0:int{0}
2:int{1}
1:int{2}
3:int{3}
}
IntVectorWithStringKeys{
a:int{0}
b:int{1}
c:int{2}
}
TableWithIntKeys{
0:int{0}
1:int{1}
3:int{3}
}
FalseBoolean{"false"}
TrueBoolean{"true"}
Null{""}
Float{"1.23"}
}
Entry2{"String"}
}

View File

@@ -0,0 +1,3 @@
en_nofallback:table(nofallback){
Entry{"Value"}
}

View File

@@ -0,0 +1,4 @@
escaped{
"EntryWith:Colon"{"Value"}
"Entry With Spaces"{"Value"}
}

View File

@@ -0,0 +1,5 @@
{
"Entry": {
"NestedEntry": "Value"
}
}

View File

@@ -0,0 +1,7 @@
<?php
return [
'Entry' => [
'NestedEntry' => 'Value',
],
];

Binary file not shown.

View File

@@ -0,0 +1,5 @@
rb{
Entry{
NestedEntry{"Value"}
}
}

View File

@@ -0,0 +1,78 @@
<?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\Data\Bundle\Writer;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Intl\Data\Bundle\Writer\JsonBundleWriter;
/**
* @author Bernhard Schussek <bschussek@gmail.com>
*/
class JsonBundleWriterTest extends TestCase
{
/**
* @var JsonBundleWriter
*/
private $writer;
private $directory;
/**
* @var Filesystem
*/
private $filesystem;
protected function setUp()
{
$this->writer = new JsonBundleWriter();
$this->directory = sys_get_temp_dir().'/JsonBundleWriterTest/'.mt_rand(1000, 9999);
$this->filesystem = new Filesystem();
$this->filesystem->mkdir($this->directory);
}
protected function tearDown()
{
$this->filesystem->remove($this->directory);
}
public function testWrite()
{
$this->writer->write($this->directory, 'en', [
'Entry1' => [
'Array' => ['foo', 'bar'],
'Integer' => 5,
'Boolean' => false,
'Float' => 1.23,
],
'Entry2' => 'String',
'Traversable' => new \ArrayIterator([
'Foo' => 'Bar',
]),
]);
$this->assertFileEquals(__DIR__.'/Fixtures/en.json', $this->directory.'/en.json');
}
/**
* @requires extension intl
*/
public function testWriteResourceBundle()
{
$bundle = new \ResourceBundle('rb', __DIR__.'/Fixtures', false);
$this->writer->write($this->directory, 'en', $bundle);
$this->assertFileEquals(__DIR__.'/Fixtures/rb.json', $this->directory.'/en.json');
}
}

View File

@@ -0,0 +1,78 @@
<?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\Data\Bundle\Writer;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Intl\Data\Bundle\Writer\PhpBundleWriter;
/**
* @author Bernhard Schussek <bschussek@gmail.com>
*/
class PhpBundleWriterTest extends TestCase
{
/**
* @var PhpBundleWriter
*/
private $writer;
private $directory;
/**
* @var Filesystem
*/
private $filesystem;
protected function setUp()
{
$this->writer = new PhpBundleWriter();
$this->directory = sys_get_temp_dir().'/PhpBundleWriterTest/'.mt_rand(1000, 9999);
$this->filesystem = new Filesystem();
$this->filesystem->mkdir($this->directory);
}
protected function tearDown()
{
$this->filesystem->remove($this->directory);
}
public function testWrite()
{
$this->writer->write($this->directory, 'en', [
'Entry1' => [
'Array' => ['foo', 'bar'],
'Integer' => 5,
'Boolean' => false,
'Float' => 1.23,
],
'Entry2' => 'String',
'Traversable' => new \ArrayIterator([
'Foo' => 'Bar',
]),
]);
$this->assertFileEquals(__DIR__.'/Fixtures/en.php', $this->directory.'/en.php');
}
/**
* @requires extension intl
*/
public function testWriteResourceBundle()
{
$bundle = new \ResourceBundle('rb', __DIR__.'/Fixtures', false);
$this->writer->write($this->directory, 'en', $bundle);
$this->assertFileEquals(__DIR__.'/Fixtures/rb.php', $this->directory.'/en.php');
}
}

View File

@@ -0,0 +1,116 @@
<?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\Data\Bundle\Writer;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Intl\Data\Bundle\Writer\TextBundleWriter;
/**
* @author Bernhard Schussek <bschussek@gmail.com>
*
* @see http://source.icu-project.org/repos/icu/icuhtml/trunk/design/bnf_rb.txt
*/
class TextBundleWriterTest extends TestCase
{
/**
* @var TextBundleWriter
*/
private $writer;
private $directory;
/**
* @var Filesystem
*/
private $filesystem;
protected function setUp()
{
$this->writer = new TextBundleWriter();
$this->directory = sys_get_temp_dir().'/TextBundleWriterTest/'.mt_rand(1000, 9999);
$this->filesystem = new Filesystem();
$this->filesystem->mkdir($this->directory);
}
protected function tearDown()
{
$this->filesystem->remove($this->directory);
}
public function testWrite()
{
$this->writer->write($this->directory, 'en', [
'Entry1' => [
'Array' => ['foo', 'bar', ['Key' => 'value']],
'Integer' => 5,
'IntVector' => [0, 1, 2, 3],
'NotAnIntVector' => [0 => 0, 2 => 1, 1 => 2, 3 => 3],
'IntVectorWithStringKeys' => ['a' => 0, 'b' => 1, 'c' => 2],
'TableWithIntKeys' => [0 => 0, 1 => 1, 3 => 3],
'FalseBoolean' => false,
'TrueBoolean' => true,
'Null' => null,
'Float' => 1.23,
],
'Entry2' => 'String',
]);
$this->assertFileEquals(__DIR__.'/Fixtures/en.txt', $this->directory.'/en.txt');
}
public function testWriteTraversable()
{
$this->writer->write($this->directory, 'en', new \ArrayIterator([
'Entry1' => new \ArrayIterator([
'Array' => ['foo', 'bar', ['Key' => 'value']],
'Integer' => 5,
'IntVector' => [0, 1, 2, 3],
'NotAnIntVector' => [0 => 0, 2 => 1, 1 => 2, 3 => 3],
'IntVectorWithStringKeys' => ['a' => 0, 'b' => 1, 'c' => 2],
'TableWithIntKeys' => [0 => 0, 1 => 1, 3 => 3],
'FalseBoolean' => false,
'TrueBoolean' => true,
'Null' => null,
'Float' => 1.23,
]),
'Entry2' => 'String',
]));
$this->assertFileEquals(__DIR__.'/Fixtures/en.txt', $this->directory.'/en.txt');
}
public function testWriteNoFallback()
{
$data = [
'Entry' => 'Value',
];
$this->writer->write($this->directory, 'en_nofallback', $data, $fallback = false);
$this->assertFileEquals(__DIR__.'/Fixtures/en_nofallback.txt', $this->directory.'/en_nofallback.txt');
}
public function testEscapeKeysIfNecessary()
{
$this->writer->write($this->directory, 'escaped', [
// Keys with colons must be escaped, otherwise the part after the
// colon is interpreted as resource type
'EntryWith:Colon' => 'Value',
// Keys with spaces must be escaped
'Entry With Spaces' => 'Value',
]);
$this->assertFileEquals(__DIR__.'/Fixtures/escaped.txt', $this->directory.'/escaped.txt');
}
}

View File

@@ -0,0 +1,822 @@
<?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\Data\Provider;
use Symfony\Component\Intl\Data\Provider\CurrencyDataProvider;
use Symfony\Component\Intl\Intl;
/**
* @author Bernhard Schussek <bschussek@gmail.com>
*/
abstract class AbstractCurrencyDataProviderTest extends AbstractDataProviderTest
{
// The below arrays document the state of the ICU data bundled with this package.
protected static $currencies = [
'ADP',
'AED',
'AFA',
'AFN',
'ALK',
'ALL',
'AMD',
'ANG',
'AOA',
'AOK',
'AON',
'AOR',
'ARA',
'ARL',
'ARM',
'ARP',
'ARS',
'ATS',
'AUD',
'AWG',
'AZM',
'AZN',
'BAD',
'BAM',
'BAN',
'BBD',
'BDT',
'BEC',
'BEF',
'BEL',
'BGL',
'BGM',
'BGN',
'BGO',
'BHD',
'BIF',
'BMD',
'BND',
'BOB',
'BOL',
'BOP',
'BOV',
'BRB',
'BRC',
'BRE',
'BRL',
'BRN',
'BRR',
'BRZ',
'BSD',
'BTN',
'BUK',
'BWP',
'BYB',
'BYN',
'BYR',
'BZD',
'CAD',
'CDF',
'CHE',
'CHF',
'CHW',
'CLE',
'CLF',
'CLP',
'CNH',
'CNX',
'CNY',
'COP',
'COU',
'CRC',
'CSD',
'CSK',
'CUC',
'CUP',
'CVE',
'CYP',
'CZK',
'DDM',
'DEM',
'DJF',
'DKK',
'DOP',
'DZD',
'ECS',
'ECV',
'EEK',
'EGP',
'ERN',
'ESA',
'ESB',
'ESP',
'ETB',
'EUR',
'FIM',
'FJD',
'FKP',
'FRF',
'GBP',
'GEK',
'GEL',
'GHC',
'GHS',
'GIP',
'GMD',
'GNF',
'GNS',
'GQE',
'GRD',
'GTQ',
'GWE',
'GWP',
'GYD',
'HKD',
'HNL',
'HRD',
'HRK',
'HTG',
'HUF',
'IDR',
'IEP',
'ILP',
'ILR',
'ILS',
'INR',
'IQD',
'IRR',
'ISJ',
'ISK',
'ITL',
'JMD',
'JOD',
'JPY',
'KES',
'KGS',
'KHR',
'KMF',
'KPW',
'KRH',
'KRO',
'KRW',
'KWD',
'KYD',
'KZT',
'LAK',
'LBP',
'LKR',
'LRD',
'LSL',
'LTL',
'LTT',
'LUC',
'LUF',
'LUL',
'LVL',
'LVR',
'LYD',
'MAD',
'MAF',
'MCF',
'MDC',
'MDL',
'MGA',
'MGF',
'MKD',
'MKN',
'MLF',
'MMK',
'MNT',
'MOP',
'MRO',
'MRU',
'MTL',
'MTP',
'MUR',
'MVP',
'MVR',
'MWK',
'MXN',
'MXP',
'MXV',
'MYR',
'MZE',
'MZM',
'MZN',
'NAD',
'NGN',
'NIC',
'NIO',
'NLG',
'NOK',
'NPR',
'NZD',
'OMR',
'PAB',
'PEI',
'PEN',
'PES',
'PGK',
'PHP',
'PKR',
'PLN',
'PLZ',
'PTE',
'PYG',
'QAR',
'RHD',
'ROL',
'RON',
'RSD',
'RUB',
'RUR',
'RWF',
'SAR',
'SBD',
'SCR',
'SDD',
'SDG',
'SDP',
'SEK',
'SGD',
'SHP',
'SIT',
'SKK',
'SLL',
'SOS',
'SRD',
'SRG',
'SSP',
'STD',
'STN',
'SUR',
'SVC',
'SYP',
'SZL',
'THB',
'TJR',
'TJS',
'TMM',
'TMT',
'TND',
'TOP',
'TPE',
'TRL',
'TRY',
'TTD',
'TWD',
'TZS',
'UAH',
'UAK',
'UGS',
'UGX',
'USD',
'USN',
'USS',
'UYI',
'UYP',
'UYU',
'UYW',
'UZS',
'VEB',
'VEF',
'VES',
'VND',
'VNN',
'VUV',
'WST',
'XAF',
'XCD',
'XEU',
'XFO',
'XFU',
'XOF',
'XPF',
'XRE',
'YDD',
'YER',
'YUD',
'YUM',
'YUN',
'YUR',
'ZAL',
'ZAR',
'ZMK',
'ZMW',
'ZRN',
'ZRZ',
'ZWD',
'ZWL',
'ZWR',
];
protected static $alpha3ToNumeric = [
'AFA' => 4,
'ALK' => 8,
'ALL' => 8,
'DZD' => 12,
'ADP' => 20,
'AON' => 24,
'AOK' => 24,
'AZM' => 31,
'ARA' => 32,
'ARP' => 32,
'ARS' => 32,
'AUD' => 36,
'ATS' => 40,
'BSD' => 44,
'BHD' => 48,
'BDT' => 50,
'AMD' => 51,
'BBD' => 52,
'BEF' => 56,
'BMD' => 60,
'BTN' => 64,
'BOB' => 68,
'BOP' => 68,
'BAD' => 70,
'BWP' => 72,
'BRN' => 76,
'BRE' => 76,
'BRC' => 76,
'BRB' => 76,
'BZD' => 84,
'SBD' => 90,
'BND' => 96,
'BGL' => 100,
'MMK' => 104,
'BUK' => 104,
'BIF' => 108,
'BYB' => 112,
'KHR' => 116,
'CAD' => 124,
'CVE' => 132,
'KYD' => 136,
'LKR' => 144,
'CLP' => 152,
'CNY' => 156,
'COP' => 170,
'KMF' => 174,
'ZRZ' => 180,
'ZRN' => 180,
'CRC' => 188,
'HRK' => 191,
'HRD' => 191,
'CUP' => 192,
'CYP' => 196,
'CSK' => 200,
'CZK' => 203,
'DKK' => 208,
'DOP' => 214,
'ECS' => 218,
'SVC' => 222,
'GQE' => 226,
'ETB' => 230,
'ERN' => 232,
'EEK' => 233,
'FKP' => 238,
'FJD' => 242,
'FIM' => 246,
'FRF' => 250,
'DJF' => 262,
'GEK' => 268,
'GMD' => 270,
'DEM' => 276,
'DDM' => 278,
'GHC' => 288,
'GIP' => 292,
'GRD' => 300,
'GTQ' => 320,
'GNS' => 324,
'GNF' => 324,
'GYD' => 328,
'HTG' => 332,
'HNL' => 340,
'HKD' => 344,
'HUF' => 348,
'ISJ' => 352,
'ISK' => 352,
'INR' => 356,
'IDR' => 360,
'IRR' => 364,
'IQD' => 368,
'IEP' => 372,
'ILP' => 376,
'ILR' => 376,
'ILS' => 376,
'ITL' => 380,
'JMD' => 388,
'JPY' => 392,
'KZT' => 398,
'JOD' => 400,
'KES' => 404,
'KPW' => 408,
'KRW' => 410,
'KWD' => 414,
'KGS' => 417,
'LAK' => 418,
'LBP' => 422,
'LSL' => 426,
'LVR' => 428,
'LVL' => 428,
'LRD' => 430,
'LYD' => 434,
'LTL' => 440,
'LTT' => 440,
'LUF' => 442,
'MOP' => 446,
'MGF' => 450,
'MWK' => 454,
'MYR' => 458,
'MVR' => 462,
'MLF' => 466,
'MTL' => 470,
'MTP' => 470,
'MRO' => 478,
'MUR' => 480,
'MXP' => 484,
'MXN' => 484,
'MNT' => 496,
'MDL' => 498,
'MAD' => 504,
'MZE' => 508,
'MZM' => 508,
'OMR' => 512,
'NAD' => 516,
'NPR' => 524,
'NLG' => 528,
'ANG' => 532,
'AWG' => 533,
'VUV' => 548,
'NZD' => 554,
'NIC' => 558,
'NIO' => 558,
'NGN' => 566,
'NOK' => 578,
'PKR' => 586,
'PAB' => 590,
'PGK' => 598,
'PYG' => 600,
'PEI' => 604,
'PES' => 604,
'PEN' => 604,
'PHP' => 608,
'PLZ' => 616,
'PTE' => 620,
'GWP' => 624,
'GWE' => 624,
'TPE' => 626,
'QAR' => 634,
'ROL' => 642,
'RUB' => 643,
'RWF' => 646,
'SHP' => 654,
'STD' => 678,
'SAR' => 682,
'SCR' => 690,
'SLL' => 694,
'SGD' => 702,
'SKK' => 703,
'VND' => 704,
'SIT' => 705,
'SOS' => 706,
'ZAR' => 710,
'ZWD' => 716,
'RHD' => 716,
'YDD' => 720,
'ESP' => 724,
'SSP' => 728,
'SDD' => 736,
'SDP' => 736,
'SRG' => 740,
'SZL' => 748,
'SEK' => 752,
'CHF' => 756,
'SYP' => 760,
'TJR' => 762,
'THB' => 764,
'TOP' => 776,
'TTD' => 780,
'AED' => 784,
'TND' => 788,
'TRL' => 792,
'TMM' => 795,
'UGX' => 800,
'UGS' => 800,
'UAK' => 804,
'MKD' => 807,
'RUR' => 810,
'SUR' => 810,
'EGP' => 818,
'GBP' => 826,
'TZS' => 834,
'USD' => 840,
'UYP' => 858,
'UYU' => 858,
'UZS' => 860,
'VEB' => 862,
'WST' => 882,
'YER' => 886,
'YUN' => 890,
'YUD' => 890,
'YUM' => 891,
'CSD' => 891,
'ZMK' => 894,
'TWD' => 901,
'UYW' => 927,
'VES' => 928,
'MRU' => 929,
'STN' => 930,
'CUC' => 931,
'ZWL' => 932,
'BYN' => 933,
'TMT' => 934,
'ZWR' => 935,
'GHS' => 936,
'VEF' => 937,
'SDG' => 938,
'UYI' => 940,
'RSD' => 941,
'MZN' => 943,
'AZN' => 944,
'RON' => 946,
'CHE' => 947,
'CHW' => 948,
'TRY' => 949,
'XAF' => 950,
'XCD' => 951,
'XOF' => 952,
'XPF' => 953,
'XEU' => 954,
'ZMW' => 967,
'SRD' => 968,
'MGA' => 969,
'COU' => 970,
'AFN' => 971,
'TJS' => 972,
'AOA' => 973,
'BYR' => 974,
'BGN' => 975,
'CDF' => 976,
'BAM' => 977,
'EUR' => 978,
'MXV' => 979,
'UAH' => 980,
'GEL' => 981,
'AOR' => 982,
'ECV' => 983,
'BOV' => 984,
'PLN' => 985,
'BRL' => 986,
'BRR' => 987,
'LUL' => 988,
'LUC' => 989,
'CLF' => 990,
'ZAL' => 991,
'BEL' => 992,
'BEC' => 993,
'ESB' => 995,
'ESA' => 996,
'USN' => 997,
'USS' => 998,
];
/**
* @var CurrencyDataProvider
*/
protected $dataProvider;
private $defaultLocale;
protected function setUp()
{
parent::setUp();
$this->dataProvider = new CurrencyDataProvider(
$this->getDataDirectory().'/'.Intl::CURRENCY_DIR,
$this->createEntryReader()
);
$this->defaultLocale = \Locale::getDefault();
}
protected function tearDown()
{
parent::tearDown();
\Locale::setDefault($this->defaultLocale);
}
abstract protected function getDataDirectory();
public function testGetCurrencies()
{
$this->assertSame(static::$currencies, $this->dataProvider->getCurrencies());
}
/**
* @dataProvider provideLocales
*/
public function testGetNames($displayLocale)
{
$names = $this->dataProvider->getNames($displayLocale);
$keys = array_keys($names);
sort($keys);
$this->assertEquals(static::$currencies, $keys);
// Names should be sorted
$sortedNames = $names;
$collator = new \Collator($displayLocale);
$collator->asort($names);
$this->assertEquals($sortedNames, $names);
}
public function testGetNamesDefaultLocale()
{
\Locale::setDefault('de_AT');
$this->assertSame(
$this->dataProvider->getNames('de_AT'),
$this->dataProvider->getNames()
);
}
/**
* @dataProvider provideLocaleAliases
*/
public function testGetNamesSupportsAliases($alias, $ofLocale)
{
// Can't use assertSame(), because some aliases contain scripts with
// different collation (=order of output) than their aliased locale
// e.g. sr_Latn_ME => sr_ME
$this->assertEquals(
$this->dataProvider->getNames($ofLocale),
$this->dataProvider->getNames($alias)
);
}
/**
* @dataProvider provideLocales
*/
public function testGetName($displayLocale)
{
$expected = $this->dataProvider->getNames($displayLocale);
$actual = [];
foreach ($expected as $currency => $name) {
$actual[$currency] = $this->dataProvider->getName($currency, $displayLocale);
}
$this->assertSame($expected, $actual);
}
public function testGetNameDefaultLocale()
{
\Locale::setDefault('de_AT');
$expected = $this->dataProvider->getNames('de_AT');
$actual = [];
foreach ($expected as $currency => $name) {
$actual[$currency] = $this->dataProvider->getName($currency);
}
$this->assertSame($expected, $actual);
}
/**
* @dataProvider provideLocales
*/
public function testGetSymbol($displayLocale)
{
$currencies = $this->dataProvider->getCurrencies();
foreach ($currencies as $currency) {
$this->assertGreaterThan(0, mb_strlen($this->dataProvider->getSymbol($currency, $displayLocale)));
}
}
public function provideCurrencies()
{
return array_map(
function ($currency) { return [$currency]; },
static::$currencies
);
}
/**
* @dataProvider provideCurrencies
*/
public function testGetFractionDigits($currency)
{
$this->assertIsNumeric($this->dataProvider->getFractionDigits($currency));
}
/**
* @dataProvider provideCurrencies
*/
public function testGetRoundingIncrement($currency)
{
$this->assertIsNumeric($this->dataProvider->getRoundingIncrement($currency));
}
public function provideCurrenciesWithNumericEquivalent()
{
return array_map(
function ($value) { return [$value]; },
array_keys(static::$alpha3ToNumeric)
);
}
/**
* @dataProvider provideCurrenciesWithNumericEquivalent
*/
public function testGetNumericCode($currency)
{
$this->assertSame(static::$alpha3ToNumeric[$currency], $this->dataProvider->getNumericCode($currency));
}
public function provideCurrenciesWithoutNumericEquivalent()
{
return array_map(
function ($value) { return [$value]; },
array_diff(static::$currencies, array_keys(static::$alpha3ToNumeric))
);
}
/**
* @dataProvider provideCurrenciesWithoutNumericEquivalent
*/
public function testGetNumericCodeFailsIfNoNumericEquivalent($currency)
{
$this->expectException('Symfony\Component\Intl\Exception\MissingResourceException');
$this->dataProvider->getNumericCode($currency);
}
public function provideValidNumericCodes()
{
$numericToAlpha3 = $this->getNumericToAlpha3Mapping();
return array_map(
function ($numeric, $alpha3) { return [$numeric, $alpha3]; },
array_keys($numericToAlpha3),
$numericToAlpha3
);
}
/**
* @dataProvider provideValidNumericCodes
*/
public function testForNumericCode($numeric, $expected)
{
$actual = $this->dataProvider->forNumericCode($numeric);
// Make sure that a different array order doesn't break the test
sort($actual);
sort($expected);
$this->assertEquals($expected, $actual);
}
public function provideInvalidNumericCodes()
{
$validNumericCodes = array_keys($this->getNumericToAlpha3Mapping());
$invalidNumericCodes = array_diff(range(0, 1000), $validNumericCodes);
return array_map(
function ($value) { return [$value]; },
$invalidNumericCodes
);
}
/**
* @dataProvider provideInvalidNumericCodes
*/
public function testForNumericCodeFailsIfInvalidNumericCode($currency)
{
$this->expectException('Symfony\Component\Intl\Exception\MissingResourceException');
$this->dataProvider->forNumericCode($currency);
}
private function getNumericToAlpha3Mapping()
{
$numericToAlpha3 = [];
foreach (static::$alpha3ToNumeric as $alpha3 => $numeric) {
if (!isset($numericToAlpha3[$numeric])) {
$numericToAlpha3[$numeric] = [];
}
$numericToAlpha3[$numeric][] = $alpha3;
}
return $numericToAlpha3;
}
}

View File

@@ -0,0 +1,800 @@
<?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\Data\Provider;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Intl\Data\Bundle\Reader\BundleEntryReader;
use Symfony\Component\Intl\Data\Bundle\Reader\BundleReaderInterface;
use Symfony\Component\Intl\Locale;
/**
* @author Bernhard Schussek <bschussek@gmail.com>
*/
abstract class AbstractDataProviderTest extends TestCase
{
// Include the locales statically so that the data providers are decoupled
// from the Intl class. Otherwise tests will fail if the intl extension is
// not loaded, because it is NOT possible to skip the execution of data
// providers.
private static $locales = [
'af',
'af_NA',
'af_ZA',
'ak',
'ak_GH',
'am',
'am_ET',
'ar',
'ar_001',
'ar_AE',
'ar_BH',
'ar_DJ',
'ar_DZ',
'ar_EG',
'ar_EH',
'ar_ER',
'ar_IL',
'ar_IQ',
'ar_JO',
'ar_KM',
'ar_KW',
'ar_LB',
'ar_LY',
'ar_MA',
'ar_MR',
'ar_OM',
'ar_PS',
'ar_QA',
'ar_SA',
'ar_SD',
'ar_SO',
'ar_SS',
'ar_SY',
'ar_TD',
'ar_TN',
'ar_YE',
'as',
'as_IN',
'az',
'az_AZ',
'az_Cyrl',
'az_Cyrl_AZ',
'az_Latn',
'az_Latn_AZ',
'be',
'be_BY',
'bg',
'bg_BG',
'bm',
'bm_ML',
'bn',
'bn_BD',
'bn_IN',
'bo',
'bo_CN',
'bo_IN',
'br',
'br_FR',
'bs',
'bs_BA',
'bs_Cyrl',
'bs_Cyrl_BA',
'bs_Latn',
'bs_Latn_BA',
'ca',
'ca_AD',
'ca_ES',
'ca_FR',
'ca_IT',
'ce',
'ce_RU',
'cs',
'cs_CZ',
'cy',
'cy_GB',
'da',
'da_DK',
'da_GL',
'de',
'de_AT',
'de_BE',
'de_CH',
'de_DE',
'de_IT',
'de_LI',
'de_LU',
'dz',
'dz_BT',
'ee',
'ee_GH',
'ee_TG',
'el',
'el_CY',
'el_GR',
'en',
'en_001',
'en_150',
'en_AE',
'en_AG',
'en_AI',
'en_AS',
'en_AT',
'en_AU',
'en_BB',
'en_BE',
'en_BI',
'en_BM',
'en_BS',
'en_BW',
'en_BZ',
'en_CA',
'en_CC',
'en_CH',
'en_CK',
'en_CM',
'en_CX',
'en_CY',
'en_DE',
'en_DG',
'en_DK',
'en_DM',
'en_ER',
'en_FI',
'en_FJ',
'en_FK',
'en_FM',
'en_GB',
'en_GD',
'en_GG',
'en_GH',
'en_GI',
'en_GM',
'en_GU',
'en_GY',
'en_HK',
'en_IE',
'en_IL',
'en_IM',
'en_IN',
'en_IO',
'en_JE',
'en_JM',
'en_KE',
'en_KI',
'en_KN',
'en_KY',
'en_LC',
'en_LR',
'en_LS',
'en_MG',
'en_MH',
'en_MO',
'en_MP',
'en_MS',
'en_MT',
'en_MU',
'en_MW',
'en_MY',
'en_NA',
'en_NF',
'en_NG',
'en_NH',
'en_NL',
'en_NR',
'en_NU',
'en_NZ',
'en_PG',
'en_PH',
'en_PK',
'en_PN',
'en_PR',
'en_PW',
'en_RH',
'en_RW',
'en_SB',
'en_SC',
'en_SD',
'en_SE',
'en_SG',
'en_SH',
'en_SI',
'en_SL',
'en_SS',
'en_SX',
'en_SZ',
'en_TC',
'en_TK',
'en_TO',
'en_TT',
'en_TV',
'en_TZ',
'en_UG',
'en_UM',
'en_US',
'en_US_POSIX',
'en_VC',
'en_VG',
'en_VI',
'en_VU',
'en_WS',
'en_ZA',
'en_ZM',
'en_ZW',
'eo',
'eo_001',
'es',
'es_419',
'es_AR',
'es_BO',
'es_BR',
'es_BZ',
'es_CL',
'es_CO',
'es_CR',
'es_CU',
'es_DO',
'es_EA',
'es_EC',
'es_ES',
'es_GQ',
'es_GT',
'es_HN',
'es_IC',
'es_MX',
'es_NI',
'es_PA',
'es_PE',
'es_PH',
'es_PR',
'es_PY',
'es_SV',
'es_US',
'es_UY',
'es_VE',
'et',
'et_EE',
'eu',
'eu_ES',
'fa',
'fa_AF',
'fa_IR',
'ff',
'ff_Adlm',
'ff_Adlm_BF',
'ff_Adlm_CM',
'ff_Adlm_GH',
'ff_Adlm_GM',
'ff_Adlm_GN',
'ff_Adlm_GW',
'ff_Adlm_LR',
'ff_Adlm_MR',
'ff_Adlm_NE',
'ff_Adlm_NG',
'ff_Adlm_SL',
'ff_Adlm_SN',
'ff_CM',
'ff_GN',
'ff_Latn',
'ff_Latn_BF',
'ff_Latn_CM',
'ff_Latn_GH',
'ff_Latn_GM',
'ff_Latn_GN',
'ff_Latn_GW',
'ff_Latn_LR',
'ff_Latn_MR',
'ff_Latn_NE',
'ff_Latn_NG',
'ff_Latn_SL',
'ff_Latn_SN',
'ff_MR',
'ff_SN',
'fi',
'fi_FI',
'fo',
'fo_DK',
'fo_FO',
'fr',
'fr_BE',
'fr_BF',
'fr_BI',
'fr_BJ',
'fr_BL',
'fr_CA',
'fr_CD',
'fr_CF',
'fr_CG',
'fr_CH',
'fr_CI',
'fr_CM',
'fr_DJ',
'fr_DZ',
'fr_FR',
'fr_GA',
'fr_GF',
'fr_GN',
'fr_GP',
'fr_GQ',
'fr_HT',
'fr_KM',
'fr_LU',
'fr_MA',
'fr_MC',
'fr_MF',
'fr_MG',
'fr_ML',
'fr_MQ',
'fr_MR',
'fr_MU',
'fr_NC',
'fr_NE',
'fr_PF',
'fr_PM',
'fr_RE',
'fr_RW',
'fr_SC',
'fr_SN',
'fr_SY',
'fr_TD',
'fr_TG',
'fr_TN',
'fr_VU',
'fr_WF',
'fr_YT',
'fy',
'fy_NL',
'ga',
'ga_GB',
'ga_IE',
'gd',
'gd_GB',
'gl',
'gl_ES',
'gu',
'gu_IN',
'gv',
'gv_IM',
'ha',
'ha_GH',
'ha_NE',
'ha_NG',
'he',
'he_IL',
'hi',
'hi_IN',
'hr',
'hr_BA',
'hr_HR',
'hu',
'hu_HU',
'hy',
'hy_AM',
'ia',
'ia_001',
'id',
'id_ID',
'ig',
'ig_NG',
'ii',
'ii_CN',
'in',
'in_ID',
'is',
'is_IS',
'it',
'it_CH',
'it_IT',
'it_SM',
'it_VA',
'iw',
'iw_IL',
'ja',
'ja_JP',
'ja_JP_TRADITIONAL',
'jv',
'jv_ID',
'ka',
'ka_GE',
'ki',
'ki_KE',
'kk',
'kk_KZ',
'kl',
'kl_GL',
'km',
'km_KH',
'kn',
'kn_IN',
'ko',
'ko_KP',
'ko_KR',
'ks',
'ks_Arab',
'ks_Arab_IN',
'ks_IN',
'ku',
'ku_TR',
'kw',
'kw_GB',
'ky',
'ky_KG',
'lb',
'lb_LU',
'lg',
'lg_UG',
'ln',
'ln_AO',
'ln_CD',
'ln_CF',
'ln_CG',
'lo',
'lo_LA',
'lt',
'lt_LT',
'lu',
'lu_CD',
'lv',
'lv_LV',
'mg',
'mg_MG',
'mi',
'mi_NZ',
'mk',
'mk_MK',
'ml',
'ml_IN',
'mn',
'mn_MN',
'mo',
'mr',
'mr_IN',
'ms',
'ms_BN',
'ms_ID',
'ms_MY',
'ms_SG',
'mt',
'mt_MT',
'my',
'my_MM',
'nb',
'nb_NO',
'nb_SJ',
'nd',
'nd_ZW',
'ne',
'ne_IN',
'ne_NP',
'nl',
'nl_AW',
'nl_BE',
'nl_BQ',
'nl_CW',
'nl_NL',
'nl_SR',
'nl_SX',
'nn',
'nn_NO',
'no',
'no_NO',
'no_NO_NY',
'om',
'om_ET',
'om_KE',
'or',
'or_IN',
'os',
'os_GE',
'os_RU',
'pa',
'pa_Arab',
'pa_Arab_PK',
'pa_Guru',
'pa_Guru_IN',
'pa_IN',
'pa_PK',
'pl',
'pl_PL',
'ps',
'ps_AF',
'ps_PK',
'pt',
'pt_AO',
'pt_BR',
'pt_CH',
'pt_CV',
'pt_GQ',
'pt_GW',
'pt_LU',
'pt_MO',
'pt_MZ',
'pt_PT',
'pt_ST',
'pt_TL',
'qu',
'qu_BO',
'qu_EC',
'qu_PE',
'rm',
'rm_CH',
'rn',
'rn_BI',
'ro',
'ro_MD',
'ro_RO',
'ru',
'ru_BY',
'ru_KG',
'ru_KZ',
'ru_MD',
'ru_RU',
'ru_UA',
'rw',
'rw_RW',
'sd',
'sd_Arab',
'sd_Arab_PK',
'sd_Deva',
'sd_Deva_IN',
'sd_PK',
'se',
'se_FI',
'se_NO',
'se_SE',
'sg',
'sg_CF',
'sh',
'sh_BA',
'sh_CS',
'sh_YU',
'si',
'si_LK',
'sk',
'sk_SK',
'sl',
'sl_SI',
'sn',
'sn_ZW',
'so',
'so_DJ',
'so_ET',
'so_KE',
'so_SO',
'sq',
'sq_AL',
'sq_MK',
'sq_XK',
'sr',
'sr_BA',
'sr_CS',
'sr_Cyrl',
'sr_Cyrl_BA',
'sr_Cyrl_CS',
'sr_Cyrl_ME',
'sr_Cyrl_RS',
'sr_Cyrl_XK',
'sr_Cyrl_YU',
'sr_Latn',
'sr_Latn_BA',
'sr_Latn_CS',
'sr_Latn_ME',
'sr_Latn_RS',
'sr_Latn_XK',
'sr_Latn_YU',
'sr_ME',
'sr_RS',
'sr_XK',
'sr_YU',
'su',
'su_ID',
'su_Latn',
'su_Latn_ID',
'sv',
'sv_AX',
'sv_FI',
'sv_SE',
'sw',
'sw_CD',
'sw_KE',
'sw_TZ',
'sw_UG',
'ta',
'ta_IN',
'ta_LK',
'ta_MY',
'ta_SG',
'te',
'te_IN',
'tg',
'tg_TJ',
'th',
'th_TH',
'th_TH_TRADITIONAL',
'ti',
'ti_ER',
'ti_ET',
'tk',
'tk_TM',
'tl',
'tl_PH',
'to',
'to_TO',
'tr',
'tr_CY',
'tr_TR',
'tt',
'tt_RU',
'ug',
'ug_CN',
'uk',
'uk_UA',
'ur',
'ur_IN',
'ur_PK',
'uz',
'uz_AF',
'uz_Arab',
'uz_Arab_AF',
'uz_Cyrl',
'uz_Cyrl_UZ',
'uz_Latn',
'uz_Latn_UZ',
'uz_UZ',
'vi',
'vi_VN',
'wo',
'wo_SN',
'xh',
'xh_ZA',
'yi',
'yi_001',
'yo',
'yo_BJ',
'yo_NG',
'zh',
'zh_CN',
'zh_HK',
'zh_Hans',
'zh_Hans_CN',
'zh_Hans_HK',
'zh_Hans_MO',
'zh_Hans_SG',
'zh_Hant',
'zh_Hant_HK',
'zh_Hant_MO',
'zh_Hant_TW',
'zh_MO',
'zh_SG',
'zh_TW',
'zu',
'zu_ZA',
];
private static $localeAliases = [
'az_AZ' => 'az_Latn_AZ',
'bs_BA' => 'bs_Latn_BA',
'en_NH' => 'en_VU',
'en_RH' => 'en_ZW',
'ff_CM' => 'ff_Latn_CM',
'ff_GN' => 'ff_Latn_GN',
'ff_MR' => 'ff_Latn_MR',
'ff_SN' => 'ff_Latn_SN',
'in' => 'id',
'in_ID' => 'id_ID',
'iw' => 'he',
'iw_IL' => 'he_IL',
'ks_IN' => 'ks_Arab_IN',
'mo' => 'ro',
'no' => 'nb',
'no_NO' => 'nb_NO',
'no_NO_NY' => 'nn_NO',
'pa_IN' => 'pa_Guru_IN',
'pa_PK' => 'pa_Arab_PK',
'sd_PK' => 'sd_Arab_PK',
'sh' => 'sr_Latn',
'sh_BA' => 'sr_Latn_BA',
'sh_CS' => 'sr_Latn_RS',
'sh_YU' => 'sr_Latn_RS',
'sr_BA' => 'sr_Cyrl_BA',
'sr_CS' => 'sr_Cyrl_RS',
'sr_Cyrl_CS' => 'sr_Cyrl_RS',
'sr_Cyrl_YU' => 'sr_Cyrl_RS',
'sr_Latn_CS' => 'sr_Latn_RS',
'sr_Latn_YU' => 'sr_Latn_RS',
'sr_ME' => 'sr_Latn_ME',
'sr_RS' => 'sr_Cyrl_RS',
'sr_XK' => 'sr_Cyrl_XK',
'sr_YU' => 'sr_Cyrl_RS',
'su_ID' => 'su_Latn_ID',
'tl' => 'fil',
'tl_PH' => 'fil_PH',
'uz_AF' => 'uz_Arab_AF',
'uz_UZ' => 'uz_Latn_UZ',
'zh_CN' => 'zh_Hans_CN',
'zh_HK' => 'zh_Hant_HK',
'zh_MO' => 'zh_Hant_MO',
'zh_SG' => 'zh_Hans_SG',
'zh_TW' => 'zh_Hant_TW',
];
private static $rootLocales;
protected function setUp()
{
\Locale::setDefault('en');
Locale::setDefaultFallback('en');
}
public function provideLocales()
{
return array_map(
function ($locale) { return [$locale]; },
$this->getLocales()
);
}
public function provideLocaleAliases()
{
return array_map(
function ($alias, $ofLocale) { return [$alias, $ofLocale]; },
array_keys($this->getLocaleAliases()),
$this->getLocaleAliases()
);
}
public function provideRootLocales()
{
return array_map(
function ($locale) { return [$locale]; },
$this->getRootLocales()
);
}
protected function getLocales()
{
return self::$locales;
}
protected function getLocaleAliases()
{
return self::$localeAliases;
}
protected function getRootLocales()
{
if (null === self::$rootLocales) {
self::$rootLocales = array_filter(static::getLocales(), function ($locale) {
// no locales for which fallback is possible (e.g "en_GB")
return false === strpos($locale, '_');
});
}
return self::$rootLocales;
}
/**
* @return BundleEntryReader
*/
protected function createEntryReader()
{
$entryReader = new BundleEntryReader($this->createBundleReader());
$entryReader->setLocaleAliases($this->getLocaleAliases());
return $entryReader;
}
/**
* @return BundleReaderInterface
*/
abstract protected function createBundleReader();
}

View File

@@ -0,0 +1,955 @@
<?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\Data\Provider;
use Symfony\Component\Intl\Data\Provider\LanguageDataProvider;
use Symfony\Component\Intl\Intl;
/**
* @author Bernhard Schussek <bschussek@gmail.com>
*/
abstract class AbstractLanguageDataProviderTest extends AbstractDataProviderTest
{
// The below arrays document the state of the ICU data bundled with this package.
protected static $languages = [
'aa',
'ab',
'ace',
'ach',
'ada',
'ady',
'ae',
'aeb',
'af',
'afh',
'agq',
'ain',
'ak',
'akk',
'akz',
'ale',
'aln',
'alt',
'am',
'an',
'ang',
'anp',
'ar',
'ar_001',
'arc',
'arn',
'aro',
'arp',
'arq',
'ars',
'arw',
'ary',
'arz',
'as',
'asa',
'ase',
'ast',
'av',
'avk',
'awa',
'ay',
'az',
'az_Arab',
'ba',
'bal',
'ban',
'bar',
'bas',
'bax',
'bbc',
'bbj',
'be',
'bej',
'bem',
'bew',
'bez',
'bfd',
'bfq',
'bg',
'bgn',
'bho',
'bi',
'bik',
'bin',
'bjn',
'bkm',
'bla',
'bm',
'bn',
'bo',
'bpy',
'bqi',
'br',
'bra',
'brh',
'brx',
'bs',
'bss',
'bua',
'bug',
'bum',
'byn',
'byv',
'ca',
'cad',
'car',
'cay',
'cch',
'ccp',
'ce',
'ceb',
'cgg',
'ch',
'chb',
'chg',
'chk',
'chm',
'chn',
'cho',
'chp',
'chr',
'chy',
'cic',
'ckb',
'co',
'cop',
'cps',
'cr',
'crh',
'crs',
'cs',
'csb',
'cu',
'cv',
'cy',
'da',
'dak',
'dar',
'dav',
'de',
'de_AT',
'de_CH',
'del',
'den',
'dgr',
'din',
'dje',
'doi',
'dsb',
'dtp',
'dua',
'dum',
'dv',
'dyo',
'dyu',
'dz',
'dzg',
'ebu',
'ee',
'efi',
'egl',
'egy',
'eka',
'el',
'elx',
'en',
'en_AU',
'en_CA',
'en_GB',
'en_US',
'enm',
'eo',
'es',
'es_419',
'es_ES',
'es_MX',
'esu',
'et',
'eu',
'ewo',
'ext',
'fa',
'fa_AF',
'fan',
'fat',
'ff',
'fi',
'fil',
'fit',
'fj',
'fo',
'fon',
'fr',
'fr_CA',
'fr_CH',
'frc',
'frm',
'fro',
'frp',
'frr',
'frs',
'fur',
'fy',
'ga',
'gaa',
'gag',
'gan',
'gay',
'gba',
'gbz',
'gd',
'gez',
'gil',
'gl',
'glk',
'gmh',
'gn',
'goh',
'gom',
'gon',
'gor',
'got',
'grb',
'grc',
'gsw',
'gu',
'guc',
'gur',
'guz',
'gv',
'gwi',
'ha',
'hai',
'hak',
'haw',
'he',
'hi',
'hif',
'hil',
'hit',
'hmn',
'ho',
'hr',
'hsb',
'hsn',
'ht',
'hu',
'hup',
'hy',
'hz',
'ia',
'iba',
'ibb',
'id',
'ie',
'ig',
'ii',
'ik',
'ilo',
'inh',
'io',
'is',
'it',
'iu',
'izh',
'ja',
'jam',
'jbo',
'jgo',
'jmc',
'jpr',
'jrb',
'jut',
'jv',
'ka',
'kaa',
'kab',
'kac',
'kaj',
'kam',
'kaw',
'kbd',
'kbl',
'kcg',
'kde',
'kea',
'ken',
'kfo',
'kg',
'kgp',
'kha',
'kho',
'khq',
'khw',
'ki',
'kiu',
'kj',
'kk',
'kkj',
'kl',
'kln',
'km',
'kmb',
'kn',
'ko',
'koi',
'kok',
'kos',
'kpe',
'kr',
'krc',
'kri',
'krj',
'krl',
'kru',
'ks',
'ksb',
'ksf',
'ksh',
'ku',
'kum',
'kut',
'kv',
'kw',
'ky',
'la',
'lad',
'lag',
'lah',
'lam',
'lb',
'lez',
'lfn',
'lg',
'li',
'lij',
'liv',
'lkt',
'lmo',
'ln',
'lo',
'lol',
'lou',
'loz',
'lrc',
'lt',
'ltg',
'lu',
'lua',
'lui',
'lun',
'luo',
'lus',
'luy',
'lv',
'lzh',
'lzz',
'mad',
'maf',
'mag',
'mai',
'mak',
'man',
'mas',
'mde',
'mdf',
'mdr',
'men',
'mer',
'mfe',
'mg',
'mga',
'mgh',
'mgo',
'mh',
'mi',
'mic',
'min',
'mk',
'ml',
'mn',
'mnc',
'mni',
'moh',
'mos',
'mr',
'mrj',
'ms',
'mt',
'mua',
'mul',
'mus',
'mwl',
'mwr',
'mwv',
'my',
'mye',
'myv',
'mzn',
'na',
'nan',
'nap',
'naq',
'nb',
'nd',
'nds',
'nds_NL',
'ne',
'new',
'ng',
'nia',
'niu',
'njo',
'nl',
'nl_BE',
'nmg',
'nn',
'nnh',
'no',
'nog',
'non',
'nov',
'nqo',
'nr',
'nso',
'nus',
'nv',
'nwc',
'ny',
'nym',
'nyn',
'nyo',
'nzi',
'oc',
'oj',
'om',
'or',
'os',
'osa',
'ota',
'pa',
'pag',
'pal',
'pam',
'pap',
'pau',
'pcd',
'pcm',
'pdc',
'pdt',
'peo',
'pfl',
'phn',
'pi',
'pl',
'pms',
'pnt',
'pon',
'prg',
'pro',
'ps',
'pt',
'pt_BR',
'pt_PT',
'qu',
'quc',
'qug',
'raj',
'rap',
'rar',
'rgn',
'rif',
'rm',
'rn',
'ro',
'ro_MD',
'rof',
'rom',
'root',
'rtm',
'ru',
'rue',
'rug',
'rup',
'rw',
'rwk',
'sa',
'sad',
'sah',
'sam',
'saq',
'sas',
'sat',
'saz',
'sba',
'sbp',
'sc',
'scn',
'sco',
'sd',
'sdc',
'sdh',
'se',
'see',
'seh',
'sei',
'sel',
'ses',
'sg',
'sga',
'sgs',
'sh',
'shi',
'shn',
'shu',
'si',
'sid',
'sk',
'sl',
'sli',
'sly',
'sm',
'sma',
'smj',
'smn',
'sms',
'sn',
'snk',
'so',
'sog',
'sq',
'sr',
'sr_ME',
'srn',
'srr',
'ss',
'ssy',
'st',
'stq',
'su',
'suk',
'sus',
'sux',
'sv',
'sw',
'sw_CD',
'swb',
'syc',
'syr',
'szl',
'ta',
'tcy',
'te',
'tem',
'teo',
'ter',
'tet',
'tg',
'th',
'ti',
'tig',
'tiv',
'tk',
'tkl',
'tkr',
'tl',
'tlh',
'tli',
'tly',
'tmh',
'tn',
'to',
'tog',
'tpi',
'tr',
'tru',
'trv',
'ts',
'tsd',
'tsi',
'tt',
'ttt',
'tum',
'tvl',
'tw',
'twq',
'ty',
'tyv',
'tzm',
'udm',
'ug',
'uga',
'uk',
'umb',
'und',
'ur',
'uz',
'vai',
've',
'vec',
'vep',
'vi',
'vls',
'vmf',
'vo',
'vot',
'vro',
'vun',
'wa',
'wae',
'wal',
'war',
'was',
'wbp',
'wo',
'wuu',
'xal',
'xh',
'xmf',
'xog',
'yao',
'yap',
'yav',
'ybb',
'yi',
'yo',
'yrl',
'yue',
'za',
'zap',
'zbl',
'zea',
'zen',
'zgh',
'zh',
'zh_Hans',
'zh_Hant',
'zu',
'zun',
'zxx',
'zza',
];
protected static $alpha2ToAlpha3 = [
'aa' => 'aar',
'ab' => 'abk',
'af' => 'afr',
'ak' => 'aka',
'am' => 'amh',
'ar' => 'ara',
'an' => 'arg',
'as' => 'asm',
'av' => 'ava',
'ae' => 'ave',
'ay' => 'aym',
'az' => 'aze',
'ba' => 'bak',
'bm' => 'bam',
'be' => 'bel',
'bn' => 'ben',
'bi' => 'bis',
'bo' => 'bod',
'bs' => 'bos',
'br' => 'bre',
'bg' => 'bul',
'ca' => 'cat',
'cs' => 'ces',
'ch' => 'cha',
'ce' => 'che',
'cu' => 'chu',
'cv' => 'chv',
'kw' => 'cor',
'co' => 'cos',
'cr' => 'cre',
'cy' => 'cym',
'da' => 'dan',
'de' => 'deu',
'dv' => 'div',
'dz' => 'dzo',
'el' => 'ell',
'en' => 'eng',
'eo' => 'epo',
'et' => 'est',
'eu' => 'eus',
'ee' => 'ewe',
'fo' => 'fao',
'fa' => 'fas',
'fj' => 'fij',
'fi' => 'fin',
'fr' => 'fra',
'fy' => 'fry',
'ff' => 'ful',
'gd' => 'gla',
'ga' => 'gle',
'gl' => 'glg',
'gv' => 'glv',
'gn' => 'grn',
'gu' => 'guj',
'ht' => 'hat',
'ha' => 'hau',
'he' => 'heb',
'hz' => 'her',
'hi' => 'hin',
'ho' => 'hmo',
'hr' => 'hrv',
'hu' => 'hun',
'hy' => 'hye',
'ig' => 'ibo',
'io' => 'ido',
'ii' => 'iii',
'iu' => 'iku',
'ie' => 'ile',
'ia' => 'ina',
'id' => 'ind',
'ik' => 'ipk',
'is' => 'isl',
'it' => 'ita',
'jv' => 'jav',
'ja' => 'jpn',
'kl' => 'kal',
'kn' => 'kan',
'ks' => 'kas',
'ka' => 'kat',
'kr' => 'kau',
'kk' => 'kaz',
'km' => 'khm',
'ki' => 'kik',
'rw' => 'kin',
'ky' => 'kir',
'kv' => 'kom',
'kg' => 'kon',
'ko' => 'kor',
'kj' => 'kua',
'ku' => 'kur',
'lo' => 'lao',
'la' => 'lat',
'lv' => 'lav',
'li' => 'lim',
'ln' => 'lin',
'lt' => 'lit',
'lb' => 'ltz',
'lu' => 'lub',
'lg' => 'lug',
'mh' => 'mah',
'ml' => 'mal',
'mr' => 'mar',
'mk' => 'mkd',
'mg' => 'mlg',
'mt' => 'mlt',
'mn' => 'mon',
'mi' => 'mri',
'ms' => 'msa',
'my' => 'mya',
'na' => 'nau',
'nv' => 'nav',
'nr' => 'nbl',
'nd' => 'nde',
'ng' => 'ndo',
'ne' => 'nep',
'nl' => 'nld',
'nn' => 'nno',
'nb' => 'nob',
'ny' => 'nya',
'oc' => 'oci',
'oj' => 'oji',
'or' => 'ori',
'om' => 'orm',
'os' => 'oss',
'pa' => 'pan',
'pi' => 'pli',
'pl' => 'pol',
'pt' => 'por',
'ps' => 'pus',
'qu' => 'que',
'rm' => 'roh',
'ro' => 'ron',
'rn' => 'run',
'ru' => 'rus',
'sg' => 'sag',
'sa' => 'san',
'si' => 'sin',
'sk' => 'slk',
'sl' => 'slv',
'se' => 'sme',
'sm' => 'smo',
'sn' => 'sna',
'sd' => 'snd',
'so' => 'som',
'st' => 'sot',
'es' => 'spa',
'sq' => 'sqi',
'sc' => 'srd',
'sr' => 'srp',
'ss' => 'ssw',
'su' => 'sun',
'sw' => 'swa',
'sv' => 'swe',
'ty' => 'tah',
'ta' => 'tam',
'tt' => 'tat',
'te' => 'tel',
'tg' => 'tgk',
'th' => 'tha',
'ti' => 'tir',
'to' => 'ton',
'tn' => 'tsn',
'ts' => 'tso',
'tk' => 'tuk',
'tr' => 'tur',
'ug' => 'uig',
'uk' => 'ukr',
'ur' => 'urd',
'uz' => 'uzb',
've' => 'ven',
'vi' => 'vie',
'vo' => 'vol',
'wa' => 'wln',
'wo' => 'wol',
'xh' => 'xho',
'yi' => 'yid',
'yo' => 'yor',
'za' => 'zha',
'zh' => 'zho',
'zu' => 'zul',
];
/**
* @var LanguageDataProvider
*/
protected $dataProvider;
private $defaultLocale;
protected function setUp()
{
parent::setUp();
$this->dataProvider = new LanguageDataProvider(
$this->getDataDirectory().'/'.Intl::LANGUAGE_DIR,
$this->createEntryReader()
);
$this->defaultLocale = \Locale::getDefault();
}
protected function tearDown()
{
parent::tearDown();
\Locale::setDefault($this->defaultLocale);
}
abstract protected function getDataDirectory();
public function testGetLanguages()
{
$this->assertEquals(static::$languages, $this->dataProvider->getLanguages());
}
/**
* @dataProvider provideLocales
*/
public function testGetNames($displayLocale)
{
$languages = array_keys($this->dataProvider->getNames($displayLocale));
sort($languages);
$this->assertNotEmpty($languages);
$this->assertEmpty(array_diff($languages, static::$languages));
}
public function testGetNamesDefaultLocale()
{
\Locale::setDefault('de_AT');
$this->assertSame(
$this->dataProvider->getNames('de_AT'),
$this->dataProvider->getNames()
);
}
/**
* @dataProvider provideLocaleAliases
*/
public function testGetNamesSupportsAliases($alias, $ofLocale)
{
// Can't use assertSame(), because some aliases contain scripts with
// different collation (=order of output) than their aliased locale
// e.g. sr_Latn_ME => sr_ME
$this->assertEquals(
$this->dataProvider->getNames($ofLocale),
$this->dataProvider->getNames($alias)
);
}
/**
* @dataProvider provideLocales
*/
public function testGetName($displayLocale)
{
$names = $this->dataProvider->getNames($displayLocale);
foreach ($names as $language => $name) {
$this->assertSame($name, $this->dataProvider->getName($language, $displayLocale));
}
}
public function testGetNameDefaultLocale()
{
\Locale::setDefault('de_AT');
$names = $this->dataProvider->getNames('de_AT');
foreach ($names as $language => $name) {
$this->assertSame($name, $this->dataProvider->getName($language));
}
}
public function provideLanguagesWithAlpha3Equivalent()
{
return array_map(
function ($value) { return [$value]; },
array_keys(static::$alpha2ToAlpha3)
);
}
/**
* @dataProvider provideLanguagesWithAlpha3Equivalent
*/
public function testGetAlpha3Code($language)
{
$this->assertSame(static::$alpha2ToAlpha3[$language], $this->dataProvider->getAlpha3Code($language));
}
public function provideLanguagesWithoutAlpha3Equivalent()
{
return array_map(
function ($value) { return [$value]; },
array_diff(static::$languages, array_keys(static::$alpha2ToAlpha3))
);
}
/**
* @dataProvider provideLanguagesWithoutAlpha3Equivalent
*/
public function testGetAlpha3CodeFailsIfNoAlpha3Equivalent($currency)
{
$this->expectException('Symfony\Component\Intl\Exception\MissingResourceException');
$this->dataProvider->getAlpha3Code($currency);
}
}

View File

@@ -0,0 +1,118 @@
<?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\Data\Provider;
use Symfony\Component\Intl\Data\Provider\LocaleDataProvider;
use Symfony\Component\Intl\Intl;
/**
* @author Bernhard Schussek <bschussek@gmail.com>
*/
abstract class AbstractLocaleDataProviderTest extends AbstractDataProviderTest
{
/**
* @var LocaleDataProvider
*/
protected $dataProvider;
private $defaultLocale;
protected function setUp()
{
parent::setUp();
$this->dataProvider = new LocaleDataProvider(
$this->getDataDirectory().'/'.Intl::LOCALE_DIR,
$this->createEntryReader()
);
$this->defaultLocale = \Locale::getDefault();
}
protected function tearDown()
{
\Locale::setDefault($this->defaultLocale);
}
abstract protected function getDataDirectory();
public function testGetLocales()
{
$this->assertSame($this->getLocales(), $this->dataProvider->getLocales());
}
public function testGetLocaleAliases()
{
$this->assertSame($this->getLocaleAliases(), $this->dataProvider->getAliases());
}
/**
* @dataProvider provideLocales
*/
public function testGetNames($displayLocale)
{
$locales = array_keys($this->dataProvider->getNames($displayLocale));
sort($locales);
// We can't assert on exact list of locale, as there's too many variations.
// The best we can do is to make sure getNames() returns a subset of what getLocales() returns.
$this->assertNotEmpty($locales);
$this->assertEmpty(array_diff($locales, $this->getLocales()));
}
public function testGetNamesDefaultLocale()
{
\Locale::setDefault('de_AT');
$this->assertSame(
$this->dataProvider->getNames('de_AT'),
$this->dataProvider->getNames()
);
}
/**
* @dataProvider provideLocaleAliases
*/
public function testGetNamesSupportsAliases($alias, $ofLocale)
{
// Can't use assertSame(), because some aliases contain scripts with
// different collation (=order of output) than their aliased locale
// e.g. sr_Latn_ME => sr_ME
$this->assertEquals(
$this->dataProvider->getNames($ofLocale),
$this->dataProvider->getNames($alias)
);
}
/**
* @dataProvider provideLocales
*/
public function testGetName($displayLocale)
{
$names = $this->dataProvider->getNames($displayLocale);
foreach ($names as $locale => $name) {
$this->assertSame($name, $this->dataProvider->getName($locale, $displayLocale));
}
}
public function testGetNameDefaultLocale()
{
\Locale::setDefault('de_AT');
$names = $this->dataProvider->getNames('de_AT');
foreach ($names as $locale => $name) {
$this->assertSame($name, $this->dataProvider->getName($locale));
}
}
}

View File

@@ -0,0 +1,361 @@
<?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\Data\Provider;
use Symfony\Component\Intl\Data\Provider\RegionDataProvider;
use Symfony\Component\Intl\Intl;
/**
* @author Bernhard Schussek <bschussek@gmail.com>
*/
abstract class AbstractRegionDataProviderTest extends AbstractDataProviderTest
{
// The below arrays document the state of the ICU data bundled with this package.
protected static $territories = [
'AC',
'AD',
'AE',
'AF',
'AG',
'AI',
'AL',
'AM',
'AO',
'AQ',
'AR',
'AS',
'AT',
'AU',
'AW',
'AX',
'AZ',
'BA',
'BB',
'BD',
'BE',
'BF',
'BG',
'BH',
'BI',
'BJ',
'BL',
'BM',
'BN',
'BO',
'BQ',
'BR',
'BS',
'BT',
'BW',
'BY',
'BZ',
'CA',
'CC',
'CD',
'CF',
'CG',
'CH',
'CI',
'CK',
'CL',
'CM',
'CN',
'CO',
'CR',
'CU',
'CV',
'CW',
'CX',
'CY',
'CZ',
'DE',
'DG',
'DJ',
'DK',
'DM',
'DO',
'DZ',
'EA',
'EC',
'EE',
'EG',
'EH',
'ER',
'ES',
'ET',
'FI',
'FJ',
'FK',
'FM',
'FO',
'FR',
'GA',
'GB',
'GD',
'GE',
'GF',
'GG',
'GH',
'GI',
'GL',
'GM',
'GN',
'GP',
'GQ',
'GR',
'GS',
'GT',
'GU',
'GW',
'GY',
'HK',
'HN',
'HR',
'HT',
'HU',
'IC',
'ID',
'IE',
'IL',
'IM',
'IN',
'IO',
'IQ',
'IR',
'IS',
'IT',
'JE',
'JM',
'JO',
'JP',
'KE',
'KG',
'KH',
'KI',
'KM',
'KN',
'KP',
'KR',
'KW',
'KY',
'KZ',
'LA',
'LB',
'LC',
'LI',
'LK',
'LR',
'LS',
'LT',
'LU',
'LV',
'LY',
'MA',
'MC',
'MD',
'ME',
'MF',
'MG',
'MH',
'MK',
'ML',
'MM',
'MN',
'MO',
'MP',
'MQ',
'MR',
'MS',
'MT',
'MU',
'MV',
'MW',
'MX',
'MY',
'MZ',
'NA',
'NC',
'NE',
'NF',
'NG',
'NI',
'NL',
'NO',
'NP',
'NR',
'NU',
'NZ',
'OM',
'PA',
'PE',
'PF',
'PG',
'PH',
'PK',
'PL',
'PM',
'PN',
'PR',
'PS',
'PT',
'PW',
'PY',
'QA',
'RE',
'RO',
'RS',
'RU',
'RW',
'SA',
'SB',
'SC',
'SD',
'SE',
'SG',
'SH',
'SI',
'SJ',
'SK',
'SL',
'SM',
'SN',
'SO',
'SR',
'SS',
'ST',
'SV',
'SX',
'SY',
'SZ',
'TA',
'TC',
'TD',
'TF',
'TG',
'TH',
'TJ',
'TK',
'TL',
'TM',
'TN',
'TO',
'TR',
'TT',
'TV',
'TW',
'TZ',
'UA',
'UG',
'UM',
'US',
'UY',
'UZ',
'VA',
'VC',
'VE',
'VG',
'VI',
'VN',
'VU',
'WF',
'WS',
'XA',
'XB',
'XK',
'YE',
'YT',
'ZA',
'ZM',
'ZW',
];
/**
* @var RegionDataProvider
*/
protected $dataProvider;
private $defaultLocale;
protected function setUp()
{
parent::setUp();
$this->dataProvider = new RegionDataProvider(
$this->getDataDirectory().'/'.Intl::REGION_DIR,
$this->createEntryReader()
);
$this->defaultLocale = \Locale::getDefault();
}
protected function tearDown()
{
parent::tearDown();
\Locale::setDefault($this->defaultLocale);
}
abstract protected function getDataDirectory();
public function testGetRegions()
{
$this->assertSame(static::$territories, $this->dataProvider->getRegions());
}
/**
* @dataProvider provideLocales
*/
public function testGetNames($displayLocale)
{
$countries = array_keys($this->dataProvider->getNames($displayLocale));
sort($countries);
$this->assertSame(static::$territories, $countries);
}
public function testGetNamesDefaultLocale()
{
\Locale::setDefault('de_AT');
$this->assertSame(
$this->dataProvider->getNames('de_AT'),
$this->dataProvider->getNames()
);
}
/**
* @dataProvider provideLocaleAliases
*/
public function testGetNamesSupportsAliases($alias, $ofLocale)
{
// Can't use assertSame(), because some aliases contain scripts with
// different collation (=order of output) than their aliased locale
// e.g. sr_Latn_ME => sr_ME
$this->assertEquals(
$this->dataProvider->getNames($ofLocale),
$this->dataProvider->getNames($alias)
);
}
/**
* @dataProvider provideLocales
*/
public function testGetName($displayLocale)
{
$names = $this->dataProvider->getNames($displayLocale);
foreach ($names as $country => $name) {
$this->assertSame($name, $this->dataProvider->getName($country, $displayLocale));
}
}
}

View File

@@ -0,0 +1,316 @@
<?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\Data\Provider;
use Symfony\Component\Intl\Data\Provider\ScriptDataProvider;
use Symfony\Component\Intl\Intl;
/**
* @author Bernhard Schussek <bschussek@gmail.com>
* @group intl-data
*/
abstract class AbstractScriptDataProviderTest extends AbstractDataProviderTest
{
// The below arrays document the state of the ICU data bundled with this package.
protected static $scripts = [
'Adlm',
'Afak',
'Aghb',
'Ahom',
'Arab',
'Aran',
'Armi',
'Armn',
'Avst',
'Bali',
'Bamu',
'Bass',
'Batk',
'Beng',
'Bhks',
'Blis',
'Bopo',
'Brah',
'Brai',
'Bugi',
'Buhd',
'Cakm',
'Cans',
'Cari',
'Cham',
'Cher',
'Chrs',
'Cirt',
'Copt',
'Cprt',
'Cyrl',
'Cyrs',
'Deva',
'Diak',
'Dogr',
'Dsrt',
'Dupl',
'Egyd',
'Egyh',
'Egyp',
'Elba',
'Elym',
'Ethi',
'Geok',
'Geor',
'Glag',
'Gong',
'Gonm',
'Goth',
'Gran',
'Grek',
'Gujr',
'Guru',
'Hanb',
'Hang',
'Hani',
'Hano',
'Hans',
'Hant',
'Hatr',
'Hebr',
'Hira',
'Hluw',
'Hmng',
'Hmnp',
'Hrkt',
'Hung',
'Inds',
'Ital',
'Jamo',
'Java',
'Jpan',
'Jurc',
'Kali',
'Kana',
'Khar',
'Khmr',
'Khoj',
'Kits',
'Knda',
'Kore',
'Kpel',
'Kthi',
'Lana',
'Laoo',
'Latf',
'Latg',
'Latn',
'Lepc',
'Limb',
'Lina',
'Linb',
'Lisu',
'Loma',
'Lyci',
'Lydi',
'Mahj',
'Maka',
'Mand',
'Mani',
'Marc',
'Maya',
'Medf',
'Mend',
'Merc',
'Mero',
'Mlym',
'Modi',
'Mong',
'Moon',
'Mroo',
'Mtei',
'Mult',
'Mymr',
'Nand',
'Narb',
'Nbat',
'Newa',
'Nkgb',
'Nkoo',
'Nshu',
'Ogam',
'Olck',
'Orkh',
'Orya',
'Osge',
'Osma',
'Palm',
'Pauc',
'Perm',
'Phag',
'Phli',
'Phlp',
'Phlv',
'Phnx',
'Plrd',
'Prti',
'Qaag',
'Rjng',
'Rohg',
'Roro',
'Runr',
'Samr',
'Sara',
'Sarb',
'Saur',
'Sgnw',
'Shaw',
'Shrd',
'Sidd',
'Sind',
'Sinh',
'Sogd',
'Sogo',
'Sora',
'Soyo',
'Sund',
'Sylo',
'Syrc',
'Syre',
'Syrj',
'Syrn',
'Tagb',
'Takr',
'Tale',
'Talu',
'Taml',
'Tang',
'Tavt',
'Telu',
'Teng',
'Tfng',
'Tglg',
'Thaa',
'Thai',
'Tibt',
'Tirh',
'Ugar',
'Vaii',
'Visp',
'Wara',
'Wcho',
'Wole',
'Xpeo',
'Xsux',
'Yezi',
'Yiii',
'Zanb',
'Zinh',
'Zmth',
'Zsye',
'Zsym',
'Zxxx',
'Zyyy',
'Zzzz',
];
/**
* @var ScriptDataProvider
*/
protected $dataProvider;
private $defaultLocale;
protected function setUp()
{
parent::setUp();
$this->dataProvider = new ScriptDataProvider(
$this->getDataDirectory().'/'.Intl::SCRIPT_DIR,
$this->createEntryReader()
);
$this->defaultLocale = \Locale::getDefault();
}
protected function tearDown()
{
parent::tearDown();
\Locale::setDefault($this->defaultLocale);
}
abstract protected function getDataDirectory();
public function testGetScripts()
{
$this->assertSame(static::$scripts, $this->dataProvider->getScripts());
}
/**
* @dataProvider provideLocales
*/
public function testGetNames($displayLocale)
{
$scripts = array_keys($this->dataProvider->getNames($displayLocale));
sort($scripts);
// We can't assert on exact list of scripts, as there's too many variations between locales.
// The best we can do is to make sure getNames() returns a subset of what getScripts() returns.
$this->assertNotEmpty($scripts);
$this->assertEmpty(array_diff($scripts, self::$scripts));
}
public function testGetNamesDefaultLocale()
{
\Locale::setDefault('de_AT');
$this->assertSame(
$this->dataProvider->getNames('de_AT'),
$this->dataProvider->getNames()
);
}
/**
* @dataProvider provideLocaleAliases
*/
public function testGetNamesSupportsAliases($alias, $ofLocale)
{
// Can't use assertSame(), because some aliases contain scripts with
// different collation (=order of output) than their aliased locale
// e.g. sr_Latn_ME => sr_ME
$this->assertEquals(
$this->dataProvider->getNames($ofLocale),
$this->dataProvider->getNames($alias)
);
}
/**
* @dataProvider provideLocales
*/
public function testGetName($displayLocale)
{
$names = $this->dataProvider->getNames($displayLocale);
foreach ($names as $script => $name) {
$this->assertSame($name, $this->dataProvider->getName($script, $displayLocale));
}
}
public function testGetNameDefaultLocale()
{
\Locale::setDefault('de_AT');
$names = $this->dataProvider->getNames('de_AT');
foreach ($names as $script => $name) {
$this->assertSame($name, $this->dataProvider->getName($script));
}
}
}

View File

@@ -0,0 +1,37 @@
<?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\Data\Provider\Json;
use Symfony\Component\Intl\Data\Bundle\Reader\BundleReaderInterface;
use Symfony\Component\Intl\Data\Bundle\Reader\JsonBundleReader;
use Symfony\Component\Intl\Intl;
use Symfony\Component\Intl\Tests\Data\Provider\AbstractCurrencyDataProviderTest;
/**
* @author Bernhard Schussek <bschussek@gmail.com>
* @group intl-data
*/
class JsonCurrencyDataProviderTest extends AbstractCurrencyDataProviderTest
{
protected function getDataDirectory()
{
return Intl::getDataDirectory();
}
/**
* @return BundleReaderInterface
*/
protected function createBundleReader()
{
return new JsonBundleReader();
}
}

View File

@@ -0,0 +1,37 @@
<?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\Data\Provider\Json;
use Symfony\Component\Intl\Data\Bundle\Reader\BundleReaderInterface;
use Symfony\Component\Intl\Data\Bundle\Reader\JsonBundleReader;
use Symfony\Component\Intl\Intl;
use Symfony\Component\Intl\Tests\Data\Provider\AbstractLanguageDataProviderTest;
/**
* @author Bernhard Schussek <bschussek@gmail.com>
* @group intl-data
*/
class JsonLanguageDataProviderTest extends AbstractLanguageDataProviderTest
{
protected function getDataDirectory()
{
return Intl::getDataDirectory();
}
/**
* @return BundleReaderInterface
*/
protected function createBundleReader()
{
return new JsonBundleReader();
}
}

View File

@@ -0,0 +1,37 @@
<?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\Data\Provider\Json;
use Symfony\Component\Intl\Data\Bundle\Reader\BundleReaderInterface;
use Symfony\Component\Intl\Data\Bundle\Reader\JsonBundleReader;
use Symfony\Component\Intl\Intl;
use Symfony\Component\Intl\Tests\Data\Provider\AbstractLocaleDataProviderTest;
/**
* @author Bernhard Schussek <bschussek@gmail.com>
* @group intl-data
*/
class JsonLocaleDataProviderTest extends AbstractLocaleDataProviderTest
{
protected function getDataDirectory()
{
return Intl::getDataDirectory();
}
/**
* @return BundleReaderInterface
*/
protected function createBundleReader()
{
return new JsonBundleReader();
}
}

View File

@@ -0,0 +1,37 @@
<?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\Data\Provider\Json;
use Symfony\Component\Intl\Data\Bundle\Reader\BundleReaderInterface;
use Symfony\Component\Intl\Data\Bundle\Reader\JsonBundleReader;
use Symfony\Component\Intl\Intl;
use Symfony\Component\Intl\Tests\Data\Provider\AbstractRegionDataProviderTest;
/**
* @author Bernhard Schussek <bschussek@gmail.com>
* @group intl-data
*/
class JsonRegionDataProviderTest extends AbstractRegionDataProviderTest
{
protected function getDataDirectory()
{
return Intl::getDataDirectory();
}
/**
* @return BundleReaderInterface
*/
protected function createBundleReader()
{
return new JsonBundleReader();
}
}

View File

@@ -0,0 +1,37 @@
<?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\Data\Provider\Json;
use Symfony\Component\Intl\Data\Bundle\Reader\BundleReaderInterface;
use Symfony\Component\Intl\Data\Bundle\Reader\JsonBundleReader;
use Symfony\Component\Intl\Intl;
use Symfony\Component\Intl\Tests\Data\Provider\AbstractScriptDataProviderTest;
/**
* @author Bernhard Schussek <bschussek@gmail.com>
* @group intl-data
*/
class JsonScriptDataProviderTest extends AbstractScriptDataProviderTest
{
protected function getDataDirectory()
{
return Intl::getDataDirectory();
}
/**
* @return BundleReaderInterface
*/
protected function createBundleReader()
{
return new JsonBundleReader();
}
}

View File

@@ -0,0 +1,77 @@
<?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\Data\Util;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Intl\Data\Util\LocaleScanner;
/**
* @author Bernhard Schussek <bschussek@gmail.com>
*/
class LocaleScannerTest extends TestCase
{
private $directory;
/**
* @var Filesystem
*/
private $filesystem;
/**
* @var LocaleScanner
*/
private $scanner;
protected function setUp()
{
$this->directory = sys_get_temp_dir().'/LocaleScannerTest/'.mt_rand(1000, 9999);
$this->filesystem = new Filesystem();
$this->scanner = new LocaleScanner();
$this->filesystem->mkdir($this->directory);
$this->filesystem->touch($this->directory.'/en.txt');
$this->filesystem->touch($this->directory.'/en_alias.txt');
$this->filesystem->touch($this->directory.'/de.txt');
$this->filesystem->touch($this->directory.'/de_alias.txt');
$this->filesystem->touch($this->directory.'/fr.txt');
$this->filesystem->touch($this->directory.'/fr_alias.txt');
$this->filesystem->touch($this->directory.'/root.txt');
$this->filesystem->touch($this->directory.'/supplementalData.txt');
$this->filesystem->touch($this->directory.'/supplementaldata.txt');
$this->filesystem->touch($this->directory.'/meta.txt');
file_put_contents($this->directory.'/en_alias.txt', 'en_alias{"%%ALIAS"{"en"}}');
file_put_contents($this->directory.'/de_alias.txt', 'de_alias{"%%ALIAS"{"de"}}');
file_put_contents($this->directory.'/fr_alias.txt', 'fr_alias{"%%ALIAS"{"fr"}}');
}
protected function tearDown()
{
$this->filesystem->remove($this->directory);
}
public function testScanLocales()
{
$sortedLocales = ['de', 'de_alias', 'en', 'en_alias', 'fr', 'fr_alias'];
$this->assertSame($sortedLocales, $this->scanner->scanLocales($this->directory));
}
public function testScanAliases()
{
$sortedAliases = ['de_alias' => 'de', 'en_alias' => 'en', 'fr_alias' => 'fr'];
$this->assertSame($sortedAliases, $this->scanner->scanAliases($this->directory));
}
}

View File

@@ -0,0 +1,98 @@
<?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\Data\Util;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Intl\Data\Util\RingBuffer;
/**
* @author Bernhard Schussek <bschussek@gmail.com>
*/
class RingBufferTest extends TestCase
{
/**
* @var RingBuffer
*/
private $buffer;
protected function setUp()
{
$this->buffer = new RingBuffer(2);
}
public function testWriteWithinBuffer()
{
$this->buffer[0] = 'foo';
$this->buffer['bar'] = 'baz';
$this->assertArrayHasKey(0, $this->buffer);
$this->assertArrayHasKey('bar', $this->buffer);
$this->assertSame('foo', $this->buffer[0]);
$this->assertSame('baz', $this->buffer['bar']);
}
public function testWritePastBuffer()
{
$this->buffer[0] = 'foo';
$this->buffer['bar'] = 'baz';
$this->buffer[2] = 'bam';
$this->assertArrayHasKey('bar', $this->buffer);
$this->assertArrayHasKey(2, $this->buffer);
$this->assertSame('baz', $this->buffer['bar']);
$this->assertSame('bam', $this->buffer[2]);
}
public function testReadNonExistingFails()
{
$this->expectException('Symfony\Component\Intl\Exception\OutOfBoundsException');
$this->buffer['foo'];
}
public function testQueryNonExisting()
{
$this->assertArrayNotHasKey('foo', $this->buffer);
}
public function testUnsetNonExistingSucceeds()
{
unset($this->buffer['foo']);
$this->assertArrayNotHasKey('foo', $this->buffer);
}
public function testReadOverwrittenFails()
{
$this->expectException('Symfony\Component\Intl\Exception\OutOfBoundsException');
$this->buffer[0] = 'foo';
$this->buffer['bar'] = 'baz';
$this->buffer[2] = 'bam';
$this->buffer[0];
}
public function testQueryOverwritten()
{
$this->assertArrayNotHasKey(0, $this->buffer);
}
public function testUnsetOverwrittenSucceeds()
{
$this->buffer[0] = 'foo';
$this->buffer['bar'] = 'baz';
$this->buffer[2] = 'bam';
unset($this->buffer[0]);
$this->assertArrayNotHasKey(0, $this->buffer);
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,219 @@
<?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\DateFormatter;
use Symfony\Component\Intl\DateFormatter\IntlDateFormatter;
use Symfony\Component\Intl\Globals\IntlGlobals;
class IntlDateFormatterTest extends AbstractIntlDateFormatterTest
{
public function testConstructor()
{
$formatter = new IntlDateFormatter('en', IntlDateFormatter::MEDIUM, IntlDateFormatter::SHORT, 'UTC', IntlDateFormatter::GREGORIAN, 'y-M-d');
$this->assertEquals('y-M-d', $formatter->getPattern());
}
public function testConstructorWithoutLocale()
{
$formatter = new IntlDateFormatter(null, IntlDateFormatter::MEDIUM, IntlDateFormatter::SHORT, 'UTC', IntlDateFormatter::GREGORIAN, 'y-M-d');
$this->assertEquals('y-M-d', $formatter->getPattern());
}
public function testConstructorWithoutCalendar()
{
$formatter = new IntlDateFormatter('en', IntlDateFormatter::MEDIUM, IntlDateFormatter::SHORT, 'UTC', null, 'y-M-d');
$this->assertEquals('y-M-d', $formatter->getPattern());
}
public function testConstructorWithUnsupportedLocale()
{
$this->expectException('Symfony\Component\Intl\Exception\MethodArgumentValueNotImplementedException');
new IntlDateFormatter('pt_BR', IntlDateFormatter::MEDIUM, IntlDateFormatter::SHORT);
}
public function testStaticCreate()
{
$formatter = IntlDateFormatter::create('en', IntlDateFormatter::MEDIUM, IntlDateFormatter::SHORT);
$this->assertInstanceOf('\Symfony\Component\Intl\DateFormatter\IntlDateFormatter', $formatter);
}
public function testFormatWithUnsupportedTimestampArgument()
{
$formatter = $this->getDefaultDateFormatter();
$localtime = [
'tm_sec' => 59,
'tm_min' => 3,
'tm_hour' => 15,
'tm_mday' => 15,
'tm_mon' => 3,
'tm_year' => 112,
'tm_wday' => 0,
'tm_yday' => 105,
'tm_isdst' => 0,
];
try {
$formatter->format($localtime);
} catch (\Exception $e) {
$this->assertInstanceOf('Symfony\Component\Intl\Exception\MethodArgumentValueNotImplementedException', $e);
$this->assertStringEndsWith('Only integer Unix timestamps and DateTime objects are supported. Please install the "intl" extension for full localization capabilities.', $e->getMessage());
}
}
public function testFormatWithUnimplementedChars()
{
$this->expectException('Symfony\Component\Intl\Exception\NotImplementedException');
$pattern = 'Y';
$formatter = new IntlDateFormatter('en', IntlDateFormatter::MEDIUM, IntlDateFormatter::SHORT, 'UTC', IntlDateFormatter::GREGORIAN, $pattern);
$formatter->format(0);
}
public function testFormatWithNonIntegerTimestamp()
{
$this->expectException('Symfony\Component\Intl\Exception\NotImplementedException');
$formatter = $this->getDefaultDateFormatter();
$formatter->format([]);
}
public function testGetErrorCode()
{
$formatter = $this->getDefaultDateFormatter();
$this->assertEquals(IntlGlobals::getErrorCode(), $formatter->getErrorCode());
}
public function testGetErrorMessage()
{
$formatter = $this->getDefaultDateFormatter();
$this->assertEquals(IntlGlobals::getErrorMessage(), $formatter->getErrorMessage());
}
public function testIsLenient()
{
$formatter = $this->getDefaultDateFormatter();
$this->assertFalse($formatter->isLenient());
}
public function testLocaltime()
{
$this->expectException('Symfony\Component\Intl\Exception\MethodNotImplementedException');
$formatter = $this->getDefaultDateFormatter();
$formatter->localtime('Wednesday, December 31, 1969 4:00:00 PM PT');
}
public function testParseWithNotNullPositionValue()
{
$this->expectException('Symfony\Component\Intl\Exception\MethodArgumentNotImplementedException');
$position = 0;
$formatter = $this->getDefaultDateFormatter('y');
$this->assertSame(0, $formatter->parse('1970', $position));
}
public function testSetCalendar()
{
$this->expectException('Symfony\Component\Intl\Exception\MethodNotImplementedException');
$formatter = $this->getDefaultDateFormatter();
$formatter->setCalendar(IntlDateFormatter::GREGORIAN);
}
public function testSetLenient()
{
$this->expectException('Symfony\Component\Intl\Exception\MethodArgumentValueNotImplementedException');
$formatter = $this->getDefaultDateFormatter();
$formatter->setLenient(true);
}
public function testFormatWithGmtTimeZoneAndMinutesOffset()
{
$this->expectException('Symfony\Component\Intl\Exception\NotImplementedException');
parent::testFormatWithGmtTimeZoneAndMinutesOffset();
}
public function testFormatWithNonStandardTimezone()
{
$this->expectException('Symfony\Component\Intl\Exception\NotImplementedException');
parent::testFormatWithNonStandardTimezone();
}
public function parseStandaloneAmPmProvider()
{
return $this->notImplemented(parent::parseStandaloneAmPmProvider());
}
public function parseDayOfWeekProvider()
{
return $this->notImplemented(parent::parseDayOfWeekProvider());
}
public function parseDayOfYearProvider()
{
return $this->notImplemented(parent::parseDayOfYearProvider());
}
public function parseQuarterProvider()
{
return $this->notImplemented(parent::parseQuarterProvider());
}
public function testParseThreeDigitsYears()
{
if (\PHP_INT_SIZE < 8) {
$this->markTestSkipped('Parsing three digits years requires a 64bit PHP.');
}
$formatter = $this->getDefaultDateFormatter('yyyy-M-d');
$this->assertSame(-32157648000, $formatter->parse('950-12-19'));
$this->assertIsIntlSuccess($formatter, 'U_ZERO_ERROR', IntlGlobals::U_ZERO_ERROR);
}
protected function getDateFormatter($locale, $datetype, $timetype, $timezone = null, $calendar = IntlDateFormatter::GREGORIAN, $pattern = null)
{
return new IntlDateFormatter($locale, $datetype, $timetype, $timezone, $calendar, $pattern);
}
protected function getIntlErrorMessage()
{
return IntlGlobals::getErrorMessage();
}
protected function getIntlErrorCode()
{
return IntlGlobals::getErrorCode();
}
protected function isIntlFailure($errorCode)
{
return IntlGlobals::isFailure($errorCode);
}
/**
* Just to document the differences between the stub and the intl
* implementations. The intl can parse any of the tested formats alone. The
* stub does not implement them as it would be needed to add more
* abstraction, passing more context to the transformers objects. Any of the
* formats are ignored alone or with date/time data (years, months, days,
* hours, minutes and seconds).
*
* Also in intl, format like 'ss E' for '10 2' (2nd day of year
* + 10 seconds) are added, then we have 86,400 seconds (24h * 60min * 60s)
* + 10 seconds
*
* @return array
*/
private function notImplemented(array $dataSets)
{
return array_map(function ($row) {
return [$row[0], $row[1], 0];
}, $dataSets);
}
}

View File

@@ -0,0 +1,85 @@
<?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\DateFormatter\Verification;
use Symfony\Component\Intl\DateFormatter\IntlDateFormatter;
use Symfony\Component\Intl\Tests\DateFormatter\AbstractIntlDateFormatterTest;
use Symfony\Component\Intl\Util\IntlTestHelper;
/**
* Verifies that {@link AbstractIntlDateFormatterTest} matches the behavior of
* the {@link \IntlDateFormatter} class in a specific version of ICU.
*
* @author Bernhard Schussek <bschussek@gmail.com>
*/
class IntlDateFormatterTest extends AbstractIntlDateFormatterTest
{
protected function setUp()
{
IntlTestHelper::requireFullIntl($this, false);
parent::setUp();
}
/**
* @dataProvider formatTimezoneProvider
*/
public function testFormatTimezone($pattern, $timezone, $expected)
{
IntlTestHelper::requireFullIntl($this, '59.1');
parent::testFormatTimezone($pattern, $timezone, $expected);
}
public function testFormatUtcAndGmtAreSplit()
{
IntlTestHelper::requireFullIntl($this, '59.1');
parent::testFormatUtcAndGmtAreSplit();
}
/**
* @dataProvider dateAndTimeTypeProvider
*/
public function testDateAndTimeType($timestamp, $datetype, $timetype, $expected)
{
IntlTestHelper::requireFullIntl($this, '59.1');
parent::testDateAndTimeType($timestamp, $datetype, $timetype, $expected);
}
protected function getDateFormatter($locale, $datetype, $timetype, $timezone = null, $calendar = IntlDateFormatter::GREGORIAN, $pattern = null)
{
IntlTestHelper::requireFullIntl($this, '55.1');
if (!$formatter = new \IntlDateFormatter($locale, $datetype, $timetype, $timezone, $calendar, $pattern)) {
throw new \InvalidArgumentException(intl_get_error_message());
}
return $formatter;
}
protected function getIntlErrorMessage()
{
return intl_get_error_message();
}
protected function getIntlErrorCode()
{
return intl_get_error_code();
}
protected function isIntlFailure($errorCode)
{
return intl_is_failure($errorCode);
}
}

View File

@@ -0,0 +1,43 @@
<?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\Globals;
use PHPUnit\Framework\TestCase;
/**
* Test case for intl function implementations.
*
* @author Bernhard Schussek <bschussek@gmail.com>
*/
abstract class AbstractIntlGlobalsTest extends TestCase
{
public function errorNameProvider()
{
return [
[-129, '[BOGUS UErrorCode]'],
[0, 'U_ZERO_ERROR'],
[1, 'U_ILLEGAL_ARGUMENT_ERROR'],
[9, 'U_PARSE_ERROR'],
[129, '[BOGUS UErrorCode]'],
];
}
/**
* @dataProvider errorNameProvider
*/
public function testGetErrorName($errorCode, $errorName)
{
$this->assertSame($errorName, $this->getIntlErrorName($errorCode));
}
abstract protected function getIntlErrorName($errorCode);
}

View File

@@ -0,0 +1,22 @@
<?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\Globals;
use Symfony\Component\Intl\Globals\IntlGlobals;
class IntlGlobalsTest extends AbstractIntlGlobalsTest
{
protected function getIntlErrorName($errorCode)
{
return IntlGlobals::getErrorName($errorCode);
}
}

View File

@@ -0,0 +1,36 @@
<?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\Globals\Verification;
use Symfony\Component\Intl\Tests\Globals\AbstractIntlGlobalsTest;
use Symfony\Component\Intl\Util\IntlTestHelper;
/**
* Verifies that {@link AbstractIntlGlobalsTest} matches the behavior of the
* intl functions with a specific version of ICU.
*
* @author Bernhard Schussek <bschussek@gmail.com>
*/
class IntlGlobalsTest extends AbstractIntlGlobalsTest
{
protected function setUp()
{
IntlTestHelper::requireFullIntl($this, false);
parent::setUp();
}
protected function getIntlErrorName($errorCode)
{
return intl_error_name($errorCode);
}
}

100
vendor/symfony/intl/Tests/IntlTest.php vendored Normal file
View File

@@ -0,0 +1,100 @@
<?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 PHPUnit\Framework\TestCase;
use Symfony\Component\Intl\Intl;
class IntlTest extends TestCase
{
private $defaultLocale;
protected function setUp()
{
parent::setUp();
$this->defaultLocale = \Locale::getDefault();
}
protected function tearDown()
{
parent::tearDown();
\Locale::setDefault($this->defaultLocale);
}
/**
* @requires extension intl
*/
public function testIsExtensionLoadedChecksIfIntlExtensionIsLoaded()
{
$this->assertTrue(Intl::isExtensionLoaded());
}
public function testGetCurrencyBundleCreatesTheCurrencyBundle()
{
$this->assertInstanceOf('Symfony\Component\Intl\ResourceBundle\CurrencyBundleInterface', Intl::getCurrencyBundle());
}
public function testGetLanguageBundleCreatesTheLanguageBundle()
{
$this->assertInstanceOf('Symfony\Component\Intl\ResourceBundle\LanguageBundleInterface', Intl::getLanguageBundle());
}
public function testGetLocaleBundleCreatesTheLocaleBundle()
{
$this->assertInstanceOf('Symfony\Component\Intl\ResourceBundle\LocaleBundleInterface', Intl::getLocaleBundle());
}
public function testGetRegionBundleCreatesTheRegionBundle()
{
$this->assertInstanceOf('Symfony\Component\Intl\ResourceBundle\RegionBundleInterface', Intl::getRegionBundle());
}
public function testGetIcuVersionReadsTheVersionOfInstalledIcuLibrary()
{
$this->assertStringMatchesFormat('%d.%d', Intl::getIcuVersion());
}
public function testGetIcuDataVersionReadsTheVersionOfInstalledIcuData()
{
$this->assertStringMatchesFormat('%d.%d', Intl::getIcuDataVersion());
}
public function testGetIcuStubVersionReadsTheVersionOfBundledStubs()
{
$this->assertStringMatchesFormat('%d.%d', Intl::getIcuStubVersion());
}
public function testGetDataDirectoryReturnsThePathToIcuData()
{
$this->assertDirectoryExists(Intl::getDataDirectory());
}
/**
* @requires extension intl
*/
public function testLocaleAliasesAreLoaded()
{
\Locale::setDefault('zh_TW');
$countryNameZhTw = Intl::getRegionBundle()->getCountryName('AD');
\Locale::setDefault('zh_Hant_TW');
$countryNameHantZhTw = Intl::getRegionBundle()->getCountryName('AD');
\Locale::setDefault('zh');
$countryNameZh = Intl::getRegionBundle()->getCountryName('AD');
$this->assertSame($countryNameZhTw, $countryNameHantZhTw, 'zh_TW is an alias to zh_Hant_TW');
$this->assertNotSame($countryNameZh, $countryNameZhTw, 'zh_TW does not fall back to zh');
}
}

View File

@@ -0,0 +1,31 @@
<?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\Locale;
use PHPUnit\Framework\TestCase;
/**
* Test case for Locale implementations.
*
* @author Bernhard Schussek <bschussek@gmail.com>
*/
abstract class AbstractLocaleTest extends TestCase
{
public function testSetDefault()
{
$this->call('setDefault', 'en_GB');
$this->assertSame('en_GB', $this->call('getDefault'));
}
abstract protected function call($methodName);
}

View File

@@ -0,0 +1,134 @@
<?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\Locale;
class LocaleTest extends AbstractLocaleTest
{
public function testAcceptFromHttp()
{
$this->expectException('Symfony\Component\Intl\Exception\MethodNotImplementedException');
$this->call('acceptFromHttp', 'pt-br,en-us;q=0.7,en;q=0.5');
}
public function testComposeLocale()
{
$this->expectException('Symfony\Component\Intl\Exception\MethodNotImplementedException');
$subtags = [
'language' => 'pt',
'script' => 'Latn',
'region' => 'BR',
];
$this->call('composeLocale', $subtags);
}
public function testFilterMatches()
{
$this->expectException('Symfony\Component\Intl\Exception\MethodNotImplementedException');
$this->call('filterMatches', 'pt-BR', 'pt-BR');
}
public function testGetAllVariants()
{
$this->expectException('Symfony\Component\Intl\Exception\MethodNotImplementedException');
$this->call('getAllVariants', 'pt_BR_Latn');
}
public function testGetDisplayLanguage()
{
$this->expectException('Symfony\Component\Intl\Exception\MethodNotImplementedException');
$this->call('getDisplayLanguage', 'pt-Latn-BR', 'en');
}
public function testGetDisplayName()
{
$this->expectException('Symfony\Component\Intl\Exception\MethodNotImplementedException');
$this->call('getDisplayName', 'pt-Latn-BR', 'en');
}
public function testGetDisplayRegion()
{
$this->expectException('Symfony\Component\Intl\Exception\MethodNotImplementedException');
$this->call('getDisplayRegion', 'pt-Latn-BR', 'en');
}
public function testGetDisplayScript()
{
$this->expectException('Symfony\Component\Intl\Exception\MethodNotImplementedException');
$this->call('getDisplayScript', 'pt-Latn-BR', 'en');
}
public function testGetDisplayVariant()
{
$this->expectException('Symfony\Component\Intl\Exception\MethodNotImplementedException');
$this->call('getDisplayVariant', 'pt-Latn-BR', 'en');
}
public function testGetKeywords()
{
$this->expectException('Symfony\Component\Intl\Exception\MethodNotImplementedException');
$this->call('getKeywords', 'pt-BR@currency=BRL');
}
public function testGetPrimaryLanguage()
{
$this->expectException('Symfony\Component\Intl\Exception\MethodNotImplementedException');
$this->call('getPrimaryLanguage', 'pt-Latn-BR');
}
public function testGetRegion()
{
$this->expectException('Symfony\Component\Intl\Exception\MethodNotImplementedException');
$this->call('getRegion', 'pt-Latn-BR');
}
public function testGetScript()
{
$this->expectException('Symfony\Component\Intl\Exception\MethodNotImplementedException');
$this->call('getScript', 'pt-Latn-BR');
}
public function testLookup()
{
$this->expectException('Symfony\Component\Intl\Exception\MethodNotImplementedException');
$langtag = [
'pt-Latn-BR',
'pt-BR',
];
$this->call('lookup', $langtag, 'pt-BR-x-priv1');
}
public function testParseLocale()
{
$this->expectException('Symfony\Component\Intl\Exception\MethodNotImplementedException');
$this->call('parseLocale', 'pt-Latn-BR');
}
public function testSetDefault()
{
$this->expectException('Symfony\Component\Intl\Exception\MethodNotImplementedException');
$this->call('setDefault', 'pt_BR');
}
public function testSetDefaultAcceptsEn()
{
$this->call('setDefault', 'en');
$this->assertSame('en', $this->call('getDefault'));
}
protected function call($methodName)
{
$args = \array_slice(\func_get_args(), 1);
return \call_user_func_array(['Symfony\Component\Intl\Locale\Locale', $methodName], $args);
}
}

View File

@@ -0,0 +1,38 @@
<?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\Locale\Verification;
use Symfony\Component\Intl\Tests\Locale\AbstractLocaleTest;
use Symfony\Component\Intl\Util\IntlTestHelper;
/**
* Verifies that {@link AbstractLocaleTest} matches the behavior of the
* {@link Locale} class with a specific version of ICU.
*
* @author Bernhard Schussek <bschussek@gmail.com>
*/
class LocaleTest extends AbstractLocaleTest
{
protected function setUp()
{
IntlTestHelper::requireFullIntl($this, false);
parent::setUp();
}
protected function call($methodName)
{
$args = \array_slice(\func_get_args(), 1);
return \call_user_func_array(['Locale', $methodName], $args);
}
}

View File

@@ -0,0 +1,73 @@
<?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 PHPUnit\Framework\TestCase;
use Symfony\Component\Intl\Locale;
class LocaleTest extends TestCase
{
public function provideGetFallbackTests()
{
$tests = [
['sl_Latn_IT', 'sl_Latn_IT_nedis'],
['sl_Latn', 'sl_Latn_IT'],
['fr', 'fr_FR'],
['fr', 'fr-FR'],
['en', 'fr'],
['root', 'en'],
[null, 'root'],
];
if (\function_exists('locale_parse')) {
$tests[] = ['sl_Latn_IT', 'sl-Latn-IT-nedis'];
$tests[] = ['sl_Latn', 'sl-Latn_IT'];
} else {
$tests[] = ['sl-Latn-IT', 'sl-Latn-IT-nedis'];
$tests[] = ['sl-Latn', 'sl-Latn-IT'];
}
return $tests;
}
/**
* @dataProvider provideGetFallbackTests
*/
public function testGetFallback($expected, $locale)
{
$this->assertSame($expected, Locale::getFallback($locale));
}
public function testNoDefaultFallback()
{
$prev = Locale::getDefaultFallback();
Locale::setDefaultFallback(null);
$this->assertSame('nl', Locale::getFallback('nl_NL'));
$this->assertNull(Locale::getFallback('nl'));
$this->assertNull(Locale::getFallback('root'));
Locale::setDefaultFallback($prev);
}
public function testDefaultRootFallback()
{
$prev = Locale::getDefaultFallback();
Locale::setDefaultFallback('root');
$this->assertSame('nl', Locale::getFallback('nl_NL'));
$this->assertSame('root', Locale::getFallback('nl'));
$this->assertNull(Locale::getFallback('root'));
Locale::setDefaultFallback($prev);
}
}

View File

@@ -0,0 +1,889 @@
<?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\NumberFormatter;
use PHPUnit\Framework\Error\Warning;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Intl\Globals\IntlGlobals;
use Symfony\Component\Intl\NumberFormatter\NumberFormatter;
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 TestCase
{
/**
* @dataProvider formatCurrencyWithDecimalStyleProvider
*/
public function testFormatCurrencyWithDecimalStyle($value, $currency, $expected)
{
$formatter = $this->getNumberFormatter('en', NumberFormatter::DECIMAL);
$this->assertEquals($expected, $formatter->formatCurrency($value, $currency));
}
public function formatCurrencyWithDecimalStyleProvider()
{
return [
[100, 'ALL', '100'],
[100, 'BRL', '100'],
[100, 'CRC', '100'],
[100, 'JPY', '100'],
[100, 'CHF', '100'],
[-100, 'ALL', '-100'],
[-100, 'BRL', '-100'],
[-100, 'CRC', '-100'],
[-100, 'JPY', '-100'],
[-100, 'CHF', '-100'],
[1000.12, 'ALL', '1,000.12'],
[1000.12, 'BRL', '1,000.12'],
[1000.12, 'CRC', '1,000.12'],
[1000.12, 'JPY', '1,000.12'],
[1000.12, 'CHF', '1,000.12'],
];
}
/**
* @dataProvider formatCurrencyWithCurrencyStyleProvider
*/
public function testFormatCurrencyWithCurrencyStyle($value, $currency, $expected)
{
IntlTestHelper::requireIntl($this, '63.1');
$formatter = $this->getNumberFormatter('en', NumberFormatter::CURRENCY);
$this->assertEquals($expected, $formatter->formatCurrency($value, $currency));
}
public function formatCurrencyWithCurrencyStyleProvider()
{
return [
[100, 'ALL', "ALL\xc2\xa0100"],
[-100, 'ALL', "-ALL\xc2\xa0100"],
[1000.12, 'ALL', "ALL\xc2\xa01,000"],
[100, 'JPY', '¥100'],
[-100, 'JPY', '-¥100'],
[1000.12, 'JPY', '¥1,000'],
[100, 'EUR', '€100.00'],
[-100, 'EUR', '-€100.00'],
[1000.12, 'EUR', '€1,000.12'],
];
}
/**
* @dataProvider formatCurrencyWithCurrencyStyleCostaRicanColonsRoundingProvider
*/
public function testFormatCurrencyWithCurrencyStyleCostaRicanColonsRounding($value, $currency, $symbol, $expected)
{
IntlTestHelper::requireIntl($this, '63.1');
$formatter = $this->getNumberFormatter('en', NumberFormatter::CURRENCY);
$this->assertEquals(sprintf($expected, $symbol), $formatter->formatCurrency($value, $currency));
}
public function formatCurrencyWithCurrencyStyleCostaRicanColonsRoundingProvider()
{
return [
[100, 'CRC', 'CRC', "%s\xc2\xa0100.00"],
[-100, 'CRC', 'CRC', "-%s\xc2\xa0100.00"],
[1000.12, 'CRC', 'CRC', "%s\xc2\xa01,000.12"],
];
}
/**
* @dataProvider formatCurrencyWithCurrencyStyleBrazilianRealRoundingProvider
*/
public function testFormatCurrencyWithCurrencyStyleBrazilianRealRounding($value, $currency, $symbol, $expected)
{
$formatter = $this->getNumberFormatter('en', NumberFormatter::CURRENCY);
$this->assertEquals(sprintf($expected, $symbol), $formatter->formatCurrency($value, $currency));
}
public function formatCurrencyWithCurrencyStyleBrazilianRealRoundingProvider()
{
return [
[100, 'BRL', 'R', '%s$100.00'],
[-100, 'BRL', 'R', '-%s$100.00'],
[1000.12, 'BRL', 'R', '%s$1,000.12'],
// Rounding checks
[1000.121, 'BRL', 'R', '%s$1,000.12'],
[1000.123, 'BRL', 'R', '%s$1,000.12'],
[1000.125, 'BRL', 'R', '%s$1,000.12'],
[1000.127, 'BRL', 'R', '%s$1,000.13'],
[1000.129, 'BRL', 'R', '%s$1,000.13'],
[11.50999, 'BRL', 'R', '%s$11.51'],
[11.9999464, 'BRL', 'R', '%s$12.00'],
];
}
/**
* @dataProvider formatCurrencyWithCurrencyStyleSwissRoundingProvider
*/
public function testFormatCurrencyWithCurrencyStyleSwissRounding($value, $currency, $symbol, $expected)
{
IntlTestHelper::requireIntl($this, '62.1');
$formatter = $this->getNumberFormatter('en', NumberFormatter::CURRENCY);
$this->assertEquals(sprintf($expected, $symbol), $formatter->formatCurrency($value, $currency));
}
public function formatCurrencyWithCurrencyStyleSwissRoundingProvider()
{
return [
[100, 'CHF', 'CHF', "%s\xc2\xa0100.00"],
[-100, 'CHF', 'CHF', "-%s\xc2\xa0100.00"],
[1000.12, 'CHF', 'CHF', "%s\xc2\xa01,000.12"],
['1000.12', 'CHF', 'CHF', "%s\xc2\xa01,000.12"],
// Rounding checks
[1000.121, 'CHF', 'CHF', "%s\xc2\xa01,000.12"],
[1000.123, 'CHF', 'CHF', "%s\xc2\xa01,000.12"],
[1000.125, 'CHF', 'CHF', "%s\xc2\xa01,000.12"],
[1000.127, 'CHF', 'CHF', "%s\xc2\xa01,000.13"],
[1000.129, 'CHF', 'CHF', "%s\xc2\xa01,000.13"],
[1200000.00, 'CHF', 'CHF', "%s\xc2\xa01,200,000.00"],
[1200000.1, 'CHF', 'CHF', "%s\xc2\xa01,200,000.10"],
[1200000.10, 'CHF', 'CHF', "%s\xc2\xa01,200,000.10"],
[1200000.101, 'CHF', 'CHF', "%s\xc2\xa01,200,000.10"],
];
}
public function testFormat()
{
$errorCode = IntlGlobals::U_ZERO_ERROR;
$errorMessage = 'U_ZERO_ERROR';
$formatter = $this->getNumberFormatter('en', NumberFormatter::DECIMAL);
$this->assertSame('9.555', $formatter->format(9.555));
$this->assertSame($errorMessage, $this->getIntlErrorMessage());
$this->assertSame($errorCode, $this->getIntlErrorCode());
$this->assertFalse($this->isIntlFailure($this->getIntlErrorCode()));
$this->assertSame($errorMessage, $formatter->getErrorMessage());
$this->assertSame($errorCode, $formatter->getErrorCode());
$this->assertFalse($this->isIntlFailure($formatter->getErrorCode()));
}
public function testFormatWithCurrencyStyle()
{
IntlTestHelper::requireIntl($this, '63.1');
$formatter = $this->getNumberFormatter('en', NumberFormatter::CURRENCY);
$this->assertEquals('¤1.00', $formatter->format(1));
}
/**
* @dataProvider formatTypeInt32Provider
*/
public function testFormatTypeInt32($formatter, $value, $expected, $message = '')
{
$formattedValue = $formatter->format($value, NumberFormatter::TYPE_INT32);
$this->assertEquals($expected, $formattedValue, $message);
}
public function formatTypeInt32Provider()
{
$formatter = $this->getNumberFormatter('en', NumberFormatter::DECIMAL);
$message = '->format() TYPE_INT32 formats inconsistently an integer if out of the 32 bit range.';
return [
[$formatter, 1, '1'],
[$formatter, 1.1, '1'],
[$formatter, 2147483648, '-2,147,483,648', $message],
[$formatter, -2147483649, '2,147,483,647', $message],
];
}
/**
* @dataProvider formatTypeInt32WithCurrencyStyleProvider
*/
public function testFormatTypeInt32WithCurrencyStyle($formatter, $value, $expected, $message = '')
{
IntlTestHelper::requireIntl($this, '63.1');
$formattedValue = $formatter->format($value, NumberFormatter::TYPE_INT32);
$this->assertEquals($expected, $formattedValue, $message);
}
public function formatTypeInt32WithCurrencyStyleProvider()
{
$formatter = $this->getNumberFormatter('en', NumberFormatter::CURRENCY);
$message = '->format() TYPE_INT32 formats inconsistently an integer if out of the 32 bit range.';
return [
[$formatter, 1, '¤1.00'],
[$formatter, 1.1, '¤1.00'],
[$formatter, 2147483648, '-¤2,147,483,648.00', $message],
[$formatter, -2147483649, '¤2,147,483,647.00', $message],
];
}
/**
* The parse() method works differently with integer out of the 32 bit range. format() works fine.
*
* @dataProvider formatTypeInt64Provider
*/
public function testFormatTypeInt64($formatter, $value, $expected)
{
$formattedValue = $formatter->format($value, NumberFormatter::TYPE_INT64);
$this->assertEquals($expected, $formattedValue);
}
public function formatTypeInt64Provider()
{
$formatter = $this->getNumberFormatter('en', NumberFormatter::DECIMAL);
return [
[$formatter, 1, '1'],
[$formatter, 1.1, '1'],
[$formatter, 2147483648, '2,147,483,648'],
[$formatter, -2147483649, '-2,147,483,649'],
];
}
/**
* @dataProvider formatTypeInt64WithCurrencyStyleProvider
*/
public function testFormatTypeInt64WithCurrencyStyle($formatter, $value, $expected)
{
IntlTestHelper::requireIntl($this, '63.1');
$formattedValue = $formatter->format($value, NumberFormatter::TYPE_INT64);
$this->assertEquals($expected, $formattedValue);
}
public function formatTypeInt64WithCurrencyStyleProvider()
{
$formatter = $this->getNumberFormatter('en', NumberFormatter::CURRENCY);
return [
[$formatter, 1, '¤1.00'],
[$formatter, 1.1, '¤1.00'],
[$formatter, 2147483648, '¤2,147,483,648.00'],
[$formatter, -2147483649, '-¤2,147,483,649.00'],
];
}
/**
* @dataProvider formatTypeDoubleProvider
*/
public function testFormatTypeDouble($formatter, $value, $expected)
{
$formattedValue = $formatter->format($value, NumberFormatter::TYPE_DOUBLE);
$this->assertEquals($expected, $formattedValue);
}
public function formatTypeDoubleProvider()
{
$formatter = $this->getNumberFormatter('en', NumberFormatter::DECIMAL);
return [
[$formatter, 1, '1'],
[$formatter, 1.1, '1.1'],
];
}
/**
* @dataProvider formatTypeDoubleWithCurrencyStyleProvider
*/
public function testFormatTypeDoubleWithCurrencyStyle($formatter, $value, $expected)
{
IntlTestHelper::requireIntl($this, '63.1');
$formattedValue = $formatter->format($value, NumberFormatter::TYPE_DOUBLE);
$this->assertEquals($expected, $formattedValue);
}
public function formatTypeDoubleWithCurrencyStyleProvider()
{
$formatter = $this->getNumberFormatter('en', NumberFormatter::CURRENCY);
return [
[$formatter, 1, '¤1.00'],
[$formatter, 1.1, '¤1.10'],
];
}
/**
* @dataProvider formatTypeCurrencyProvider
*/
public function testFormatTypeCurrency($formatter, $value)
{
if (\PHP_VERSION_ID >= 80000) {
$this->expectException(\ValueError::class);
} elseif (method_exists($this, 'expectWarning')) {
$this->expectWarning();
} else {
$this->expectException(Warning::class);
}
$formatter->format($value, NumberFormatter::TYPE_CURRENCY);
}
/**
* @dataProvider formatTypeCurrencyProvider
*/
public function testFormatTypeCurrencyReturn($formatter, $value)
{
if (\PHP_VERSION_ID >= 80000) {
$this->expectException(\ValueError::class);
}
$this->assertFalse(@$formatter->format($value, NumberFormatter::TYPE_CURRENCY));
}
public function formatTypeCurrencyProvider()
{
$df = $this->getNumberFormatter('en', NumberFormatter::DECIMAL);
$cf = $this->getNumberFormatter('en', NumberFormatter::CURRENCY);
return [
[$df, 1],
[$cf, 1],
];
}
/**
* @dataProvider formatFractionDigitsProvider
*/
public function testFormatFractionDigits($value, $expected, $fractionDigits = null, $expectedFractionDigits = 1)
{
IntlTestHelper::requireIntl($this, '62.1');
$formatter = $this->getNumberFormatter('en', NumberFormatter::DECIMAL);
$attributeRet = null;
if (null !== $fractionDigits) {
$attributeRet = $formatter->setAttribute(NumberFormatter::FRACTION_DIGITS, $fractionDigits);
}
$formattedValue = $formatter->format($value);
$this->assertSame($expected, $formattedValue);
$this->assertSame($expectedFractionDigits, $formatter->getAttribute(NumberFormatter::FRACTION_DIGITS));
if (null !== $attributeRet) {
$this->assertTrue($attributeRet);
}
}
public function formatFractionDigitsProvider()
{
yield [1.123, '1.123', null, 0];
yield [1.123, '1', 0, 0];
yield [1.123, '1.1', 1, 1];
yield [1.123, '1.12', 2, 2];
yield [1.123, '1.123', -1, 0];
if (\PHP_VERSION_ID < 80000) {
// This dataset will produce a TypeError on php 8.
yield [1.123, '1', 'abc', 0];
}
}
/**
* @dataProvider formatGroupingUsedProvider
*/
public function testFormatGroupingUsed($value, $expected, $groupingUsed = null, $expectedGroupingUsed = 1)
{
$formatter = $this->getNumberFormatter('en', NumberFormatter::DECIMAL);
$attributeRet = null;
if (null !== $groupingUsed) {
$attributeRet = $formatter->setAttribute(NumberFormatter::GROUPING_USED, $groupingUsed);
}
$formattedValue = $formatter->format($value);
$this->assertSame($expected, $formattedValue);
$this->assertSame($expectedGroupingUsed, $formatter->getAttribute(NumberFormatter::GROUPING_USED));
if (null !== $attributeRet) {
$this->assertTrue($attributeRet);
}
}
public function formatGroupingUsedProvider()
{
yield [1000, '1,000', null, 1];
yield [1000, '1000', 0, 0];
yield [1000, '1,000', 1, 1];
yield [1000, '1,000', 2, 1];
yield [1000, '1,000', -1, 1];
if (\PHP_VERSION_ID < 80000) {
// This dataset will produce a TypeError on php 8.
yield [1000, '1000', 'abc', 0];
}
}
/**
* @dataProvider formatRoundingModeRoundHalfUpProvider
*/
public function testFormatRoundingModeHalfUp($value, $expected)
{
$formatter = $this->getNumberFormatter('en', NumberFormatter::DECIMAL);
$formatter->setAttribute(NumberFormatter::FRACTION_DIGITS, 2);
$formatter->setAttribute(NumberFormatter::ROUNDING_MODE, NumberFormatter::ROUND_HALFUP);
$this->assertSame($expected, $formatter->format($value), '->format() with ROUND_HALFUP rounding mode.');
}
public function formatRoundingModeRoundHalfUpProvider()
{
// The commented value is differently rounded by intl's NumberFormatter in 32 and 64 bit architectures
return [
[1.121, '1.12'],
[1.123, '1.12'],
// [1.125, '1.13'],
[1.127, '1.13'],
[1.129, '1.13'],
[1020 / 100, '10.20'],
];
}
/**
* @dataProvider formatRoundingModeRoundHalfDownProvider
*/
public function testFormatRoundingModeHalfDown($value, $expected)
{
$formatter = $this->getNumberFormatter('en', NumberFormatter::DECIMAL);
$formatter->setAttribute(NumberFormatter::FRACTION_DIGITS, 2);
$formatter->setAttribute(NumberFormatter::ROUNDING_MODE, NumberFormatter::ROUND_HALFDOWN);
$this->assertSame($expected, $formatter->format($value), '->format() with ROUND_HALFDOWN rounding mode.');
}
public function formatRoundingModeRoundHalfDownProvider()
{
return [
[1.121, '1.12'],
[1.123, '1.12'],
[1.125, '1.12'],
[1.127, '1.13'],
[1.129, '1.13'],
[1020 / 100, '10.20'],
];
}
/**
* @dataProvider formatRoundingModeRoundHalfEvenProvider
*/
public function testFormatRoundingModeHalfEven($value, $expected)
{
$formatter = $this->getNumberFormatter('en', NumberFormatter::DECIMAL);
$formatter->setAttribute(NumberFormatter::FRACTION_DIGITS, 2);
$formatter->setAttribute(NumberFormatter::ROUNDING_MODE, NumberFormatter::ROUND_HALFEVEN);
$this->assertSame($expected, $formatter->format($value), '->format() with ROUND_HALFEVEN rounding mode.');
}
public function formatRoundingModeRoundHalfEvenProvider()
{
return [
[1.121, '1.12'],
[1.123, '1.12'],
[1.125, '1.12'],
[1.127, '1.13'],
[1.129, '1.13'],
[1020 / 100, '10.20'],
];
}
/**
* @dataProvider formatRoundingModeRoundCeilingProvider
*/
public function testFormatRoundingModeCeiling($value, $expected)
{
$formatter = $this->getNumberFormatter('en', NumberFormatter::DECIMAL);
$formatter->setAttribute(NumberFormatter::FRACTION_DIGITS, 2);
$formatter->setAttribute(NumberFormatter::ROUNDING_MODE, NumberFormatter::ROUND_CEILING);
$this->assertSame($expected, $formatter->format($value), '->format() with ROUND_CEILING rounding mode.');
}
public function formatRoundingModeRoundCeilingProvider()
{
return [
[1.123, '1.13'],
[1.125, '1.13'],
[1.127, '1.13'],
[-1.123, '-1.12'],
[-1.125, '-1.12'],
[-1.127, '-1.12'],
[1020 / 100, '10.20'],
];
}
/**
* @dataProvider formatRoundingModeRoundFloorProvider
*/
public function testFormatRoundingModeFloor($value, $expected)
{
$formatter = $this->getNumberFormatter('en', NumberFormatter::DECIMAL);
$formatter->setAttribute(NumberFormatter::FRACTION_DIGITS, 2);
$formatter->setAttribute(NumberFormatter::ROUNDING_MODE, NumberFormatter::ROUND_FLOOR);
$this->assertSame($expected, $formatter->format($value), '->format() with ROUND_FLOOR rounding mode.');
}
public function formatRoundingModeRoundFloorProvider()
{
return [
[1.123, '1.12'],
[1.125, '1.12'],
[1.127, '1.12'],
[-1.123, '-1.13'],
[-1.125, '-1.13'],
[-1.127, '-1.13'],
[1020 / 100, '10.20'],
];
}
/**
* @dataProvider formatRoundingModeRoundDownProvider
*/
public function testFormatRoundingModeDown($value, $expected)
{
$formatter = $this->getNumberFormatter('en', NumberFormatter::DECIMAL);
$formatter->setAttribute(NumberFormatter::FRACTION_DIGITS, 2);
$formatter->setAttribute(NumberFormatter::ROUNDING_MODE, NumberFormatter::ROUND_DOWN);
$this->assertSame($expected, $formatter->format($value), '->format() with ROUND_DOWN rounding mode.');
}
public function formatRoundingModeRoundDownProvider()
{
return [
[1.123, '1.12'],
[1.125, '1.12'],
[1.127, '1.12'],
[-1.123, '-1.12'],
[-1.125, '-1.12'],
[-1.127, '-1.12'],
[1020 / 100, '10.20'],
];
}
/**
* @dataProvider formatRoundingModeRoundUpProvider
*/
public function testFormatRoundingModeUp($value, $expected)
{
$formatter = $this->getNumberFormatter('en', NumberFormatter::DECIMAL);
$formatter->setAttribute(NumberFormatter::FRACTION_DIGITS, 2);
$formatter->setAttribute(NumberFormatter::ROUNDING_MODE, NumberFormatter::ROUND_UP);
$this->assertSame($expected, $formatter->format($value), '->format() with ROUND_UP rounding mode.');
}
public function formatRoundingModeRoundUpProvider()
{
return [
[1.123, '1.13'],
[1.125, '1.13'],
[1.127, '1.13'],
[-1.123, '-1.13'],
[-1.125, '-1.13'],
[-1.127, '-1.13'],
[1020 / 100, '10.20'],
];
}
public function testGetLocale()
{
$formatter = $this->getNumberFormatter('en', NumberFormatter::DECIMAL);
$this->assertEquals('en', $formatter->getLocale());
}
public function testGetSymbol()
{
$decimalFormatter = $this->getNumberFormatter('en', NumberFormatter::DECIMAL);
$currencyFormatter = $this->getNumberFormatter('en', NumberFormatter::CURRENCY);
$r = new \ReflectionProperty('Symfony\Component\Intl\NumberFormatter\NumberFormatter', 'enSymbols');
$r->setAccessible(true);
$expected = $r->getValue();
for ($i = 0; $i <= 17; ++$i) {
$this->assertSame($expected[1][$i], $decimalFormatter->getSymbol($i));
$this->assertSame($expected[2][$i], $currencyFormatter->getSymbol($i));
}
}
public function testGetTextAttribute()
{
IntlTestHelper::requireIntl($this, '63.1');
$decimalFormatter = $this->getNumberFormatter('en', NumberFormatter::DECIMAL);
$currencyFormatter = $this->getNumberFormatter('en', NumberFormatter::CURRENCY);
$r = new \ReflectionProperty('Symfony\Component\Intl\NumberFormatter\NumberFormatter', 'enTextAttributes');
$r->setAccessible(true);
$expected = $r->getValue();
for ($i = 0; $i <= 5; ++$i) {
$this->assertSame($expected[1][$i], $decimalFormatter->getTextAttribute($i));
$this->assertSame($expected[2][$i], $currencyFormatter->getTextAttribute($i));
}
}
/**
* @dataProvider parseProvider
*/
public function testParse($value, $expected, $message, $expectedPosition, $groupingUsed = true)
{
IntlTestHelper::requireIntl($this, '62.1');
$position = 0;
$formatter = $this->getNumberFormatter('en', NumberFormatter::DECIMAL);
$formatter->setAttribute(NumberFormatter::GROUPING_USED, $groupingUsed);
$parsedValue = $formatter->parse($value, NumberFormatter::TYPE_DOUBLE, $position);
$this->assertSame($expected, $parsedValue, $message);
$this->assertSame($expectedPosition, $position, $message);
if (false === $expected) {
$errorCode = IntlGlobals::U_PARSE_ERROR;
$errorMessage = 'Number parsing failed: U_PARSE_ERROR';
} else {
$errorCode = IntlGlobals::U_ZERO_ERROR;
$errorMessage = 'U_ZERO_ERROR';
}
$this->assertSame($errorMessage, $this->getIntlErrorMessage());
$this->assertSame($errorCode, $this->getIntlErrorCode());
$this->assertSame(0 !== $errorCode, $this->isIntlFailure($this->getIntlErrorCode()));
$this->assertSame($errorMessage, $formatter->getErrorMessage());
$this->assertSame($errorCode, $formatter->getErrorCode());
$this->assertSame(0 !== $errorCode, $this->isIntlFailure($formatter->getErrorCode()));
}
public function parseProvider()
{
return [
['prefix1', false, '->parse() does not parse a number with a string prefix.', 0],
['prefix1', false, '->parse() does not parse a number with a string prefix.', 0, false],
['1.4suffix', (float) 1.4, '->parse() parses a number with a string suffix.', 3],
['1.4suffix', (float) 1.4, '->parse() parses a number with a string suffix.', 3, false],
['1,234.4suffix', 1234.4, '->parse() parses a number with a string suffix.', 7],
['1,234.4suffix', 1.0, '->parse() parses a number with a string suffix.', 1, false],
['-.4suffix', (float) -0.4, '->parse() parses a negative dot float with suffix.', 3],
['-.4suffix', (float) -0.4, '->parse() parses a negative dot float with suffix.', 3, false],
[',4', false, '->parse() does not parse when invalid grouping used.', 0],
[',4', false, '->parse() does not parse when invalid grouping used.', 0, false],
['123,4', false, '->parse() does not parse when invalid grouping used.', 0],
['123,4', 123.0, '->parse() truncates invalid grouping when grouping is disabled.', 3, false],
['123,a4', 123.0, '->parse() truncates a string suffix.', 3],
['123,a4', 123.0, '->parse() truncates a string suffix.', 3, false],
['-123,4', false, '->parse() does not parse when invalid grouping used.', 1],
['-123,4', -123.0, '->parse() truncates invalid grouping when grouping is disabled.', 4, false],
['-123,4567', false, '->parse() does not parse when invalid grouping used.', 1],
['-123,4567', -123.0, '->parse() truncates invalid grouping when grouping is disabled.', 4, false],
['-123,456,789', -123456789.0, '->parse() parses a number with grouping.', 12],
['-123,456,789', -123.0, '->parse() truncates a group if grouping is disabled.', 4, false],
['-123,456,789.66', -123456789.66, '->parse() parses a number with grouping.', 15],
['-123,456,789.66', -123.00, '->parse() truncates a group if grouping is disabled.', 4, false],
['-123,456789.66', false, '->parse() does not parse when invalid grouping used.', 1],
['-123,456789.66', -123.00, '->parse() truncates a group if grouping is disabled.', 4, false],
['-123456,789.66', false, '->parse() does not parse when invalid grouping used.', 1],
['-123456,789.66', -123456.00, '->parse() truncates a group if grouping is disabled.', 7, false],
['-123,456,78', false, '->parse() does not parse when invalid grouping used.', 1],
['-123,456,78', -123.0, '->parse() truncates a group if grouping is disabled.', 4, false],
['-123,45,789', false, '->parse() does not parse when invalid grouping used.', 1],
['-123,45,789', -123.0, '->parse() truncates a group if grouping is disabled.', 4, false],
['-123,,456', -123.0, '->parse() parses when grouping is duplicated.', 4],
['-123,,456', -123.0, '->parse() parses when grouping is disabled.', 4, false],
['-123,,4', -123.0, '->parse() parses when grouping is duplicated.', 4],
['-123,,4', -123.0, '->parse() parses when grouping is duplicated.', 4, false],
['239.', 239.0, '->parse() parses when string ends with decimal separator.', 4],
['239.', 239.0, '->parse() parses when string ends with decimal separator.', 4, false],
];
}
public function testParseTypeDefault()
{
if (\PHP_VERSION_ID >= 80000) {
$this->expectException(\ValueError::class);
} elseif (method_exists($this, 'expectWarning')) {
$this->expectWarning();
} else {
$this->expectException(Warning::class);
}
$formatter = $this->getNumberFormatter('en', NumberFormatter::DECIMAL);
$formatter->parse('1', NumberFormatter::TYPE_DEFAULT);
}
/**
* @dataProvider parseTypeInt32Provider
*/
public function testParseTypeInt32($value, $expected, $message = '')
{
$formatter = $this->getNumberFormatter('en', NumberFormatter::DECIMAL);
$parsedValue = $formatter->parse($value, NumberFormatter::TYPE_INT32);
$this->assertSame($expected, $parsedValue, $message);
}
public function parseTypeInt32Provider()
{
return [
['1', 1],
['1.1', 1],
['.1', 0],
['2,147,483,647', 2147483647],
['-2,147,483,648', -2147483647 - 1],
['2,147,483,648', false, '->parse() TYPE_INT32 returns false when the number is greater than the integer positive range.'],
['-2,147,483,649', false, '->parse() TYPE_INT32 returns false when the number is greater than the integer negative range.'],
];
}
public function testParseTypeInt64With32BitIntegerInPhp32Bit()
{
IntlTestHelper::require32Bit($this);
$formatter = $this->getNumberFormatter('en', NumberFormatter::DECIMAL);
$parsedValue = $formatter->parse('2,147,483,647', NumberFormatter::TYPE_INT64);
$this->assertIsInt($parsedValue);
$this->assertEquals(2147483647, $parsedValue);
$parsedValue = $formatter->parse('-2,147,483,648', NumberFormatter::TYPE_INT64);
$this->assertIsInt($parsedValue);
$this->assertEquals(-2147483648, $parsedValue);
}
public function testParseTypeInt64With32BitIntegerInPhp64Bit()
{
IntlTestHelper::require64Bit($this);
$formatter = $this->getNumberFormatter('en', NumberFormatter::DECIMAL);
$parsedValue = $formatter->parse('2,147,483,647', NumberFormatter::TYPE_INT64);
$this->assertIsInt($parsedValue);
$this->assertEquals(2147483647, $parsedValue);
$parsedValue = $formatter->parse('-2,147,483,648', NumberFormatter::TYPE_INT64);
$this->assertIsInt($parsedValue);
$this->assertEquals(-2147483647 - 1, $parsedValue);
}
/**
* If PHP is compiled in 32bit mode, the returned value for a 64bit integer are float numbers.
*/
public function testParseTypeInt64With64BitIntegerInPhp32Bit()
{
IntlTestHelper::require32Bit($this);
$formatter = $this->getNumberFormatter('en', NumberFormatter::DECIMAL);
// int 64 using only 32 bit range strangeness
$parsedValue = $formatter->parse('2,147,483,648', NumberFormatter::TYPE_INT64);
$this->assertIsFloat($parsedValue);
$this->assertEquals(2147483648, $parsedValue, '->parse() TYPE_INT64 does not use true 64 bit integers, using only the 32 bit range.');
$parsedValue = $formatter->parse('-2,147,483,649', NumberFormatter::TYPE_INT64);
$this->assertIsFloat($parsedValue);
$this->assertEquals(-2147483649, $parsedValue, '->parse() TYPE_INT64 does not use true 64 bit integers, using only the 32 bit range.');
}
/**
* If PHP is compiled in 64bit mode, the returned value for a 64bit integer are 32bit integer numbers.
*/
public function testParseTypeInt64With64BitIntegerInPhp64Bit()
{
IntlTestHelper::require64Bit($this);
$formatter = $this->getNumberFormatter('en', NumberFormatter::DECIMAL);
$parsedValue = $formatter->parse('2,147,483,648', NumberFormatter::TYPE_INT64);
$this->assertIsInt($parsedValue);
$this->assertEquals(2147483648, $parsedValue, '->parse() TYPE_INT64 uses true 64 bit integers (PHP >= 5.3.14 and PHP >= 5.4.4).');
$parsedValue = $formatter->parse('-2,147,483,649', NumberFormatter::TYPE_INT64);
$this->assertIsInt($parsedValue);
$this->assertEquals(-2147483649, $parsedValue, '->parse() TYPE_INT64 uses true 64 bit integers (PHP >= 5.3.14 and PHP >= 5.4.4).');
}
/**
* @dataProvider parseTypeDoubleProvider
*/
public function testParseTypeDouble($value, $expectedValue)
{
$formatter = $this->getNumberFormatter('en', NumberFormatter::DECIMAL);
$parsedValue = $formatter->parse($value, NumberFormatter::TYPE_DOUBLE);
$this->assertEqualsWithDelta($expectedValue, $parsedValue, 0.001);
}
public function parseTypeDoubleProvider()
{
return [
['1', (float) 1],
['1.1', 1.1],
['9,223,372,036,854,775,808', 9223372036854775808],
['-9,223,372,036,854,775,809', -9223372036854775809],
];
}
public function testParseTypeCurrency()
{
if (\PHP_VERSION_ID >= 80000) {
$this->expectException(\ValueError::class);
} elseif (method_exists($this, 'expectWarning')) {
$this->expectWarning();
} else {
$this->expectException(Warning::class);
}
$formatter = $this->getNumberFormatter('en', NumberFormatter::DECIMAL);
$formatter->parse('1', NumberFormatter::TYPE_CURRENCY);
}
public function testParseWithNotNullPositionValue()
{
$position = 1;
$formatter = $this->getNumberFormatter('en', NumberFormatter::DECIMAL);
$formatter->parse('123', NumberFormatter::TYPE_DOUBLE, $position);
$this->assertEquals(3, $position);
}
/**
* @param string $locale
* @param null $style
* @param null $pattern
*
* @return \NumberFormatter
*/
abstract protected function getNumberFormatter($locale = 'en', $style = null, $pattern = null);
/**
* @return string
*/
abstract protected function getIntlErrorMessage();
/**
* @return int
*/
abstract protected function getIntlErrorCode();
/**
* @param int $errorCode
*
* @return bool
*/
abstract protected function isIntlFailure($errorCode);
}

View File

@@ -0,0 +1,191 @@
<?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\NumberFormatter;
use Symfony\Component\Intl\Globals\IntlGlobals;
use Symfony\Component\Intl\NumberFormatter\NumberFormatter;
/**
* Note that there are some values written like -2147483647 - 1. This is the lower 32bit int max and is a known
* behavior of PHP.
*/
class NumberFormatterTest extends AbstractNumberFormatterTest
{
public function testConstructorWithUnsupportedLocale()
{
$this->expectException('Symfony\Component\Intl\Exception\MethodArgumentValueNotImplementedException');
new NumberFormatter('pt_BR');
}
public function testConstructorWithUnsupportedStyle()
{
$this->expectException('Symfony\Component\Intl\Exception\MethodArgumentValueNotImplementedException');
new NumberFormatter('en', NumberFormatter::PATTERN_DECIMAL);
}
public function testConstructorWithPatternDifferentThanNull()
{
$this->expectException('Symfony\Component\Intl\Exception\MethodArgumentNotImplementedException');
new NumberFormatter('en', NumberFormatter::DECIMAL, '');
}
public function testSetAttributeWithUnsupportedAttribute()
{
$this->expectException('Symfony\Component\Intl\Exception\MethodArgumentValueNotImplementedException');
$formatter = $this->getNumberFormatter('en', NumberFormatter::DECIMAL);
$formatter->setAttribute(NumberFormatter::LENIENT_PARSE, null);
}
public function testSetAttributeInvalidRoundingMode()
{
$this->expectException('Symfony\Component\Intl\Exception\MethodArgumentValueNotImplementedException');
$formatter = $this->getNumberFormatter('en', NumberFormatter::DECIMAL);
$formatter->setAttribute(NumberFormatter::ROUNDING_MODE, null);
}
public function testConstructWithoutLocale()
{
$this->assertInstanceOf(
'\Symfony\Component\Intl\NumberFormatter\NumberFormatter',
$this->getNumberFormatter(null, NumberFormatter::DECIMAL)
);
}
public function testCreate()
{
$this->assertInstanceOf(
'\Symfony\Component\Intl\NumberFormatter\NumberFormatter',
NumberFormatter::create('en', NumberFormatter::DECIMAL)
);
}
public function testFormatWithCurrencyStyle()
{
$this->expectException('RuntimeException');
parent::testFormatWithCurrencyStyle();
}
/**
* @dataProvider formatTypeInt32Provider
*/
public function testFormatTypeInt32($formatter, $value, $expected, $message = '')
{
$this->expectException('Symfony\Component\Intl\Exception\MethodArgumentValueNotImplementedException');
parent::testFormatTypeInt32($formatter, $value, $expected, $message);
}
/**
* @dataProvider formatTypeInt32WithCurrencyStyleProvider
*/
public function testFormatTypeInt32WithCurrencyStyle($formatter, $value, $expected, $message = '')
{
$this->expectException('Symfony\Component\Intl\Exception\NotImplementedException');
parent::testFormatTypeInt32WithCurrencyStyle($formatter, $value, $expected, $message);
}
/**
* @dataProvider formatTypeInt64Provider
*/
public function testFormatTypeInt64($formatter, $value, $expected)
{
$this->expectException('Symfony\Component\Intl\Exception\MethodArgumentValueNotImplementedException');
parent::testFormatTypeInt64($formatter, $value, $expected);
}
/**
* @dataProvider formatTypeInt64WithCurrencyStyleProvider
*/
public function testFormatTypeInt64WithCurrencyStyle($formatter, $value, $expected)
{
$this->expectException('Symfony\Component\Intl\Exception\NotImplementedException');
parent::testFormatTypeInt64WithCurrencyStyle($formatter, $value, $expected);
}
/**
* @dataProvider formatTypeDoubleProvider
*/
public function testFormatTypeDouble($formatter, $value, $expected)
{
$this->expectException('Symfony\Component\Intl\Exception\MethodArgumentValueNotImplementedException');
parent::testFormatTypeDouble($formatter, $value, $expected);
}
/**
* @dataProvider formatTypeDoubleWithCurrencyStyleProvider
*/
public function testFormatTypeDoubleWithCurrencyStyle($formatter, $value, $expected)
{
$this->expectException('Symfony\Component\Intl\Exception\NotImplementedException');
parent::testFormatTypeDoubleWithCurrencyStyle($formatter, $value, $expected);
}
public function testGetPattern()
{
$this->expectException('Symfony\Component\Intl\Exception\MethodNotImplementedException');
$formatter = $this->getNumberFormatter('en', NumberFormatter::DECIMAL);
$formatter->getPattern();
}
public function testGetErrorCode()
{
$formatter = $this->getNumberFormatter('en', NumberFormatter::DECIMAL);
$this->assertEquals(IntlGlobals::U_ZERO_ERROR, $formatter->getErrorCode());
}
public function testParseCurrency()
{
$this->expectException('Symfony\Component\Intl\Exception\MethodNotImplementedException');
$formatter = $this->getNumberFormatter('en', NumberFormatter::DECIMAL);
$formatter->parseCurrency(null, $currency);
}
public function testSetPattern()
{
$this->expectException('Symfony\Component\Intl\Exception\MethodNotImplementedException');
$formatter = $this->getNumberFormatter('en', NumberFormatter::DECIMAL);
$formatter->setPattern(null);
}
public function testSetSymbol()
{
$this->expectException('Symfony\Component\Intl\Exception\MethodNotImplementedException');
$formatter = $this->getNumberFormatter('en', NumberFormatter::DECIMAL);
$formatter->setSymbol(null, null);
}
public function testSetTextAttribute()
{
$this->expectException('Symfony\Component\Intl\Exception\MethodNotImplementedException');
$formatter = $this->getNumberFormatter('en', NumberFormatter::DECIMAL);
$formatter->setTextAttribute(null, null);
}
protected function getNumberFormatter($locale = 'en', $style = null, $pattern = null)
{
return new NumberFormatter($locale, $style, $pattern);
}
protected function getIntlErrorMessage()
{
return IntlGlobals::getErrorMessage();
}
protected function getIntlErrorCode()
{
return IntlGlobals::getErrorCode();
}
protected function isIntlFailure($errorCode)
{
return IntlGlobals::isFailure($errorCode);
}
}

View File

@@ -0,0 +1,61 @@
<?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\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
* behavior of PHP.
*/
class NumberFormatterTest extends AbstractNumberFormatterTest
{
protected function setUp()
{
IntlTestHelper::requireFullIntl($this, '55.1');
parent::setUp();
}
public function testCreate()
{
$this->assertInstanceOf('\NumberFormatter', \NumberFormatter::create('en', \NumberFormatter::DECIMAL));
}
public function testGetTextAttribute()
{
IntlTestHelper::requireFullIntl($this, '57.1');
parent::testGetTextAttribute();
}
protected function getNumberFormatter($locale = 'en', $style = null, $pattern = null)
{
return new \NumberFormatter($locale, $style, $pattern);
}
protected function getIntlErrorMessage()
{
return intl_get_error_message();
}
protected function getIntlErrorCode()
{
return intl_get_error_code();
}
protected function isIntlFailure($errorCode)
{
return intl_is_failure($errorCode);
}
}

View File

@@ -0,0 +1,74 @@
<?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\Util;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Intl\Exception\RuntimeException;
use Symfony\Component\Intl\Util\GitRepository;
/**
* @group intl-data
*/
class GitRepositoryTest extends TestCase
{
private $targetDir;
const REPO_URL = 'https://github.com/symfony/intl.git';
/**
* @before
* @after
*/
protected function cleanup()
{
$this->targetDir = sys_get_temp_dir().'/GitRepositoryTest/source';
$fs = new Filesystem();
$fs->remove($this->targetDir);
}
public function testItThrowsAnExceptionIfInitialisedWithNonGitDirectory()
{
$this->expectException(RuntimeException::class);
@mkdir($this->targetDir, 0777, true);
new GitRepository($this->targetDir);
}
public function testItClonesTheRepository()
{
$git = GitRepository::download(self::REPO_URL, $this->targetDir);
$this->assertInstanceOf(GitRepository::class, $git);
$this->assertDirectoryExists($this->targetDir.'/.git');
$this->assertSame($this->targetDir, $git->getPath());
$this->assertSame(self::REPO_URL, $git->getUrl());
$this->assertMatchesRegularExpression('#^[0-9a-z]{40}$#', $git->getLastCommitHash());
$this->assertNotEmpty($git->getLastAuthor());
$this->assertInstanceOf('DateTime', $git->getLastAuthoredDate());
$this->assertStringMatchesFormat('v%s', $git->getLastTag());
$this->assertStringMatchesFormat('v3%s', $git->getLastTag(function ($tag) { return 0 === strpos($tag, 'v3'); }));
}
public function testItCheckoutsToTheLastTag()
{
$git = GitRepository::download(self::REPO_URL, $this->targetDir);
$lastCommitHash = $git->getLastCommitHash();
$lastV3Tag = $git->getLastTag(function ($tag) { return 0 === strpos($tag, 'v3'); });
$git->checkout($lastV3Tag);
$this->assertNotEquals($lastCommitHash, $git->getLastCommitHash());
}
}

View File

@@ -0,0 +1,112 @@
<?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\Util;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Intl\Util\IcuVersion;
/**
* @author Bernhard Schussek <bschussek@gmail.com>
*/
class IcuVersionTest extends TestCase
{
public function normalizeProvider()
{
return [
[null, '1', '10'],
[null, '1.2', '12'],
[null, '1.2.3', '12.3'],
[null, '1.2.3.4', '12.3.4'],
[1, '1', '10'],
[1, '1.2', '12'],
[1, '1.2.3', '12'],
[1, '1.2.3.4', '12'],
[2, '1', '10'],
[2, '1.2', '12'],
[2, '1.2.3', '12.3'],
[2, '1.2.3.4', '12.3'],
[3, '1', '10'],
[3, '1.2', '12'],
[3, '1.2.3', '12.3'],
[3, '1.2.3.4', '12.3.4'],
];
}
/**
* @dataProvider normalizeProvider
*/
public function testNormalize($precision, $version, $result)
{
$this->assertSame($result, IcuVersion::normalize($version, $precision));
}
public function compareProvider()
{
return [
[null, '1', '==', '1', true],
[null, '1.0', '==', '1.1', false],
[null, '1.0.0', '==', '1.0.1', false],
[null, '1.0.0.0', '==', '1.0.0.1', false],
[null, '1.0.0.0.0', '==', '1.0.0.0.1', false],
[null, '1', '==', '10', true],
[null, '1.0', '==', '11', false],
[null, '1.0.0', '==', '10.1', false],
[null, '1.0.0.0', '==', '10.0.1', false],
[null, '1.0.0.0.0', '==', '10.0.0.1', false],
[1, '1', '==', '1', true],
[1, '1.0', '==', '1.1', false],
[1, '1.0.0', '==', '1.0.1', true],
[1, '1.0.0.0', '==', '1.0.0.1', true],
[1, '1.0.0.0.0', '==', '1.0.0.0.1', true],
[1, '1', '==', '10', true],
[1, '1.0', '==', '11', false],
[1, '1.0.0', '==', '10.1', true],
[1, '1.0.0.0', '==', '10.0.1', true],
[1, '1.0.0.0.0', '==', '10.0.0.1', true],
[2, '1', '==', '1', true],
[2, '1.0', '==', '1.1', false],
[2, '1.0.0', '==', '1.0.1', false],
[2, '1.0.0.0', '==', '1.0.0.1', true],
[2, '1.0.0.0.0', '==', '1.0.0.0.1', true],
[2, '1', '==', '10', true],
[2, '1.0', '==', '11', false],
[2, '1.0.0', '==', '10.1', false],
[2, '1.0.0.0', '==', '10.0.1', true],
[2, '1.0.0.0.0', '==', '10.0.0.1', true],
[3, '1', '==', '1', true],
[3, '1.0', '==', '1.1', false],
[3, '1.0.0', '==', '1.0.1', false],
[3, '1.0.0.0', '==', '1.0.0.1', false],
[3, '1.0.0.0.0', '==', '1.0.0.0.1', true],
[3, '1', '==', '10', true],
[3, '1.0', '==', '11', false],
[3, '1.0.0', '==', '10.1', false],
[3, '1.0.0.0', '==', '10.0.1', false],
[3, '1.0.0.0.0', '==', '10.0.0.1', true],
];
}
/**
* @dataProvider compareProvider
*/
public function testCompare($precision, $version1, $operator, $version2, $result)
{
$this->assertSame($result, IcuVersion::compare($version1, $version2, $operator, $precision));
}
}

View File

@@ -0,0 +1,88 @@
<?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\Util;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Intl\Util\Version;
/**
* @author Bernhard Schussek <bschussek@gmail.com>
*/
class VersionTest extends TestCase
{
public function normalizeProvider()
{
return [
[null, '1', '1'],
[null, '1.2', '1.2'],
[null, '1.2.3', '1.2.3'],
[null, '1.2.3.4', '1.2.3.4'],
[1, '1', '1'],
[1, '1.2', '1'],
[1, '1.2.3', '1'],
[1, '1.2.3.4', '1'],
[2, '1', '1'],
[2, '1.2', '1.2'],
[2, '1.2.3', '1.2'],
[2, '1.2.3.4', '1.2'],
[3, '1', '1'],
[3, '1.2', '1.2'],
[3, '1.2.3', '1.2.3'],
[3, '1.2.3.4', '1.2.3'],
[4, '1', '1'],
[4, '1.2', '1.2'],
[4, '1.2.3', '1.2.3'],
[4, '1.2.3.4', '1.2.3.4'],
];
}
/**
* @dataProvider normalizeProvider
*/
public function testNormalize($precision, $version, $result)
{
$this->assertSame($result, Version::normalize($version, $precision));
}
public function compareProvider()
{
return [
[null, '1', '==', '1', true],
[null, '1.0', '==', '1.1', false],
[null, '1.0.0', '==', '1.0.1', false],
[null, '1.0.0.0', '==', '1.0.0.1', false],
[1, '1', '==', '1', true],
[1, '1.0', '==', '1.1', true],
[1, '1.0.0', '==', '1.0.1', true],
[1, '1.0.0.0', '==', '1.0.0.1', true],
[2, '1', '==', '1', true],
[2, '1.0', '==', '1.1', false],
[2, '1.0.0', '==', '1.0.1', true],
[2, '1.0.0.0', '==', '1.0.0.1', true],
[3, '1', '==', '1', true],
[3, '1.0', '==', '1.1', false],
[3, '1.0.0', '==', '1.0.1', false],
[3, '1.0.0.0', '==', '1.0.0.1', true],
];
}
/**
* @dataProvider compareProvider
*/
public function testCompare($precision, $version1, $operator, $version2, $result)
{
$this->assertSame($result, Version::compare($version1, $version2, $operator, $precision));
}
}