Skip to content

Commit 2128d52

Browse files
committed
Merge branch '2.8' into 3.0
* 2.8: [DependencyInjection] fix dumped YAML snytax Remove InputOption::VALUE_REQUIRED mode from $default parameter description as InputOption::setDefault() throws an exception only when called in InputOption::VALUE_NONE mode. In practice the $default value could still be accessed in InputOption::VALUE_REQUIRED mode in case InputOption was never set but accessed from InputDefinition::getOption() method [Form] Fixed violation mapping if multiple forms are using the same (or part of the same) property path fix FQCN in tests added by symfony#17694 Fix locale and written standard inconsistencies for Norwegian translations [Form] [Validator] Fix locale inconsistencies in Norwegian translations [TwigBridge] Symfony 3.1 forward compatibility fixed CS [DependencyInjection] fixed exceptions thrown by get method of ContainerBuilder [Yaml] properly parse lists in object maps [FrameworkBundle] Remove unused private method. [Form] remove useless code in ResizeFormListener [Config] Fix EnumNodeDefinition to allow building enum nodes with one element fix choice_value option in EntityType and add some tests
2 parents a14bcc6 + fc2fa79 commit 2128d52

File tree

24 files changed

+482
-368
lines changed

24 files changed

+482
-368
lines changed

src/Symfony/Bridge/Doctrine/Form/ChoiceList/DoctrineChoiceLoader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ public function loadChoicesForValues(array $values, $value = null)
146146

