Skip to content

Commit c527bf3

Browse files
Merge branch '2.7' into 2.8
* 2.7: prefer phpunit 5.x on hhvm [FrameworkBundle][HttpKernel] the finder is required to discover bundle commands [travis] Auto-conf deps=high matrix line Fix the logout path when not using the router Fix the logout path when not using the router [Form] cast IDs to match deprecated behaviour of EntityChoiceList [HttpFoundation] Added the ability of mapping stream wrapper protocols when using X-Sendfile [HttpFoundation] Add a test case for using BinaryFileResponse with stream wrappers Conflicts: .travis.yml src/Symfony/Bundle/FrameworkBundle/composer.json
2 parents d1a6e03 + 10c5bc4 commit c527bf3

File tree

3 files changed

+194
-1
lines changed

3 files changed

+194
-1
lines changed

Form/ChoiceList/DoctrineChoiceLoader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ public function loadChoicesForValues(array $values, $value = null)
156156
// "INDEX BY" clause to the Doctrine query in the loader,
157157
// but I'm not sure whether that's doable in a generic fashion.
158158
foreach ($unorderedObjects as $object) {
159-
$objectsById[$this->idReader->getIdValue($object)] = $object;
159+
$objectsById[(string) $this->idReader->getIdValue($object)] = $object;
160160
}
161161

162162
foreach ($values as $i => $id) {
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bridge\Doctrine\Tests\Fixtures;
13+
14+
use Doctrine\ORM\Mapping\Column;
15+
use Doctrine\ORM\Mapping\Entity;
16+
use Doctrine\ORM\Mapping\GeneratedValue;
17+
use Doctrine\ORM\Mapping\Id;
18+
19+
/** @Entity */
20+
class SingleStringCastableIdEntity
21+
{
22+
/**
23+
* @Id
24+
* @Column(type="string")
25+
* @GeneratedValue(strategy="NONE")
26+
*/
27+
protected $id;
28+
29+
/** @Column(type="string", nullable=true) */
30+
public $name;
31+
32+
public function __construct($id, $name)
33+
{
34+
$this->id = new StringCastableObjectIdentity($id);
35+
$this->name = $name;
36+
}
37+
38+
public function __toString()
39+
{
40+
return (string) $this->name;
41+
}
42+
}
43+
44+
class StringCastableObjectIdentity
45+
{
46+
protected $id;
47+
48+
public function __construct($id)
49+
{
50+
$this->id = $id;
51+
}
52+
53+
public function __toString()
54+
{
55+
return (string) $this->id;
56+
}
57+
}

Tests/Form/Type/EntityTypeTest.php

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
use Symfony\Bridge\Doctrine\Tests\Fixtures\CompositeStringIdEntity;
2525
use Symfony\Bridge\Doctrine\Tests\Fixtures\GroupableEntity;
2626
use Symfony\Bridge\Doctrine\Tests\Fixtures\SingleIntIdEntity;
27+
use Symfony\Bridge\Doctrine\Tests\Fixtures\SingleStringCastableIdEntity;
2728
use Symfony\Bridge\Doctrine\Tests\Fixtures\SingleStringIdEntity;
2829
use Symfony\Component\Form\ChoiceList\View\ChoiceGroupView;
2930
use Symfony\Component\Form\ChoiceList\View\ChoiceView;
@@ -40,6 +41,7 @@ class EntityTypeTest extends TypeTestCase
4041
const SINGLE_IDENT_NO_TO_STRING_CLASS = 'Symfony\Bridge\Doctrine\Tests\Fixtures\SingleIntIdNoToStringEntity';
4142
const SINGLE_STRING_IDENT_CLASS = 'Symfony\Bridge\Doctrine\Tests\Fixtures\SingleStringIdEntity';
4243
const SINGLE_ASSOC_IDENT_CLASS = 'Symfony\Bridge\Doctrine\Tests\Fixtures\SingleAssociationToIntIdEntity';
44+
const SINGLE_STRING_CASTABLE_IDENT_CLASS = 'Symfony\Bridge\Doctrine\Tests\Fixtures\SingleStringCastableIdEntity';
4345
const COMPOSITE_IDENT_CLASS = 'Symfony\Bridge\Doctrine\Tests\Fixtures\CompositeIntIdEntity';
4446
const COMPOSITE_STRING_IDENT_CLASS = 'Symfony\Bridge\Doctrine\Tests\Fixtures\CompositeStringIdEntity';
4547

@@ -67,6 +69,7 @@ protected function setUp()
6769
$this->em->getClassMetadata(self::SINGLE_IDENT_NO_TO_STRING_CLASS),
6870
$this->em->getClassMetadata(self::SINGLE_STRING_IDENT_CLASS),
6971
$this->em->getClassMetadata(self::SINGLE_ASSOC_IDENT_CLASS),
72+
$this->em->getClassMetadata(self::SINGLE_STRING_CASTABLE_IDENT_CLASS),
7073
$this->em->getClassMetadata(self::COMPOSITE_IDENT_CLASS),
7174
$this->em->getClassMetadata(self::COMPOSITE_STRING_IDENT_CLASS),
7275
);
@@ -606,6 +609,139 @@ public function testSubmitMultipleExpandedWithNegativeIntegerId()
606609
$this->assertFalse($field['2']->getData());
607610
}
608611

