Merge branch '2.3' into 2.7

* 2.3:
  Fix security-acl deps
  Fix doctrine mapping validation type error
  Remove skipping of tests based on ICU data version whenever possible
  Fix the handling of null as locale in the stub intl classes
  do not dump leading backslashes in class names
  Skip ::class constant
  [Config] type specific check for emptiness

Conflicts:
	src/Symfony/Bridge/Twig/composer.json
	src/Symfony/Bundle/SecurityBundle/composer.json
	src/Symfony/Component/Config/Tests/Definition/ScalarNodeTest.php
	src/Symfony/Component/DependencyInjection/Dumper/GraphvizDumper.php
	src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php
	src/Symfony/Component/DependencyInjection/Tests/Fixtures/containers/container9.php
	src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/IntegerToLocalizedStringTransformerTest.php
	src/Symfony/Component/Form/Tests/Extension/Core/Type/DateTimeTypeTest.php
	src/Symfony/Component/Form/Tests/Extension/Core/Type/DateTypeTest.php
	src/Symfony/Component/Locale/Tests/LocaleTest.php
	src/Symfony/Component/Locale/Tests/Stub/StubLocaleTest.php
	src/Symfony/Component/Validator/Tests/Constraints/CountryValidatorTest.php
	src/Symfony/Component/Validator/Tests/Constraints/CurrencyValidatorTest.php
This commit is contained in:
Nicolas Grekas 2015-08-01 11:05:17 +02:00
commit 3d7d378cbc
43 changed files with 438 additions and 137 deletions

View File

@ -252,7 +252,7 @@ abstract class AbstractDoctrineExtension extends Extension
throw new \InvalidArgumentException(sprintf('Can only configure "xml", "yml", "annotation", "php" or '. throw new \InvalidArgumentException(sprintf('Can only configure "xml", "yml", "annotation", "php" or '.
'"staticphp" through the DoctrineBundle. Use your own bundle to configure other metadata drivers. '. '"staticphp" through the DoctrineBundle. Use your own bundle to configure other metadata drivers. '.
'You can register them by adding a new driver to the '. 'You can register them by adding a new driver to the '.
'"%s" service definition.', $this->getObjectManagerElementName($objectManagerName.'.metadata_driver') '"%s" service definition.', $this->getObjectManagerElementName($objectManagerName.'_metadata_driver')
)); ));
} }
} }

View File

@ -31,6 +31,7 @@
"symfony/translation": "~2.7", "symfony/translation": "~2.7",
"symfony/yaml": "~2.0,>=2.0.5", "symfony/yaml": "~2.0,>=2.0.5",
"symfony/security": "~2.6", "symfony/security": "~2.6",
"symfony/security-acl": "~2.6",
"symfony/stopwatch": "~2.2", "symfony/stopwatch": "~2.2",
"symfony/console": "~2.7", "symfony/console": "~2.7",
"symfony/var-dumper": "~2.6", "symfony/var-dumper": "~2.6",

View File

@ -18,6 +18,7 @@
"require": { "require": {
"php": ">=5.3.9", "php": ">=5.3.9",
"symfony/security": "~2.7", "symfony/security": "~2.7",
"symfony/security-acl": "~2.7",
"symfony/http-kernel": "~2.2" "symfony/http-kernel": "~2.2"
}, },
"require-dev": { "require-dev": {

View File

@ -118,6 +118,25 @@ class ClassMapGenerator
case T_CLASS: case T_CLASS:
case T_INTERFACE: case T_INTERFACE:
case SYMFONY_TRAIT: case SYMFONY_TRAIT:
// Skip usage of ::class constant
$isClassConstant = false;
for ($j = $i - 1; $j > 0; --$j) {
if (is_string($tokens[$j])) {
break;
}
if (T_DOUBLE_COLON === $tokens[$j][0]) {
$isClassConstant = true;
break;
} elseif (!in_array($tokens[$j][0], array(T_WHITESPACE, T_DOC_COMMENT, T_COMMENT))) {
break;
}
}
if ($isClassConstant) {
continue;
}
// Find the classname // Find the classname
while (($t = $tokens[++$i]) && is_array($t)) { while (($t = $tokens[++$i]) && is_array($t)) {
if (T_STRING === $t[0]) { if (T_STRING === $t[0]) {

View File

@ -47,7 +47,7 @@ class ClassMapGeneratorTest extends \PHPUnit_Framework_TestCase
/** /**
* @dataProvider getTestCreateMapTests * @dataProvider getTestCreateMapTests
*/ */
public function testDump($directory, $expected) public function testDump($directory)
{ {
$this->prepare_workspace(); $this->prepare_workspace();
@ -115,6 +115,12 @@ class ClassMapGeneratorTest extends \PHPUnit_Framework_TestCase
)); ));
} }
if (PHP_VERSION_ID >= 50500) {
$data[] = array(__DIR__.'/Fixtures/php5.5', array(
'ClassCons\\Foo' => __DIR__.'/Fixtures/php5.5/class_cons.php',
));
}
return $data; return $data;
} }

View File

@ -0,0 +1,11 @@
<?php
namespace ClassCons;
class Foo
{
public function __construct()
{
\Foo\TBar/* foo */::class;
}
}

View File

@ -39,4 +39,13 @@ class BooleanNode extends ScalarNode
throw $ex; throw $ex;
} }
} }
/**
* {@inheritdoc}
*/
protected function isValueEmpty($value)
{
// a boolean value cannot be empty
return false;
}
} }

View File

@ -52,4 +52,13 @@ class NumericNode extends ScalarNode
return $value; return $value;
} }
/**
* {@inheritdoc}
*/
protected function isValueEmpty($value)
{
// a numeric value cannot be empty
return false;
}
} }

View File

@ -46,4 +46,12 @@ class ScalarNode extends VariableNode
throw $ex; throw $ex;
} }
} }
/**
* {@inheritdoc}
*/
protected function isValueEmpty($value)
{
return null === $value || '' === $value;
}
} }

View File