147147
// Optimize performance in case we have an object loader and
148148
// a single-field identifier
149-
if (!$this->choiceList && $this->objectLoader && $this->idReader->isSingleId()) {
149+
if (null === $value && !$this->choiceList && $this->objectLoader && $this->idReader->isSingleId()) {
150150
$unorderedObjects = $this->objectLoader->getEntitiesByIds($this->idReader->getIdField(), $values);
151151
$objectsById = array();
152152
$objects = array();

src/Symfony/Bridge/Doctrine/Tests/Form/Type/EntityTypeTest.php

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -753,6 +753,55 @@ public function testOverrideChoices()
753753
$this->assertSame('2', $field->getViewData());
754754
}
755755

756+
public function testOverrideChoicesValues()
757+
{
758+
$entity1 = new SingleIntIdEntity(1, 'Foo');
759+
$entity2 = new SingleIntIdEntity(2, 'Bar');
760+
761+
$this->persist(array($entity1, $entity2));
762+
763+
$field = $this->factory->createNamed('name', 'Symfony\Bridge\Doctrine\Form\Type\EntityType', null, array(
764+
'em' => 'default',
765+
'class' => self::SINGLE_IDENT_CLASS,
766+
'choice_label' => 'name',
767+
'choice_value' => 'name',
768+
));
769+
770+
$field->submit('Bar');
771+
772+
$this->assertEquals(array('Foo' => new ChoiceView($entity1, 'Foo', 'Foo'), 'Bar' => new ChoiceView($entity2, 'Bar', 'Bar')), $field->createView()->vars['choices']);
773+
$this->assertTrue($field->isSynchronized(), 'Field should be synchronized.');
774+
$this->assertSame($entity2, $field->getData(), 'Entity should be loaded by custom value.');
775+
$this->assertSame('Bar', $field->getViewData());
776+
}
777+
778+
public function testOverrideChoicesValuesWithCallable()
779+
{
780+
$entity1 = new GroupableEntity(1, 'Foo', 'BazGroup');
781+
$entity2 = new GroupableEntity(2, 'Bar', 'BooGroup');
782+
783+
$this->persist(array($entity1, $entity2));
784+
785+
$field = $this->factory->createNamed('name', 'Symfony\Bridge\Doctrine\Form\Type\EntityType', null, array(
786+
'em' => 'default',
787+
'class' => self::ITEM_GROUP_CLASS,
788+
'choice_label' => 'name',
789+
'choice_value' => function (GroupableEntity $entity) {
790+
return $entity->groupName.'/'.$entity->name;
791+
},
792+
));
793+
794+
$field->submit('BooGroup/Bar');
795+
796+
$this->assertEquals(array(
797+
'BazGroup/Foo' => new ChoiceView($entity1, 'BazGroup/Foo', 'Foo'),
798+
'BooGroup/Bar' => new ChoiceView($entity2, 'BooGroup/Bar', 'Bar'),
799+
), $field->createView()->vars['choices']);
800+
$this->assertTrue($field->isSynchronized(), 'Field should be synchronized.');
801+
$this->assertSame($entity2, $field->getData(), 'Entity should be loaded by custom value.');
802+
$this->assertSame('BooGroup/Bar', $field->getViewData());
803+
}
804+
756805
public function testGroupByChoices()
757806
{
758807
$item1 = new GroupableEntity(1, 'Foo', 'Group1');

src/Symfony/Bridge/Twig/Extension/YamlExtension.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Bridge\Twig\Extension;
1313

1414
use Symfony\Component\Yaml\Dumper as YamlDumper;
15+
use Symfony\Component\Yaml\Yaml;
1516

1617
/**
1718
* Provides integration of the Yaml component with Twig.
@@ -40,7 +41,7 @@ public function encode($input, $inline = 0, $dumpObjects = false)
4041
}
4142

4243
if (defined('Symfony\Component\Yaml\Yaml::DUMP_OBJECT')) {
43-
$dumpObjects = (int) $dumpObjects;
44+
return $dumper->dump($input, $inline, 0, is_bool($dumpObjects) ? Yaml::DUMP_OBJECT : 0);
4445
}
4546

4647
return $dumper->dump($input, $inline, 0, false, $dumpObjects);

src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/TextDescriptor.php

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -411,17 +411,6 @@ private function formatRouterConfig(array $config)
411411
return trim($configAsString);
412412
}
413413

414-
/**
415-
* @param string $section
416-
* @param string $message
417-
*
418-
* @return string
419-
*/
420-
private function formatSection($section, $message)
421-
{
422-
return sprintf('<info>[%s]</info> %s', $section, $message);
423-
}
424-
425414
/**
426415
* @param callable $callable
427416
*

src/Symfony/Component/Config/Definition/Builder/EnumNodeDefinition.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ public function values(array $values)
3131
{
3232
$values = array_unique($values);
3333

34-
if (count($values) <= 1) {
35-
throw new \InvalidArgumentException('->values() must be called with at least two distinct values.');
34+
if (empty($values)) {
35+
throw new \InvalidArgumentException('->values() must be called with at least one value.');
3636
}
3737

3838
$this->values = $values;

src/Symfony/Component/Config/Tests/Definition/Builder/EnumNodeDefinitionTest.php

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,22 @@
1515

1616
class EnumNodeDefinitionTest extends \PHPUnit_Framework_TestCase
1717
{
18-
/**
19-
* @expectedException \InvalidArgumentException
20-
* @expectedExceptionMessage ->values() must be called with at least two distinct values.
21-
*/
22-
public function testNoDistinctValues()
18+
public function testWithOneValue()
19+
{
20+
$def = new EnumNodeDefinition('foo');
21+
$def->values(array('foo'));
22+
23+
$node = $def->getNode();
24+
$this->assertEquals(array('foo'), $node->getValues());
25+
}
26+
27+
public function testWithOneDistinctValue()
2328
{
2429
$def = new EnumNodeDefinition('foo');
2530
$def->values(array('foo', 'foo'));
31+
32+
$node = $def->getNode();
33+
$this->assertEquals(array('foo'), $node->getValues());
2634
}
2735

2836
/**
@@ -35,6 +43,16 @@ public function testNoValuesPassed()
3543
$def->getNode();
3644
}
3745

46+
/**
47+
* @expectedException \InvalidArgumentException
48+
* @expectedExceptionMessage ->values() must be called with at least one value.
49+
*/
50+
public function testWithNoValues()
51+
{
52+
$def = new EnumNodeDefinition('foo');
53+
$def->values(array());
54+
}
55+
3856
public function testGetNode()
3957
{
4058
$def = new EnumNodeDefinition('foo');

src/Symfony/Component/Console/Command/Command.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ public function addArgument($name, $mode = null, $description = '', $default = n
383383
* @param string $shortcut The shortcut (can be null)
384384
* @param int $mode The option mode: One of the InputOption::VALUE_* constants
385385
* @param string $description A description text
386-
* @param mixed $default The default value (must be null for InputOption::VALUE_REQUIRED or InputOption::VALUE_NONE)
386+
* @param mixed $default The default value (must be null for InputOption::VALUE_NONE)
387387
*
388388
* @return Command The current instance
389389
*/

src/Symfony/Component/Console/Input/InputOption.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class InputOption
3939
* @param string|array $shortcut The shortcuts, can be null, a string of shortcuts delimited by | or an array of shortcuts
4040
* @param int $mode The option mode: One of the VALUE_* constants
4141
* @param string $description A description text
42-
* @param mixed $default The default value (must be null for self::VALUE_REQUIRED or self::VALUE_NONE)
42+
* @param mixed $default The default value (must be null for self::VALUE_NONE)
4343
*
4444
* @throws InvalidArgumentException If option mode is invalid or incompatible
4545
*/

src/Symfony/Component/DependencyInjection/ContainerBuilder.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
1919
use Symfony\Component\DependencyInjection\Exception\LogicException;
2020
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
21+
use Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException;
22+
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
2123
use Symfony\Component\DependencyInjection\Extension\ExtensionInterface;
2224
use Symfony\Component\Config\Resource\FileResource;
2325
use Symfony\Component\Config\Resource\ResourceInterface;
@@ -398,8 +400,9 @@ public function has($id)
398400
*
399401
* @return object The associated service
400402
*
401-
* @throws InvalidArgumentException when no definitions are available
402-
* @throws LogicException when a circular dependency is detected
403+
* @throws InvalidArgumentException when no definitions are available
404+
* @throws ServiceCircularReferenceException When a circular reference is detected
405+
* @throws ServiceNotFoundException When the service is not defined
403406
* @throws \Exception
404407
*
405408
* @see Reference
@@ -418,7 +421,7 @@ public function get($id, $invalidBehavior = ContainerInterface::EXCEPTION_ON_INV
418421

419422
try {
420423
$definition = $this->getDefinition($id);
421-
} catch (InvalidArgumentException $e) {
424+
} catch (ServiceNotFoundException $e) {
422425
if (ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE !== $invalidBehavior) {
423426
return;
424427
}
@@ -758,14 +761,14 @@ public function hasDefinition($id)
758761
*
759762
* @return Definition A Definition instance
760763
*
761-
* @throws InvalidArgumentException if the service definition does not exist
764+
* @throws ServiceNotFoundException if the service definition does not exist
762765
*/
763766
public function getDefinition($id)
764767
{
765768
$id = strtolower($id);
766769

767770
if (!array_key_exists($id, $this->definitions)) {
768-
throw new InvalidArgumentException(sprintf('The service definition "%s" does not exist.', $id));
771+
throw new ServiceNotFoundException($id);
769772
}
770773

771774
return $this->definitions[$id];
@@ -780,7 +783,7 @@ public function getDefinition($id)
780783
*
781784
* @return Definition A Definition instance
782785
*
783-
* @throws InvalidArgumentException if the service definition does not exist
786+
* @throws ServiceNotFoundException if the service definition does not exist
784787
*/
785788
public function findDefinition($id)
786789
{

src/Symfony/Component/DependencyInjection/Dumper/YamlDumper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ private function addService($id, $definition)
6565
$class = substr($class, 1);
6666
}
6767

68-
$code .= sprintf(" class: %s\n", $class);
68+
$code .= sprintf(" class: %s\n", $this->dumper->dump($class));
6969
}
7070

7171
if (!$definition->isPublic()) {

0 commit comments

Comments
 (0)