612+
public function testSubmitSingleNonExpandedStringCastableIdentifier()
613+
{
614+
$entity1 = new SingleStringCastableIdEntity(1, 'Foo');
615+
$entity2 = new SingleStringCastableIdEntity(2, 'Bar');
616+
617+
$this->persist(array($entity1, $entity2));
618+
619+
$field = $this->factory->createNamed('name', 'entity', null, array(
620+
'multiple' => false,
621+
'expanded' => false,
622+
'em' => 'default',
623+
'class' => self::SINGLE_STRING_CASTABLE_IDENT_CLASS,
624+
'choice_label' => 'name',
625+
));
626+
627+
$field->submit('2');
628+
629+
$this->assertTrue($field->isSynchronized());
630+
$this->assertSame($entity2, $field->getData());
631+
$this->assertSame('2', $field->getViewData());
632+
}
633+
634+
public function testSubmitSingleStringCastableIdentifierExpanded()
635+
{
636+
$entity1 = new SingleStringCastableIdEntity(1, 'Foo');
637+
$entity2 = new SingleStringCastableIdEntity(2, 'Bar');
638+
639+
$this->persist(array($entity1, $entity2));
640+
641+
$field = $this->factory->createNamed('name', 'entity', null, array(
642+
'multiple' => false,
643+
'expanded' => true,
644+
'em' => 'default',
645+
'class' => self::SINGLE_STRING_CASTABLE_IDENT_CLASS,
646+
'choice_label' => 'name',
647+
));
648+
649+
$field->submit('2');
650+
651+
$this->assertTrue($field->isSynchronized());
652+
$this->assertSame($entity2, $field->getData());
653+
$this->assertFalse($field['0']->getData());
654+
$this->assertTrue($field['1']->getData());
655+
$this->assertNull($field['0']->getViewData());
656+
$this->assertSame('2', $field['1']->getViewData());
657+
}
658+
659+
public function testSubmitMultipleNonExpandedStringCastableIdentifierForExistingData()
660+
{
661+
$entity1 = new SingleStringCastableIdEntity(1, 'Foo');
662+
$entity2 = new SingleStringCastableIdEntity(2, 'Bar');
663+
$entity3 = new SingleStringCastableIdEntity(3, 'Baz');
664+
665+
$this->persist(array($entity1, $entity2, $entity3));
666+
667+
$field = $this->factory->createNamed('name', 'entity', null, array(
668+
'multiple' => true,
669+
'expanded' => false,
670+
'em' => 'default',
671+
'class' => self::SINGLE_STRING_CASTABLE_IDENT_CLASS,
672+
'choice_label' => 'name',
673+
));
674+
675+
$existing = new ArrayCollection(array(0 => $entity2));
676+
677+
$field->setData($existing);
678+
$field->submit(array('1', '3'));
679+
680+
// entry with index 0 ($entity2) was replaced
681+
$expected = new ArrayCollection(array(0 => $entity1, 1 => $entity3));
682+
683+
$this->assertTrue($field->isSynchronized());
684+
$this->assertEquals($expected, $field->getData());
685+
// same object still, useful if it is a PersistentCollection
686+
$this->assertSame($existing, $field->getData());
687+
$this->assertSame(array('1', '3'), $field->getViewData());
688+
}
689+
690+
public function testSubmitMultipleNonExpandedStringCastableIdentifier()
691+
{
692+
$entity1 = new SingleStringCastableIdEntity(1, 'Foo');
693+
$entity2 = new SingleStringCastableIdEntity(2, 'Bar');
694+
$entity3 = new SingleStringCastableIdEntity(3, 'Baz');
695+
696+
$this->persist(array($entity1, $entity2, $entity3));
697+
698+
$field = $this->factory->createNamed('name', 'entity', null, array(
699+
'multiple' => true,
700+
'expanded' => false,
701+
'em' => 'default',
702+
'class' => self::SINGLE_STRING_CASTABLE_IDENT_CLASS,
703+
'choice_label' => 'name',
704+
));
705+
706+
$field->submit(array('1', '3'));
707+
708+
$expected = new ArrayCollection(array($entity1, $entity3));
709+
710+
$this->assertTrue($field->isSynchronized());
711+
$this->assertEquals($expected, $field->getData());
712+
$this->assertSame(array('1', '3'), $field->getViewData());
713+
}
714+
715+
public function testSubmitMultipleStringCastableIdentifierExpanded()
716+
{
717+
$entity1 = new SingleStringCastableIdEntity(1, 'Foo');
718+
$entity2 = new SingleStringCastableIdEntity(2, 'Bar');
719+
$entity3 = new SingleStringCastableIdEntity(3, 'Bar');
720+
721+
$this->persist(array($entity1, $entity2, $entity3));
722+
723+
$field = $this->factory->createNamed('name', 'entity', null, array(
724+
'multiple' => true,
725+
'expanded' => true,
726+
'em' => 'default',
727+
'class' => self::SINGLE_STRING_CASTABLE_IDENT_CLASS,
728+
'choice_label' => 'name',
729+
));
730+
731+
$field->submit(array('1', '3'));
732+
733+
$expected = new ArrayCollection(array($entity1, $entity3));
734+
735+
$this->assertTrue($field->isSynchronized());
736+
$this->assertEquals($expected, $field->getData());
737+
$this->assertTrue($field['0']->getData());
738+
$this->assertFalse($field['1']->getData());
739+
$this->assertTrue($field['2']->getData());
740+
$this->assertSame('1', $field['0']->getViewData());
741+
$this->assertNull($field['1']->getViewData());
742+
$this->assertSame('3', $field['2']->getViewData());
743+
}
744+
609745
public function testOverrideChoices()
610746
{
611747
$entity1 = new SingleIntIdEntity(1, 'Foo');

0 commit comments

Comments
 (0)