@ -84,7 +84,7 @@ class VariableNode extends BaseNode implements PrototypeNodeInterface
*/ */
protected function finalizeValue($value) protected function finalizeValue($value)
{ {
if (!$this->allowEmptyValue && empty($value)) { if (!$this->allowEmptyValue && $this->isValueEmpty($value)) {
$ex = new InvalidConfigurationException(sprintf( $ex = new InvalidConfigurationException(sprintf(
'The path "%s" cannot contain an empty value, but got %s.', 'The path "%s" cannot contain an empty value, but got %s.',
$this->getPath(), $this->getPath(),
@ -116,4 +116,20 @@ class VariableNode extends BaseNode implements PrototypeNodeInterface
{ {
return $rightSide; return $rightSide;
} }
/**
* Evaluates if the given value is to be treated as empty.
*
* By default, PHP's empty() function is used to test for emptiness. This
* method may be overridden by subtypes to better match their understanding
* of empty data.
*
* @param mixed $value
*
* @return bool
*/
protected function isValueEmpty($value)
{
return empty($value);
}
} }

View File

@ -24,6 +24,19 @@ class BooleanNodeTest extends \PHPUnit_Framework_TestCase
$this->assertSame($value, $node->normalize($value)); $this->assertSame($value, $node->normalize($value));
} }
/**
* @dataProvider getValidValues
*
* @param bool $value
*/
public function testValidNonEmptyValues($value)
{
$node = new BooleanNode('test');
$node->setAllowEmptyValue(false);
$this->assertSame($value, $node->finalize($value));
}
public function getValidValues() public function getValidValues()
{ {
return array( return array(

View File

@ -24,6 +24,19 @@ class FloatNodeTest extends \PHPUnit_Framework_TestCase
$this->assertSame($value, $node->normalize($value)); $this->assertSame($value, $node->normalize($value));
} }
/**
* @dataProvider getValidValues
*
* @param int $value
*/
public function testValidNonEmptyValues($value)
{
$node = new FloatNode('test');
$node->setAllowEmptyValue(false);
$this->assertSame($value, $node->finalize($value));
}
public function getValidValues() public function getValidValues()
{ {
return array( return array(

View File

@ -24,6 +24,19 @@ class IntegerNodeTest extends \PHPUnit_Framework_TestCase
$this->assertSame($value, $node->normalize($value)); $this->assertSame($value, $node->normalize($value));
} }
/**
* @dataProvider getValidValues
*
* @param int $value
*/
public function testValidNonEmptyValues($value)
{
$node = new IntegerNode('test');
$node->setAllowEmptyValue(false);
$this->assertSame($value, $node->finalize($value));
}
public function getValidValues() public function getValidValues()
{ {
return array( return array(

View File

@ -76,4 +76,51 @@ class ScalarNodeTest extends \PHPUnit_Framework_TestCase
$node->normalize(array()); $node->normalize(array());
} }
/**
* @dataProvider getValidNonEmptyValues
*
* @param mixed $value
*/
public function testValidNonEmptyValues($value)
{
$node = new ScalarNode('test');
$node->setAllowEmptyValue(false);
$this->assertSame($value, $node->finalize($value));
}
public function getValidNonEmptyValues()
{
return array(
array(false),
array(true),
array('foo'),
array(0),
array(1),
array(0.0),
array(0.1),
);
}
/**
* @dataProvider getEmptyValues
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
*
* @param mixed $value
*/
public function testNotAllowedEmptyValuesThrowException($value)
{
$node = new ScalarNode('test');
$node->setAllowEmptyValue(false);
$node->finalize($value);
}
public function getEmptyValues()
{
return array(
array(null),
array(''),
);
}
} }

View File

@ -166,14 +166,18 @@ class GraphvizDumper extends Dumper
$container = $this->cloneContainer(); $container = $this->cloneContainer();
foreach ($container->getDefinitions() as $id => $definition) { foreach ($container->getDefinitions() as $id => $definition) {
$className = $definition->getClass(); $class = $definition->getClass();
if ('\\' === substr($class, 0, 1)) {
$class = substr($class, 1);
}
try { try {
$className = $this->container->getParameterBag()->resolveValue($className); $class = $this->container->getParameterBag()->resolveValue($class);
} catch (ParameterNotFoundException $e) { } catch (ParameterNotFoundException $e) {
} }
$nodes[$id] = array('class' => str_replace('\\', '\\\\', $className), 'attributes' => array_merge($this->options['node.definition'], array('style' => ContainerInterface::SCOPE_PROTOTYPE !== $definition->getScope() ? 'filled' : 'dotted'))); $nodes[$id] = array('class' => str_replace('\\', '\\\\', $class), 'attributes' => array_merge($this->options['node.definition'], array('style' => ContainerInterface::SCOPE_PROTOTYPE !== $definition->getScope() ? 'filled' : 'dotted')));
$container->setDefinition($id, new Definition('stdClass')); $container->setDefinition($id, new Definition('stdClass'));
} }

View File

@ -372,7 +372,13 @@ class PhpDumper extends Dumper
*/ */
private function addServiceInstance($id, $definition) private function addServiceInstance($id, $definition)
{ {
$class = $this->dumpValue($definition->getClass()); $class = $definition->getClass();
if ('\\' === substr($class, 0, 1)) {
$class = substr($class, 1);
}
$class = $this->dumpValue($class);
if (0 === strpos($class, "'") && !preg_match('/^\'[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*(\\\{2}[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)*\'$/', $class)) { if (0 === strpos($class, "'") && !preg_match('/^\'[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*(\\\{2}[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)*\'$/', $class)) {
throw new InvalidArgumentException(sprintf('"%s" is not a valid class name for the "%s" service.', $class, $id)); throw new InvalidArgumentException(sprintf('"%s" is not a valid class name for the "%s" service.', $class, $id));
@ -560,7 +566,7 @@ class PhpDumper extends Dumper
if ($definition->isSynthetic()) { if ($definition->isSynthetic()) {
$return[] = '@throws RuntimeException always since this service is expected to be injected dynamically'; $return[] = '@throws RuntimeException always since this service is expected to be injected dynamically';
} elseif ($class = $definition->getClass()) { } elseif ($class = $definition->getClass()) {
$return[] = sprintf('@return %s A %s instance.', 0 === strpos($class, '%') ? 'object' : '\\'.$class, $class); $return[] = sprintf('@return %s A %s instance.', 0 === strpos($class, '%') ? 'object' : '\\'.ltrim($class, '\\'), ltrim($class, '\\'));
} elseif ($definition->getFactory()) { } elseif ($definition->getFactory()) {
$factory = $definition->getFactory(); $factory = $definition->getFactory();
if (is_string($factory)) { if (is_string($factory)) {

View File

@ -114,8 +114,12 @@ class XmlDumper extends Dumper
if (null !== $id) { if (null !== $id) {
$service->setAttribute('id', $id); $service->setAttribute('id', $id);
} }
if ($definition->getClass()) { if ($class = $definition->getClass()) {
$service->setAttribute('class', $definition->getClass()); if ('\\' === substr($class, 0, 1)) {
$class = substr($class, 1);
}
$service->setAttribute('class', $class);
} }
if ($definition->getFactoryMethod(false)) { if ($definition->getFactoryMethod(false)) {
$service->setAttribute('factory-method', $definition->getFactoryMethod(false)); $service->setAttribute('factory-method', $definition->getFactoryMethod(false));

View File

@ -64,8 +64,12 @@ class YamlDumper extends Dumper
private function addService($id, $definition) private function addService($id, $definition)
{ {
$code = " $id:\n"; $code = " $id:\n";
if ($definition->getClass()) { if ($class = $definition->getClass()) {
$code .= sprintf(" class: %s\n", $definition->getClass()); if ('\\' === substr($class, 0, 1)) {
$class = substr($class, 1);
}
$code .= sprintf(" class: %s\n", $class);
} }
if (!$definition->isPublic()) { if (!$definition->isPublic()) {

View File

@ -10,7 +10,7 @@ use Symfony\Component\ExpressionLanguage\Expression;
$container = new ContainerBuilder(); $container = new ContainerBuilder();
$container $container
->register('foo', 'Bar\FooClass') ->register('foo', '\Bar\FooClass')
->addTag('foo', array('foo' => 'foo')) ->addTag('foo', array('foo' => 'foo'))
->addTag('foo', array('bar' => 'bar', 'baz' => 'baz')) ->addTag('foo', array('bar' => 'bar', 'baz' => 'baz'))
->setFactory(array('Bar\\FooClass', 'getInstance')) ->setFactory(array('Bar\\FooClass', 'getInstance'))

View File

@ -170,9 +170,11 @@ class DateTimeToLocalizedStringTransformerTest extends DateTimeTestCase
{ {
$transformer = new DateTimeToLocalizedStringTransformer(); $transformer = new DateTimeToLocalizedStringTransformer();
$this->markTestIncomplete('Checking for intl errors needs to be reimplemented');
// HOW TO REPRODUCE? // HOW TO REPRODUCE?
//$this->setExpectedException('Symfony\Component\Form\Extension\Core\DataTransformer\Transdate_formationFailedException'); //$this->setExpectedException('Symfony\Component\Form\Extension\Core\DataTransformer\TransformationFailedException');
//$transformer->transform(1.5); //$transformer->transform(1.5);
} }

View File

@ -20,10 +20,7 @@ class IntegerToLocalizedStringTransformerTest extends \PHPUnit_Framework_TestCas
{ {
parent::setUp(); parent::setUp();
// Since we test against "de_AT", we need the full implementation \Locale::setDefault('en');
IntlTestHelper::requireFullIntl($this);
\Locale::setDefault('de_AT');
} }
public function transformWithRoundingProvider() public function transformWithRoundingProvider()
@ -89,6 +86,11 @@ class IntegerToLocalizedStringTransformerTest extends \PHPUnit_Framework_TestCas
public function testReverseTransform() public function testReverseTransform()
{ {
// Since we test against "de_AT", we need the full implementation
IntlTestHelper::requireFullIntl($this);
\Locale::setDefault('de_AT');
$transformer = new IntegerToLocalizedStringTransformer(); $transformer = new IntegerToLocalizedStringTransformer();
$this->assertEquals(1, $transformer->reverseTransform('1')); $this->assertEquals(1, $transformer->reverseTransform('1'));
@ -106,6 +108,11 @@ class IntegerToLocalizedStringTransformerTest extends \PHPUnit_Framework_TestCas
public function testReverseTransformWithGrouping() public function testReverseTransformWithGrouping()
{ {
// Since we test against "de_AT", we need the full implementation
IntlTestHelper::requireFullIntl($this);
\Locale::setDefault('de_AT');
$transformer = new IntegerToLocalizedStringTransformer(null, true); $transformer = new IntegerToLocalizedStringTransformer(null, true);
$this->assertEquals(1234, $transformer->reverseTransform('1.234,5')); $this->assertEquals(1234, $transformer->reverseTransform('1.234,5'));

View File

@ -16,18 +16,13 @@ use Symfony\Component\Intl\Util\IntlTestHelper;
class MoneyToLocalizedStringTransformerTest extends \PHPUnit_Framework_TestCase class MoneyToLocalizedStringTransformerTest extends \PHPUnit_Framework_TestCase
{ {
protected function setUp() public function testTransform()
{ {
parent::setUp();
// Since we test against "de_AT", we need the full implementation // Since we test against "de_AT", we need the full implementation
IntlTestHelper::requireFullIntl($this); IntlTestHelper::requireFullIntl($this);
\Locale::setDefault('de_AT'); \Locale::setDefault('de_AT');
}
public function testTransform()
{
$transformer = new MoneyToLocalizedStringTransformer(null, null, null, 100); $transformer = new MoneyToLocalizedStringTransformer(null, null, null, 100);
$this->assertEquals('1,23', $transformer->transform(123)); $this->assertEquals('1,23', $transformer->transform(123));
@ -51,6 +46,11 @@ class MoneyToLocalizedStringTransformerTest extends \PHPUnit_Framework_TestCase
public function testReverseTransform() public function testReverseTransform()
{ {
// Since we test against "de_AT", we need the full implementation
IntlTestHelper::requireFullIntl($this);
\Locale::setDefault('de_AT');
$transformer = new MoneyToLocalizedStringTransformer(null, null, null, 100); $transformer = new MoneyToLocalizedStringTransformer(null, null, null, 100);
$this->assertEquals(123, $transformer->reverseTransform('1,23')); $this->assertEquals(123, $transformer->reverseTransform('1,23'));

View File

@ -20,10 +20,7 @@ class NumberToLocalizedStringTransformerTest extends \PHPUnit_Framework_TestCase
{ {
parent::setUp(); parent::setUp();
// Since we test against "de_AT", we need the full implementation \Locale::setDefault('en');
IntlTestHelper::requireFullIntl($this);
\Locale::setDefault('de_AT');
} }
public function provideTransformations() public function provideTransformations()
@ -44,6 +41,9 @@ class NumberToLocalizedStringTransformerTest extends \PHPUnit_Framework_TestCase
*/ */
public function testTransform($from, $to, $locale) public function testTransform($from, $to, $locale)
{ {
// Since we test against other locales, we need the full implementation
IntlTestHelper::requireFullIntl($this);
\Locale::setDefault($locale); \Locale::setDefault($locale);
$transformer = new NumberToLocalizedStringTransformer(); $transformer = new NumberToLocalizedStringTransformer();
@ -67,6 +67,9 @@ class NumberToLocalizedStringTransformerTest extends \PHPUnit_Framework_TestCase
*/ */
public function testTransformWithGrouping($from, $to, $locale) public function testTransformWithGrouping($from, $to, $locale)
{ {
// Since we test against other locales, we need the full implementation
IntlTestHelper::requireFullIntl($this);
\Locale::setDefault($locale); \Locale::setDefault($locale);
$transformer = new NumberToLocalizedStringTransformer(null, true); $transformer = new NumberToLocalizedStringTransformer(null, true);
@ -76,6 +79,11 @@ class NumberToLocalizedStringTransformerTest extends \PHPUnit_Framework_TestCase
public function testTransformWithScale() public function testTransformWithScale()
{ {
// Since we test against "de_AT", we need the full implementation
IntlTestHelper::requireFullIntl($this);
\Locale::setDefault('de_AT');
$transformer = new NumberToLocalizedStringTransformer(2); $transformer = new NumberToLocalizedStringTransformer(2);
$this->assertEquals('1234,50', $transformer->transform(1234.5)); $this->assertEquals('1234,50', $transformer->transform(1234.5));
@ -84,6 +92,11 @@ class NumberToLocalizedStringTransformerTest extends \PHPUnit_Framework_TestCase
public function transformWithRoundingProvider() public function transformWithRoundingProvider()
{ {
// Since we test against "de_AT", we need the full implementation
IntlTestHelper::requireFullIntl($this);
\Locale::setDefault('de_AT');
return array( return array(
// towards positive infinity (1.6 -> 2, -1.6 -> -1) // towards positive infinity (1.6 -> 2, -1.6 -> -1)
array(0, 1234.5, '1235', NumberToLocalizedStringTransformer::ROUND_CEILING), array(0, 1234.5, '1235', NumberToLocalizedStringTransformer::ROUND_CEILING),
@ -183,6 +196,11 @@ class NumberToLocalizedStringTransformerTest extends \PHPUnit_Framework_TestCase
public function testTransformDoesNotRoundIfNoScale() public function testTransformDoesNotRoundIfNoScale()
{ {
// Since we test against "de_AT", we need the full implementation
IntlTestHelper::requireFullIntl($this);
\Locale::setDefault('de_AT');
$transformer = new NumberToLocalizedStringTransformer(null, null, NumberToLocalizedStringTransformer::ROUND_DOWN); $transformer = new NumberToLocalizedStringTransformer(null, null, NumberToLocalizedStringTransformer::ROUND_DOWN);
$this->assertEquals('1234,547', $transformer->transform(1234.547)); $this->assertEquals('1234,547', $transformer->transform(1234.547));
@ -193,6 +211,9 @@ class NumberToLocalizedStringTransformerTest extends \PHPUnit_Framework_TestCase
*/ */
public function testReverseTransform($to, $from, $locale) public function testReverseTransform($to, $from, $locale)
{ {
// Since we test against other locales, we need the full implementation
IntlTestHelper::requireFullIntl($this);
\Locale::setDefault($locale); \Locale::setDefault($locale);
$transformer = new NumberToLocalizedStringTransformer(); $transformer = new NumberToLocalizedStringTransformer();
@ -205,6 +226,9 @@ class NumberToLocalizedStringTransformerTest extends \PHPUnit_Framework_TestCase
*/ */
public function testReverseTransformWithGrouping($to, $from, $locale) public function testReverseTransformWithGrouping($to, $from, $locale)
{ {
// Since we test against other locales, we need the full implementation
IntlTestHelper::requireFullIntl($this);
\Locale::setDefault($locale); \Locale::setDefault($locale);
$transformer = new NumberToLocalizedStringTransformer(null, true); $transformer = new NumberToLocalizedStringTransformer(null, true);
@ -219,6 +243,9 @@ class NumberToLocalizedStringTransformerTest extends \PHPUnit_Framework_TestCase
$this->markTestSkipped('The "mbstring" extension is required for this test.'); $this->markTestSkipped('The "mbstring" extension is required for this test.');
} }
// Since we test against other locales, we need the full implementation
IntlTestHelper::requireFullIntl($this);
\Locale::setDefault('ru'); \Locale::setDefault('ru');
$transformer = new NumberToLocalizedStringTransformer(null, true); $transformer = new NumberToLocalizedStringTransformer(null, true);
@ -228,6 +255,11 @@ class NumberToLocalizedStringTransformerTest extends \PHPUnit_Framework_TestCase
public function testReverseTransformWithGroupingButWithoutGroupSeparator() public function testReverseTransformWithGroupingButWithoutGroupSeparator()
{ {
// Since we test against "de_AT", we need the full implementation
IntlTestHelper::requireFullIntl($this);
\Locale::setDefault('de_AT');
$transformer = new NumberToLocalizedStringTransformer(null, true); $transformer = new NumberToLocalizedStringTransformer(null, true);
// omit group separator // omit group separator
@ -343,6 +375,9 @@ class NumberToLocalizedStringTransformerTest extends \PHPUnit_Framework_TestCase
public function testDecimalSeparatorMayBeDotIfGroupingSeparatorIsNotDot() public function testDecimalSeparatorMayBeDotIfGroupingSeparatorIsNotDot()
{ {
// Since we test against other locales, we need the full implementation
IntlTestHelper::requireFullIntl($this);
\Locale::setDefault('fr'); \Locale::setDefault('fr');
$transformer = new NumberToLocalizedStringTransformer(null, true); $transformer = new NumberToLocalizedStringTransformer(null, true);
@ -360,6 +395,11 @@ class NumberToLocalizedStringTransformerTest extends \PHPUnit_Framework_TestCase
*/ */
public function testDecimalSeparatorMayNotBeDotIfGroupingSeparatorIsDot() public function testDecimalSeparatorMayNotBeDotIfGroupingSeparatorIsDot()
{ {
// Since we test against "de_AT", we need the full implementation
IntlTestHelper::requireFullIntl($this);
\Locale::setDefault('de_AT');
$transformer = new NumberToLocalizedStringTransformer(null, true); $transformer = new NumberToLocalizedStringTransformer(null, true);
$transformer->reverseTransform('1.234.5'); $transformer->reverseTransform('1.234.5');
@ -370,6 +410,11 @@ class NumberToLocalizedStringTransformerTest extends \PHPUnit_Framework_TestCase
*/ */
public function testDecimalSeparatorMayNotBeDotIfGroupingSeparatorIsDotWithNoGroupSep() public function testDecimalSeparatorMayNotBeDotIfGroupingSeparatorIsDotWithNoGroupSep()
{ {
// Since we test against "de_AT", we need the full implementation
IntlTestHelper::requireFullIntl($this);
\Locale::setDefault('de_AT');
$transformer = new NumberToLocalizedStringTransformer(null, true); $transformer = new NumberToLocalizedStringTransformer(null, true);
$transformer->reverseTransform('1234.5'); $transformer->reverseTransform('1234.5');
@ -377,6 +422,9 @@ class NumberToLocalizedStringTransformerTest extends \PHPUnit_Framework_TestCase
public function testDecimalSeparatorMayBeDotIfGroupingSeparatorIsDotButNoGroupingUsed() public function testDecimalSeparatorMayBeDotIfGroupingSeparatorIsDotButNoGroupingUsed()
{ {
// Since we test against other locales, we need the full implementation
IntlTestHelper::requireFullIntl($this);
\Locale::setDefault('fr'); \Locale::setDefault('fr');
$transformer = new NumberToLocalizedStringTransformer(); $transformer = new NumberToLocalizedStringTransformer();
@ -386,6 +434,9 @@ class NumberToLocalizedStringTransformerTest extends \PHPUnit_Framework_TestCase
public function testDecimalSeparatorMayBeCommaIfGroupingSeparatorIsNotComma() public function testDecimalSeparatorMayBeCommaIfGroupingSeparatorIsNotComma()
{ {
// Since we test against other locales, we need the full implementation
IntlTestHelper::requireFullIntl($this);
\Locale::setDefault('bg'); \Locale::setDefault('bg');
$transformer = new NumberToLocalizedStringTransformer(null, true); $transformer = new NumberToLocalizedStringTransformer(null, true);
@ -403,7 +454,6 @@ class NumberToLocalizedStringTransformerTest extends \PHPUnit_Framework_TestCase
*/ */
public function testDecimalSeparatorMayNotBeCommaIfGroupingSeparatorIsComma() public function testDecimalSeparatorMayNotBeCommaIfGroupingSeparatorIsComma()
{ {
\Locale::setDefault('en');
$transformer = new NumberToLocalizedStringTransformer(null, true); $transformer = new NumberToLocalizedStringTransformer(null, true);
$transformer->reverseTransform('1,234,5'); $transformer->reverseTransform('1,234,5');
@ -414,7 +464,6 @@ class NumberToLocalizedStringTransformerTest extends \PHPUnit_Framework_TestCase
*/ */
public function testDecimalSeparatorMayNotBeCommaIfGroupingSeparatorIsCommaWithNoGroupSep() public function testDecimalSeparatorMayNotBeCommaIfGroupingSeparatorIsCommaWithNoGroupSep()
{ {
\Locale::setDefault('en');
$transformer = new NumberToLocalizedStringTransformer(null, true); $transformer = new NumberToLocalizedStringTransformer(null, true);
$transformer->reverseTransform('1234,5'); $transformer->reverseTransform('1234,5');
@ -422,7 +471,6 @@ class NumberToLocalizedStringTransformerTest extends \PHPUnit_Framework_TestCase
public function testDecimalSeparatorMayBeCommaIfGroupingSeparatorIsCommaButNoGroupingUsed() public function testDecimalSeparatorMayBeCommaIfGroupingSeparatorIsCommaButNoGroupingUsed()
{ {
\Locale::setDefault('en');
$transformer = new NumberToLocalizedStringTransformer(); $transformer = new NumberToLocalizedStringTransformer();
$this->assertEquals(1234.5, $transformer->reverseTransform('1234,5')); $this->assertEquals(1234.5, $transformer->reverseTransform('1234,5'));
@ -542,6 +590,9 @@ class NumberToLocalizedStringTransformerTest extends \PHPUnit_Framework_TestCase
$this->markTestSkipped('The "mbstring" extension is required for this test.'); $this->markTestSkipped('The "mbstring" extension is required for this test.');
} }
// Since we test against other locales, we need the full implementation
IntlTestHelper::requireFullIntl($this);
\Locale::setDefault('ru'); \Locale::setDefault('ru');
$transformer = new NumberToLocalizedStringTransformer(null, true); $transformer = new NumberToLocalizedStringTransformer(null, true);
@ -559,6 +610,9 @@ class NumberToLocalizedStringTransformerTest extends \PHPUnit_Framework_TestCase
$this->markTestSkipped('The "mbstring" extension is required for this test.'); $this->markTestSkipped('The "mbstring" extension is required for this test.');
} }
// Since we test against other locales, we need the full implementation
IntlTestHelper::requireFullIntl($this);
\Locale::setDefault('ru'); \Locale::setDefault('ru');
$transformer = new NumberToLocalizedStringTransformer(null, true); $transformer = new NumberToLocalizedStringTransformer(null, true);
@ -587,6 +641,9 @@ class NumberToLocalizedStringTransformerTest extends \PHPUnit_Framework_TestCase
$this->markTestSkipped('The "mbstring" extension is required for this test.'); $this->markTestSkipped('The "mbstring" extension is required for this test.');
} }
// Since we test against other locales, we need the full implementation
IntlTestHelper::requireFullIntl($this);
\Locale::setDefault('ru'); \Locale::setDefault('ru');
$transformer = new NumberToLocalizedStringTransformer(null, true); $transformer = new NumberToLocalizedStringTransformer(null, true);

View File

@ -20,10 +20,7 @@ class PercentToLocalizedStringTransformerTest extends \PHPUnit_Framework_TestCas
{ {
parent::setUp(); parent::setUp();
// Since we test against "de_AT", we need the full implementation \Locale::setDefault('en');
IntlTestHelper::requireFullIntl($this);
\Locale::setDefault('de_AT');
} }
public function testTransform() public function testTransform()
@ -55,6 +52,11 @@ class PercentToLocalizedStringTransformerTest extends \PHPUnit_Framework_TestCas
public function testTransformWithScale() public function testTransformWithScale()
{ {
// Since we test against "de_AT", we need the full implementation
IntlTestHelper::requireFullIntl($this);
\Locale::setDefault('de_AT');
$transformer = new PercentToLocalizedStringTransformer(2); $transformer = new PercentToLocalizedStringTransformer(2);
$this->assertEquals('12,34', $transformer->transform(0.1234)); $this->assertEquals('12,34', $transformer->transform(0.1234));
@ -89,6 +91,11 @@ class PercentToLocalizedStringTransformerTest extends \PHPUnit_Framework_TestCas
public function testReverseTransformWithScale() public function testReverseTransformWithScale()
{ {
// Since we test against "de_AT", we need the full implementation
IntlTestHelper::requireFullIntl($this);
\Locale::setDefault('de_AT');
$transformer = new PercentToLocalizedStringTransformer(2); $transformer = new PercentToLocalizedStringTransformer(2);
$this->assertEquals(0.1234, $transformer->reverseTransform('12,34')); $this->assertEquals(0.1234, $transformer->reverseTransform('12,34'));

View File

@ -13,13 +13,12 @@ namespace Symfony\Component\Form\Tests\Extension\Core\Type;
use Symfony\Component\Form\FormError; use Symfony\Component\Form\FormError;
use Symfony\Component\Form\Test\TypeTestCase as TestCase; use Symfony\Component\Form\Test\TypeTestCase as TestCase;
use Symfony\Component\Intl\Util\IntlTestHelper;
class DateTimeTypeTest extends TestCase class DateTimeTypeTest extends TestCase
{ {
protected function setUp() protected function setUp()
{ {
IntlTestHelper::requireIntl($this); \Locale::setDefault('en');
parent::setUp(); parent::setUp();
} }

View File

@ -23,18 +23,13 @@ class DateTypeTest extends TestCase
protected function setUp() protected function setUp()
{ {
parent::setUp(); parent::setUp();
// we test against "de_AT", so we need the full implementation
IntlTestHelper::requireFullIntl($this);
\Locale::setDefault('de_AT');
$this->defaultTimezone = date_default_timezone_get(); $this->defaultTimezone = date_default_timezone_get();
} }
protected function tearDown() protected function tearDown()
{ {
date_default_timezone_set($this->defaultTimezone); date_default_timezone_set($this->defaultTimezone);
\Locale::setDefault('en');
} }
/** /**
@ -74,6 +69,11 @@ class DateTypeTest extends TestCase
public function testSubmitFromSingleTextDateTime() public function testSubmitFromSingleTextDateTime()
{ {
// we test against "de_AT", so we need the full implementation
IntlTestHelper::requireFullIntl($this);
\Locale::setDefault('de_AT');
$form = $this->factory->create('date', null, array( $form = $this->factory->create('date', null, array(
'format' => \IntlDateFormatter::MEDIUM, 'format' => \IntlDateFormatter::MEDIUM,
'model_timezone' => 'UTC', 'model_timezone' => 'UTC',
@ -90,6 +90,11 @@ class DateTypeTest extends TestCase
public function testSubmitFromSingleTextString() public function testSubmitFromSingleTextString()
{ {
// we test against "de_AT", so we need the full implementation
IntlTestHelper::requireFullIntl($this);
\Locale::setDefault('de_AT');
$form = $this->factory->create('date', null, array( $form = $this->factory->create('date', null, array(
'format' => \IntlDateFormatter::MEDIUM, 'format' => \IntlDateFormatter::MEDIUM,
'model_timezone' => 'UTC', 'model_timezone' => 'UTC',
@ -106,6 +111,11 @@ class DateTypeTest extends TestCase
public function testSubmitFromSingleTextTimestamp() public function testSubmitFromSingleTextTimestamp()
{ {
// we test against "de_AT", so we need the full implementation
IntlTestHelper::requireFullIntl($this);
\Locale::setDefault('de_AT');
$form = $this->factory->create('date', null, array( $form = $this->factory->create('date', null, array(
'format' => \IntlDateFormatter::MEDIUM, 'format' => \IntlDateFormatter::MEDIUM,
'model_timezone' => 'UTC', 'model_timezone' => 'UTC',
@ -124,6 +134,11 @@ class DateTypeTest extends TestCase
public function testSubmitFromSingleTextRaw() public function testSubmitFromSingleTextRaw()
{ {
// we test against "de_AT", so we need the full implementation
IntlTestHelper::requireFullIntl($this);
\Locale::setDefault('de_AT');
$form = $this->factory->create('date', null, array( $form = $this->factory->create('date', null, array(
'format' => \IntlDateFormatter::MEDIUM, 'format' => \IntlDateFormatter::MEDIUM,
'model_timezone' => 'UTC', 'model_timezone' => 'UTC',
@ -382,6 +397,11 @@ class DateTypeTest extends TestCase
public function testSetDataWithNegativeTimezoneOffsetStringInput() public function testSetDataWithNegativeTimezoneOffsetStringInput()
{ {
// we test against "de_AT", so we need the full implementation
IntlTestHelper::requireFullIntl($this);
\Locale::setDefault('de_AT');
$form = $this->factory->create('date', null, array( $form = $this->factory->create('date', null, array(
'format' => \IntlDateFormatter::MEDIUM, 'format' => \IntlDateFormatter::MEDIUM,
'model_timezone' => 'UTC', 'model_timezone' => 'UTC',
@ -399,6 +419,11 @@ class DateTypeTest extends TestCase
public function testSetDataWithNegativeTimezoneOffsetDateTimeInput() public function testSetDataWithNegativeTimezoneOffsetDateTimeInput()
{ {
// we test against "de_AT", so we need the full implementation
IntlTestHelper::requireFullIntl($this);
\Locale::setDefault('de_AT');
$form = $this->factory->create('date', null, array( $form = $this->factory->create('date', null, array(
'format' => \IntlDateFormatter::MEDIUM, 'format' => \IntlDateFormatter::MEDIUM,
'model_timezone' => 'UTC', 'model_timezone' => 'UTC',
@ -435,18 +460,24 @@ class DateTypeTest extends TestCase
{ {
$form = $this->factory->create('date', null, array( $form = $this->factory->create('date', null, array(
'months' => array(6, 7), 'months' => array(6, 7),
'format' => \IntlDateFormatter::SHORT,
)); ));
$view = $form->createView(); $view = $form->createView();
$this->assertEquals(array( $this->assertEquals(array(
new ChoiceView('6', '6', '06'), new ChoiceView(6, '6', '06'),
new ChoiceView('7', '7', '07'), new ChoiceView(7, '7', '07'),
), $view['month']->vars['choices']); ), $view['month']->vars['choices']);
} }
public function testMonthsOptionShortFormat() public function testMonthsOptionShortFormat()
{ {
// we test against "de_AT", so we need the full implementation
IntlTestHelper::requireFullIntl($this);
\Locale::setDefault('de_AT');
$form = $this->factory->create('date', null, array( $form = $this->factory->create('date', null, array(
'months' => array(1, 4), 'months' => array(1, 4),
'format' => 'dd.MMM.yy', 'format' => 'dd.MMM.yy',
@ -455,13 +486,18 @@ class DateTypeTest extends TestCase
$view = $form->createView(); $view = $form->createView();
$this->assertEquals(array( $this->assertEquals(array(
new ChoiceView('1', '1', 'Jän'), new ChoiceView(1, '1', 'Jän'),
new ChoiceView('4', '4', 'Apr.'), new ChoiceView(4, '4', 'Apr.'),
), $view['month']->vars['choices']); ), $view['month']->vars['choices']);
} }
public function testMonthsOptionLongFormat() public function testMonthsOptionLongFormat()
{ {
// we test against "de_AT", so we need the full implementation
IntlTestHelper::requireFullIntl($this);
\Locale::setDefault('de_AT');
$form = $this->factory->create('date', null, array( $form = $this->factory->create('date', null, array(
'months' => array(1, 4), 'months' => array(1, 4),
'format' => 'dd.MMMM.yy', 'format' => 'dd.MMMM.yy',
@ -470,13 +506,18 @@ class DateTypeTest extends TestCase
$view = $form->createView(); $view = $form->createView();
$this->assertEquals(array( $this->assertEquals(array(
new ChoiceView('1', '1', 'Jänner'), new ChoiceView(1, '1', 'Jänner'),
new ChoiceView('4', '4', 'April'), new ChoiceView(4, '4', 'April'),
), $view['month']->vars['choices']); ), $view['month']->vars['choices']);
} }
public function testMonthsOptionLongFormatWithDifferentTimezone() public function testMonthsOptionLongFormatWithDifferentTimezone()
{ {
// we test against "de_AT", so we need the full implementation
IntlTestHelper::requireFullIntl($this);
\Locale::setDefault('de_AT');
$form = $this->factory->create('date', null, array( $form = $this->factory->create('date', null, array(
'months' => array(1, 4), 'months' => array(1, 4),
'format' => 'dd.MMMM.yy', 'format' => 'dd.MMMM.yy',
@ -485,8 +526,8 @@ class DateTypeTest extends TestCase
$view = $form->createView(); $view = $form->createView();
$this->assertEquals(array( $this->assertEquals(array(
new ChoiceView('1', '1', 'Jänner'), new ChoiceView(1, '1', 'Jänner'),
new ChoiceView('4', '4', 'April'), new ChoiceView(4, '4', 'April'),
), $view['month']->vars['choices']); ), $view['month']->vars['choices']);
} }
@ -499,8 +540,8 @@ class DateTypeTest extends TestCase
$view = $form->createView(); $view = $form->createView();
$this->assertEquals(array( $this->assertEquals(array(
new ChoiceView('6', '6', '06'), new ChoiceView(6, '6', '06'),
new ChoiceView('7', '7', '07'), new ChoiceView(7, '7', '07'),
), $view['day']->vars['choices']); ), $view['day']->vars['choices']);
} }
@ -578,6 +619,11 @@ class DateTypeTest extends TestCase
public function testPassDatePatternToView() public function testPassDatePatternToView()
{ {
// we test against "de_AT", so we need the full implementation
IntlTestHelper::requireFullIntl($this);
\Locale::setDefault('de_AT');
$form = $this->factory->create('date'); $form = $this->factory->create('date');
$view = $form->createView(); $view = $form->createView();
@ -586,6 +632,11 @@ class DateTypeTest extends TestCase
public function testPassDatePatternToViewDifferentFormat() public function testPassDatePatternToViewDifferentFormat()
{ {
// we test against "de_AT", so we need the full implementation
IntlTestHelper::requireFullIntl($this);
\Locale::setDefault('de_AT');
$form = $this->factory->create('date', null, array( $form = $this->factory->create('date', null, array(
'format' => \IntlDateFormatter::LONG, 'format' => \IntlDateFormatter::LONG,
)); ));
@ -629,6 +680,9 @@ class DateTypeTest extends TestCase
public function testDatePatternFormatWithQuotedStrings() public function testDatePatternFormatWithQuotedStrings()
{ {
// we test against "es_ES", so we need the full implementation
IntlTestHelper::requireFullIntl($this);
\Locale::setDefault('es_ES'); \Locale::setDefault('es_ES');
$form = $this->factory->create('date', null, array( $form = $this->factory->create('date', null, array(

View File

@ -14,17 +14,9 @@ namespace Symfony\Component\Form\Tests\Extension\Core\Type;
use Symfony\Component\Form\ChoiceList\View\ChoiceView; use Symfony\Component\Form\ChoiceList\View\ChoiceView;
use Symfony\Component\Form\FormError; use Symfony\Component\Form\FormError;
use Symfony\Component\Form\Test\TypeTestCase as TestCase; use Symfony\Component\Form\Test\TypeTestCase as TestCase;
use Symfony\Component\Intl\Util\IntlTestHelper;
class TimeTypeTest extends TestCase class TimeTypeTest extends TestCase
{ {
protected function setUp()
{
IntlTestHelper::requireIntl($this);
parent::setUp();
}
public function testSubmitDateTime() public function testSubmitDateTime()
{ {
$form = $this->factory->create('time', null, array( $form = $this->factory->create('time', null, array(

View File

@ -70,13 +70,13 @@ class Collator
/** /**
* Constructor. * Constructor.
* *
* @param string $locale The locale code. The only currently supported locale is "en". * @param string $locale The locale code. The only currently supported locale is "en" (or null using the default locale, i.e. "en").
* *
* @throws MethodArgumentValueNotImplementedException When $locale different than "en" is passed * @throws MethodArgumentValueNotImplementedException When $locale different than "en" or null is passed
*/ */
public function __construct($locale) public function __construct($locale)
{ {
if ('en' != $locale) { if ('en' !== $locale && null !== $locale) {
throw new MethodArgumentValueNotImplementedException(__METHOD__, 'locale', $locale, 'Only the locale "en" is supported'); throw new MethodArgumentValueNotImplementedException(__METHOD__, 'locale', $locale, 'Only the locale "en" is supported');
} }
} }
@ -84,11 +84,11 @@ class Collator
/** /**
* Static constructor. * Static constructor.
* *
* @param string $locale The locale code. The only currently supported locale is "en". * @param string $locale The locale code. The only currently supported locale is "en" (or null using the default locale, i.e. "en").
* *
* @return Collator * @return Collator
* *
* @throws MethodArgumentValueNotImplementedException When $locale different than "en" is passed * @throws MethodArgumentValueNotImplementedException When $locale different than "en" or null is passed
*/ */
public static function create($locale) public static function create($locale)
{ {

View File

@ -129,7 +129,7 @@ class IntlDateFormatter
/** /**
* Constructor. * Constructor.
* *
* @param string $locale The locale code. The only currently supported locale is "en". * @param string $locale The locale code. The only currently supported locale is "en" (or null using the default locale, i.e. "en").
* @param int $datetype Type of date formatting, one of the format type constants * @param int $datetype Type of date formatting, one of the format type constants
* @param int $timetype Type of time formatting, one of the format type constants * @param int $timetype Type of time formatting, one of the format type constants
* @param string $timezone Timezone identifier * @param string $timezone Timezone identifier
@ -140,12 +140,12 @@ class IntlDateFormatter
* @see http://www.php.net/manual/en/intldateformatter.create.php * @see http://www.php.net/manual/en/intldateformatter.create.php
* @see http://userguide.icu-project.org/formatparse/datetime * @see http://userguide.icu-project.org/formatparse/datetime
* *
* @throws MethodArgumentValueNotImplementedException When $locale different than "en" is passed * @throws MethodArgumentValueNotImplementedException When $locale different than "en" or null is passed
* @throws MethodArgumentValueNotImplementedException When $calendar different than GREGORIAN is passed * @throws MethodArgumentValueNotImplementedException When $calendar different than GREGORIAN is passed
*/ */
public function __construct($locale, $datetype, $timetype, $timezone = null, $calendar = self::GREGORIAN, $pattern = null) public function __construct($locale, $datetype, $timetype, $timezone = null, $calendar = self::GREGORIAN, $pattern = null)
{ {
if ('en' !== $locale) { if ('en' !== $locale && null !== $locale) {
throw new MethodArgumentValueNotImplementedException(__METHOD__, 'locale', $locale, 'Only the locale "en" is supported'); throw new MethodArgumentValueNotImplementedException(__METHOD__, 'locale', $locale, 'Only the locale "en" is supported');
} }
@ -163,7 +163,7 @@ class IntlDateFormatter
/** /**
* Static constructor. * Static constructor.
* *
* @param string $locale The locale code. The only currently supported locale is "en". * @param string $locale The locale code. The only currently supported locale is "en" (or null using the default locale, i.e. "en").
* @param int $datetype Type of date formatting, one of the format type constants * @param int $datetype Type of date formatting, one of the format type constants
* @param int $timetype Type of time formatting, one of the format type constants * @param int $timetype Type of time formatting, one of the format type constants
* @param string $timezone Timezone identifier * @param string $timezone Timezone identifier
@ -176,7 +176,7 @@ class IntlDateFormatter
* @see http://www.php.net/manual/en/intldateformatter.create.php * @see http://www.php.net/manual/en/intldateformatter.create.php
* @see http://userguide.icu-project.org/formatparse/datetime * @see http://userguide.icu-project.org/formatparse/datetime
* *
* @throws MethodArgumentValueNotImplementedException When $locale different than "en" is passed * @throws MethodArgumentValueNotImplementedException When $locale different than "en" or null is passed
* @throws MethodArgumentValueNotImplementedException When $calendar different than GREGORIAN is passed * @throws MethodArgumentValueNotImplementedException When $calendar different than GREGORIAN is passed
*/ */
public static function create($locale, $datetype, $timetype, $timezone = null, $calendar = self::GREGORIAN, $pattern = null) public static function create($locale, $datetype, $timetype, $timezone = null, $calendar = self::GREGORIAN, $pattern = null)

View File

@ -263,7 +263,7 @@ class NumberFormatter
/** /**
* Constructor. * Constructor.
* *
* @param string $locale The locale code. The only currently supported locale is "en". * @param string $locale The locale code. The only currently supported locale is "en" (or null using the default locale, i.e. "en").
* @param int $style Style of the formatting, one of the format style constants. * @param int $style Style of the formatting, one of the format style constants.
* The only supported styles are NumberFormatter::DECIMAL * The only supported styles are NumberFormatter::DECIMAL
* and NumberFormatter::CURRENCY. * and NumberFormatter::CURRENCY.
@ -275,13 +275,13 @@ class NumberFormatter
* @see http://www.icu-project.org/apiref/icu4c/classDecimalFormat.html#_details * @see http://www.icu-project.org/apiref/icu4c/classDecimalFormat.html#_details
* @see http://www.icu-project.org/apiref/icu4c/classRuleBasedNumberFormat.html#_details * @see http://www.icu-project.org/apiref/icu4c/classRuleBasedNumberFormat.html#_details
* *
* @throws MethodArgumentValueNotImplementedException When $locale different than "en" is passed * @throws MethodArgumentValueNotImplementedException When $locale different than "en" or null is passed
* @throws MethodArgumentValueNotImplementedException When the $style is not supported * @throws MethodArgumentValueNotImplementedException When the $style is not supported
* @throws MethodArgumentNotImplementedException When the pattern value is different than null * @throws MethodArgumentNotImplementedException When the pattern value is different than null
*/ */
public function __construct($locale = 'en', $style = null, $pattern = null) public function __construct($locale = 'en', $style = null, $pattern = null)
{ {
if ('en' != $locale) { if ('en' !== $locale && null !== $locale) {
throw new MethodArgumentValueNotImplementedException(__METHOD__, 'locale', $locale, 'Only the locale "en" is supported'); throw new MethodArgumentValueNotImplementedException(__METHOD__, 'locale', $locale, 'Only the locale "en" is supported');
} }
@ -300,7 +300,7 @@ class NumberFormatter
/** /**
* Static constructor. * Static constructor.
* *
* @param string $locale The locale code. The only supported locale is "en". * @param string $locale The locale code. The only supported locale is "en" (or null using the default locale, i.e. "en").
* @param int $style Style of the formatting, one of the format style constants. * @param int $style Style of the formatting, one of the format style constants.
* The only currently supported styles are NumberFormatter::DECIMAL * The only currently supported styles are NumberFormatter::DECIMAL
* and NumberFormatter::CURRENCY. * and NumberFormatter::CURRENCY.
@ -314,7 +314,7 @@ class NumberFormatter
* @see http://www.icu-project.org/apiref/icu4c/classDecimalFormat.html#_details * @see http://www.icu-project.org/apiref/icu4c/classDecimalFormat.html#_details
* @see http://www.icu-project.org/apiref/icu4c/classRuleBasedNumberFormat.html#_details * @see http://www.icu-project.org/apiref/icu4c/classRuleBasedNumberFormat.html#_details
* *
* @throws MethodArgumentValueNotImplementedException When $locale different than "en" is passed * @throws MethodArgumentValueNotImplementedException When $locale different than "en" or null is passed
* @throws MethodArgumentValueNotImplementedException When the $style is not supported * @throws MethodArgumentValueNotImplementedException When the $style is not supported
* @throws MethodArgumentNotImplementedException When the pattern value is different than null * @throws MethodArgumentNotImplementedException When the pattern value is different than null
*/ */

View File

@ -60,6 +60,12 @@ class CollatorTest extends AbstractCollatorTest
$this->assertEquals('en', $collator->getLocale()); $this->assertEquals('en', $collator->getLocale());
} }
public function testConstructWithoutLocale()
{
$collator = $this->getCollator(null);
$this->assertInstanceOf('\Symfony\Component\Intl\Collator\Collator', $collator);
}
/** /**
* @expectedException \Symfony\Component\Intl\Exception\MethodNotImplementedException * @expectedException \Symfony\Component\Intl\Exception\MethodNotImplementedException
*/ */

View File

@ -12,7 +12,7 @@
namespace Symfony\Component\Intl\Tests\Data\Bundle\Reader; namespace Symfony\Component\Intl\Tests\Data\Bundle\Reader;
use Symfony\Component\Intl\Data\Bundle\Reader\IntlBundleReader; use Symfony\Component\Intl\Data\Bundle\Reader\IntlBundleReader;
use Symfony\Component\Intl\Util\IntlTestHelper; use Symfony\Component\Intl\Intl;
/** /**
* @author Bernhard Schussek <bschussek@gmail.com> * @author Bernhard Schussek <bschussek@gmail.com>
@ -26,7 +26,10 @@ class IntlBundleReaderTest extends \PHPUnit_Framework_TestCase
protected function setUp() protected function setUp()
{ {
IntlTestHelper::requireFullIntl($this); // We only run tests if the intl extension is loaded...
if (!Intl::isExtensionLoaded()) {
$this->markTestSkipped('The intl extension is not available.');
}
$this->reader = new IntlBundleReader(); $this->reader = new IntlBundleReader();
} }
@ -52,6 +55,14 @@ class IntlBundleReaderTest extends \PHPUnit_Framework_TestCase
public function testReadDoesNotFollowFallback() public function testReadDoesNotFollowFallback()
{ {
if (PHP_VERSION_ID < 50307 || PHP_VERSION_ID === 50400) {
$this->markTestSkipped('ResourceBundle handles disabling fallback properly only as of PHP 5.3.7 and 5.4.1.');
}
if (defined('HHVM_VERSION')) {
$this->markTestSkipped('ResourceBundle does not support disabling fallback properly on HHVM.');
}
// "ro_MD" -> "ro" // "ro_MD" -> "ro"
$data = $this->reader->read(__DIR__.'/Fixtures/res', 'ro_MD'); $data = $this->reader->read(__DIR__.'/Fixtures/res', 'ro_MD');
@ -64,6 +75,14 @@ class IntlBundleReaderTest extends \PHPUnit_Framework_TestCase
public function testReadDoesNotFollowFallbackAlias() public function testReadDoesNotFollowFallbackAlias()
{ {
if (PHP_VERSION_ID < 50307 || PHP_VERSION_ID === 50400) {
$this->markTestSkipped('ResourceBundle handles disabling fallback properly only as of PHP 5.3.7 and 5.4.1.');
}
if (defined('HHVM_VERSION')) {
$this->markTestSkipped('ResourceBundle does not support disabling fallback properly on HHVM.');
}
// "mo" = "ro_MD" -> "ro" // "mo" = "ro_MD" -> "ro"
$data = $this->reader->read(__DIR__.'/Fixtures/res', 'mo'); $data = $this->reader->read(__DIR__.'/Fixtures/res', 'mo');

View File

@ -13,7 +13,7 @@ namespace Symfony\Component\Intl\Tests\Data\Bundle\Writer;
use Symfony\Component\Filesystem\Filesystem; use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Intl\Data\Bundle\Writer\JsonBundleWriter; use Symfony\Component\Intl\Data\Bundle\Writer\JsonBundleWriter;
use Symfony\Component\Intl\Util\IntlTestHelper; use Symfony\Component\Intl\Intl;
/** /**
* @author Bernhard Schussek <bschussek@gmail.com> * @author Bernhard Schussek <bschussek@gmail.com>
@ -74,7 +74,10 @@ class JsonBundleWriterTest extends \PHPUnit_Framework_TestCase
public function testWriteResourceBundle() public function testWriteResourceBundle()
{ {
IntlTestHelper::requireFullIntl($this); // We only run tests if the intl extension is loaded...
if (!Intl::isExtensionLoaded()) {
$this->markTestSkipped('The intl extension is not available.');
}
$bundle = new \ResourceBundle('rb', __DIR__.'/Fixtures', false); $bundle = new \ResourceBundle('rb', __DIR__.'/Fixtures', false);

View File

@ -13,7 +13,7 @@ namespace Symfony\Component\Intl\Tests\Data\Bundle\Writer;
use Symfony\Component\Filesystem\Filesystem; use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Intl\Data\Bundle\Writer\PhpBundleWriter; use Symfony\Component\Intl\Data\Bundle\Writer\PhpBundleWriter;
use Symfony\Component\Intl\Util\IntlTestHelper; use Symfony\Component\Intl\Intl;
/** /**
* @author Bernhard Schussek <bschussek@gmail.com> * @author Bernhard Schussek <bschussek@gmail.com>
@ -66,7 +66,14 @@ class PhpBundleWriterTest extends \PHPUnit_Framework_TestCase
public function testWriteResourceBundle() public function testWriteResourceBundle()
{ {
IntlTestHelper::requireFullIntl($this); // We only run tests if the intl extension is loaded...
if (!Intl::isExtensionLoaded()) {
$this->markTestSkipped('The intl extension is not available.');
}
if (PHP_VERSION_ID < 50315 || (PHP_VERSION_ID >= 50400 && PHP_VERSION_ID < 50404)) {
$this->markTestSkipped('ResourceBundle implements Traversable only as of PHP 5.3.15 and 5.4.4');
}
$bundle = new \ResourceBundle('rb', __DIR__.'/Fixtures', false); $bundle = new \ResourceBundle('rb', __DIR__.'/Fixtures', false);

View File

@ -22,6 +22,12 @@ class IntlDateFormatterTest extends AbstractIntlDateFormatterTest
$this->assertEquals('y-M-d', $formatter->getPattern()); $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());
}
/** /**
* @expectedException \Symfony\Component\Intl\Exception\MethodArgumentValueNotImplementedException * @expectedException \Symfony\Component\Intl\Exception\MethodArgumentValueNotImplementedException
*/ */

View File

@ -56,8 +56,6 @@ abstract class AbstractNumberFormatterTest extends \PHPUnit_Framework_TestCase
*/ */
public function testFormatCurrencyWithCurrencyStyle($value, $currency, $expected) public function testFormatCurrencyWithCurrencyStyle($value, $currency, $expected)
{ {
IntlTestHelper::requireFullIntl($this);
$formatter = $this->getNumberFormatter('en', NumberFormatter::CURRENCY); $formatter = $this->getNumberFormatter('en', NumberFormatter::CURRENCY);
$this->assertEquals($expected, $formatter->formatCurrency($value, $currency)); $this->assertEquals($expected, $formatter->formatCurrency($value, $currency));
} }
@ -84,8 +82,6 @@ abstract class AbstractNumberFormatterTest extends \PHPUnit_Framework_TestCase
*/ */
public function testFormatCurrencyWithCurrencyStyleCostaRicanColonsRounding($value, $currency, $symbol, $expected) public function testFormatCurrencyWithCurrencyStyleCostaRicanColonsRounding($value, $currency, $symbol, $expected)
{ {
IntlTestHelper::requireFullIntl($this);
$formatter = $this->getNumberFormatter('en', NumberFormatter::CURRENCY); $formatter = $this->getNumberFormatter('en', NumberFormatter::CURRENCY);
$this->assertEquals(sprintf($expected, $symbol), $formatter->formatCurrency($value, $currency)); $this->assertEquals(sprintf($expected, $symbol), $formatter->formatCurrency($value, $currency));
} }
@ -104,8 +100,6 @@ abstract class AbstractNumberFormatterTest extends \PHPUnit_Framework_TestCase
*/ */
public function testFormatCurrencyWithCurrencyStyleBrazilianRealRounding($value, $currency, $symbol, $expected) public function testFormatCurrencyWithCurrencyStyleBrazilianRealRounding($value, $currency, $symbol, $expected)
{ {
IntlTestHelper::requireFullIntl($this);
$formatter = $this->getNumberFormatter('en', NumberFormatter::CURRENCY); $formatter = $this->getNumberFormatter('en', NumberFormatter::CURRENCY);
$this->assertEquals(sprintf($expected, $symbol), $formatter->formatCurrency($value, $currency)); $this->assertEquals(sprintf($expected, $symbol), $formatter->formatCurrency($value, $currency));
} }
@ -133,8 +127,6 @@ abstract class AbstractNumberFormatterTest extends \PHPUnit_Framework_TestCase
*/ */
public function testFormatCurrencyWithCurrencyStyleSwissRounding($value, $currency, $symbol, $expected) public function testFormatCurrencyWithCurrencyStyleSwissRounding($value, $currency, $symbol, $expected)
{ {
IntlTestHelper::requireFullIntl($this);
$formatter = $this->getNumberFormatter('en', NumberFormatter::CURRENCY); $formatter = $this->getNumberFormatter('en', NumberFormatter::CURRENCY);
$this->assertEquals(sprintf($expected, $symbol), $formatter->formatCurrency($value, $currency)); $this->assertEquals(sprintf($expected, $symbol), $formatter->formatCurrency($value, $currency));
} }

View File

@ -13,7 +13,6 @@ namespace Symfony\Component\Intl\Tests\NumberFormatter;
use Symfony\Component\Intl\Globals\IntlGlobals; use Symfony\Component\Intl\Globals\IntlGlobals;
use Symfony\Component\Intl\NumberFormatter\NumberFormatter; 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 * Note that there are some values written like -2147483647 - 1. This is the lower 32bit int max and is a known
@ -21,13 +20,6 @@ use Symfony\Component\Intl\Util\IntlTestHelper;
*/ */
class NumberFormatterTest extends AbstractNumberFormatterTest class NumberFormatterTest extends AbstractNumberFormatterTest
{ {
protected function setUp()
{
IntlTestHelper::requireIntl($this);
parent::setUp();
}
/** /**
* @expectedException \Symfony\Component\Intl\Exception\MethodArgumentValueNotImplementedException * @expectedException \Symfony\Component\Intl\Exception\MethodArgumentValueNotImplementedException
*/ */
@ -70,6 +62,14 @@ class NumberFormatterTest extends AbstractNumberFormatterTest
$formatter->setAttribute(NumberFormatter::ROUNDING_MODE, null); $formatter->setAttribute(NumberFormatter::ROUNDING_MODE, null);
} }
public function testConstructWithoutLocale()
{
$this->assertInstanceOf(
'\Symfony\Component\Intl\NumberFormatter\NumberFormatter',
$this->getNumberFormatter(null, NumberFormatter::DECIMAL)
);
}
public function testCreate() public function testCreate()
{ {
$this->assertInstanceOf( $this->assertInstanceOf(

View File

@ -11,7 +11,6 @@
namespace Symfony\Component\Locale\Tests; namespace Symfony\Component\Locale\Tests;
use Symfony\Component\Intl\Util\IntlTestHelper;
use Symfony\Component\Locale\Locale; use Symfony\Component\Locale\Locale;
/** /**
@ -23,8 +22,7 @@ class LocaleTest extends \PHPUnit_Framework_TestCase
{ {
protected function setUp() protected function setUp()
{ {
// Locale extends \Locale, so intl must be present \Locale::setDefault('en');
IntlTestHelper::requireIntl($this);
} }
public function testGetDisplayCountries() public function testGetDisplayCountries()

View File

@ -11,7 +11,6 @@
namespace Symfony\Component\Locale\Tests\Stub; namespace Symfony\Component\Locale\Tests\Stub;
use Symfony\Component\Intl\Util\IntlTestHelper;
use Symfony\Component\Locale\Stub\StubLocale; use Symfony\Component\Locale\Stub\StubLocale;
/** /**
@ -19,12 +18,6 @@ use Symfony\Component\Locale\Stub\StubLocale;
*/ */
class StubLocaleTest extends \PHPUnit_Framework_TestCase class StubLocaleTest extends \PHPUnit_Framework_TestCase
{ {
protected function setUp()
{
// Locale extends \Locale, so intl must be present
IntlTestHelper::requireIntl($this);
}
public function testGetCurrenciesData() public function testGetCurrenciesData()
{ {
$currencies = StubLocale::getCurrenciesData('en'); $currencies = StubLocale::getCurrenciesData('en');

View File

@ -18,13 +18,6 @@ use Symfony\Component\Validator\Validation;
class CountryValidatorTest extends AbstractConstraintValidatorTest class CountryValidatorTest extends AbstractConstraintValidatorTest
{ {
protected function setUp()
{
IntlTestHelper::requireFullIntl($this);
parent::setUp();
}
protected function getApiVersion() protected function getApiVersion()
{ {
return Validation::API_VERSION_2_5; return Validation::API_VERSION_2_5;

View File

@ -18,13 +18,6 @@ use Symfony\Component\Validator\Validation;
class CurrencyValidatorTest extends AbstractConstraintValidatorTest class CurrencyValidatorTest extends AbstractConstraintValidatorTest
{ {
protected function setUp()
{
IntlTestHelper::requireFullIntl($this);
parent::setUp();
}
protected function getApiVersion() protected function getApiVersion()
{ {
return Validation::API_VERSION_2_5; return Validation::API_VERSION_2_5;
@ -72,6 +65,8 @@ class CurrencyValidatorTest extends AbstractConstraintValidatorTest
**/ **/
public function testValidCurrenciesWithCountrySpecificLocale($currency) public function testValidCurrenciesWithCountrySpecificLocale($currency)
{ {
IntlTestHelper::requireFullIntl($this);
\Locale::setDefault('en_GB'); \Locale::setDefault('en_GB');
$this->validator->validate($currency, new Currency()); $this->validator->validate($currency, new Currency());

View File

@ -28,13 +28,6 @@ class LanguageValidatorTest extends AbstractConstraintValidatorTest
return new LanguageValidator(); return new LanguageValidator();
} }
protected function setUp()
{
IntlTestHelper::requireFullIntl($this);
parent::setUp();
}
public function testNullIsValid() public function testNullIsValid()
{ {
$this->validator->validate(null, new Language()); $this->validator->validate(null, new Language());
@ -102,6 +95,8 @@ class LanguageValidatorTest extends AbstractConstraintValidatorTest
public function testValidateUsingCountrySpecificLocale() public function testValidateUsingCountrySpecificLocale()
{ {
IntlTestHelper::requireFullIntl($this);
\Locale::setDefault('fr_FR'); \Locale::setDefault('fr_FR');
$existingLanguage = 'en'; $existingLanguage = 'en';

View File

@ -11,7 +11,6 @@
namespace Symfony\Component\Validator\Tests\Constraints; namespace Symfony\Component\Validator\Tests\Constraints;
use Symfony\Component\Intl\Util\IntlTestHelper;
use Symfony\Component\Validator\Constraints\Locale; use Symfony\Component\Validator\Constraints\Locale;
use Symfony\Component\Validator\Constraints\LocaleValidator; use Symfony\Component\Validator\Constraints\LocaleValidator;
use Symfony\Component\Validator\Validation; use Symfony\Component\Validator\Validation;
@ -28,13 +27,6 @@ class LocaleValidatorTest extends AbstractConstraintValidatorTest
return new LocaleValidator(); return new LocaleValidator();
} }
protected function setUp()
{
IntlTestHelper::requireIntl($this);
parent::setUp();
}
public function testNullIsValid() public function testNullIsValid()
{ {
$this->validator->validate(null, new Locale()); $this->validator->validate(null, new Locale());