From fc3dc16f27344d799ef5677d11bfaaab090fc32a Mon Sep 17 00:00:00 2001 From: Ian Phillips Date: Tue, 21 Jul 2015 14:00:59 -0700 Subject: [PATCH 1/4] [Form] added a failing test for EntityType The new test uses an entity whose primary key is a foreign key to another entity (an "association key"), as described here: http://doctrine-orm.readthedocs.org/en/latest/tutorials/composite-primary-keys.html#identity-through-foreign-entities --- .../Tests/Fixtures/AssociationKeyEntity.php | 43 +++++++++++++++++++ .../Tests/Form/Type/EntityTypeTest.php | 23 ++++++++++ 2 files changed, 66 insertions(+) create mode 100644 src/Symfony/Bridge/Doctrine/Tests/Fixtures/AssociationKeyEntity.php diff --git a/src/Symfony/Bridge/Doctrine/Tests/Fixtures/AssociationKeyEntity.php b/src/Symfony/Bridge/Doctrine/Tests/Fixtures/AssociationKeyEntity.php new file mode 100644 index 0000000000000..1fa9a13002e1d --- /dev/null +++ b/src/Symfony/Bridge/Doctrine/Tests/Fixtures/AssociationKeyEntity.php @@ -0,0 +1,43 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Bridge\Doctrine\Tests\Fixtures; + +use Doctrine\ORM\Mapping AS ORM; + +/** + * An entity whose primary key is a foreign key to another entity. + * + * @see http://doctrine-orm.readthedocs.org/en/latest/tutorials/composite-primary-keys.html#use-case-2-simple-derived-identity + * @ORM\Entity + */ +class AssociationKeyEntity +{ + /** + * @ORM\Id @ORM\OneToOne(targetEntity="SingleIntIdEntity") + * @var SingleIntIdEntity + */ + public $single; + + /** + * AssociationKeyEntity constructor. + * @param SingleIntIdEntity $single + */ + public function __construct(SingleIntIdEntity $single) + { + $this->single = $single; + } + + public function getName() + { + return $this->single->name; + } +} diff --git a/src/Symfony/Bridge/Doctrine/Tests/Form/Type/EntityTypeTest.php b/src/Symfony/Bridge/Doctrine/Tests/Form/Type/EntityTypeTest.php index 78f10848bccbf..c8ef6f32a08fe 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/Form/Type/EntityTypeTest.php +++ b/src/Symfony/Bridge/Doctrine/Tests/Form/Type/EntityTypeTest.php @@ -20,6 +20,7 @@ use Symfony\Bridge\Doctrine\Form\DoctrineOrmTypeGuesser; use Symfony\Bridge\Doctrine\Form\Type\EntityType; use Symfony\Bridge\Doctrine\Test\DoctrineTestHelper; +use Symfony\Bridge\Doctrine\Tests\Fixtures\AssociationKeyEntity; use Symfony\Bridge\Doctrine\Tests\Fixtures\CompositeIntIdEntity; use Symfony\Bridge\Doctrine\Tests\Fixtures\CompositeStringIdEntity; use Symfony\Bridge\Doctrine\Tests\Fixtures\GroupableEntity; @@ -42,6 +43,7 @@ class EntityTypeTest extends TypeTestCase const SINGLE_ASSOC_IDENT_CLASS = 'Symfony\Bridge\Doctrine\Tests\Fixtures\SingleAssociationToIntIdEntity'; const COMPOSITE_IDENT_CLASS = 'Symfony\Bridge\Doctrine\Tests\Fixtures\CompositeIntIdEntity'; const COMPOSITE_STRING_IDENT_CLASS = 'Symfony\Bridge\Doctrine\Tests\Fixtures\CompositeStringIdEntity'; + const ASSOCIATION_KEY_CLASS = 'Symfony\Bridge\Doctrine\Tests\Fixtures\AssociationKeyEntity'; /** * @var EntityManager @@ -69,6 +71,7 @@ protected function setUp() $this->em->getClassMetadata(self::SINGLE_ASSOC_IDENT_CLASS), $this->em->getClassMetadata(self::COMPOSITE_IDENT_CLASS), $this->em->getClassMetadata(self::COMPOSITE_STRING_IDENT_CLASS), + $this->em->getClassMetadata(self::ASSOCIATION_KEY_CLASS), ); try { @@ -580,6 +583,26 @@ public function testSubmitMultipleExpandedWithNegativeIntegerId() $this->assertFalse($field['2']->getData()); } + public function testSubmitAssociationKey() + { + $single = new SingleIntIdEntity(1, 'Foo'); + $assoc = new AssociationKeyEntity($single); + + $this->persist(array($single, $assoc)); + + $field = $this->factory->createNamed('name', 'entity', null, array( + 'multiple' => false, + 'expanded' => false, + 'em' => 'default', + 'class' => self::ASSOCIATION_KEY_CLASS, + 'choice_label' => 'name', + )); + + $field->submit('1'); + + $this->assertSame($assoc, $field->getData()); + } + public function testOverrideChoices() { $entity1 = new SingleIntIdEntity(1, 'Foo'); From 53b69a95edfd0da41959d0cf8e26d9b7f7ccfa02 Mon Sep 17 00:00:00 2001 From: Ian Phillips Date: Tue, 21 Jul 2015 14:28:26 -0700 Subject: [PATCH 2/4] Add required whitespace --- .../Bridge/Doctrine/Tests/Fixtures/AssociationKeyEntity.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Symfony/Bridge/Doctrine/Tests/Fixtures/AssociationKeyEntity.php b/src/Symfony/Bridge/Doctrine/Tests/Fixtures/AssociationKeyEntity.php index 1fa9a13002e1d..57e5d0fdd7f5c 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/Fixtures/AssociationKeyEntity.php +++ b/src/Symfony/Bridge/Doctrine/Tests/Fixtures/AssociationKeyEntity.php @@ -23,12 +23,14 @@ class AssociationKeyEntity { /** * @ORM\Id @ORM\OneToOne(targetEntity="SingleIntIdEntity") + * * @var SingleIntIdEntity */ public $single; /** * AssociationKeyEntity constructor. + * * @param SingleIntIdEntity $single */ public function __construct(SingleIntIdEntity $single) From 9333eb74fb6c4cd149d58a04ab4ec5b62b25aeb5 Mon Sep 17 00:00:00 2001 From: Ian Phillips Date: Wed, 22 Jul 2015 10:30:40 -0700 Subject: [PATCH 3/4] [Form] [DoctrineBridge] fixed URL link --- .../Bridge/Doctrine/Tests/Fixtures/AssociationKeyEntity.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Bridge/Doctrine/Tests/Fixtures/AssociationKeyEntity.php b/src/Symfony/Bridge/Doctrine/Tests/Fixtures/AssociationKeyEntity.php index 57e5d0fdd7f5c..30dce3a47578f 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/Fixtures/AssociationKeyEntity.php +++ b/src/Symfony/Bridge/Doctrine/Tests/Fixtures/AssociationKeyEntity.php @@ -16,7 +16,7 @@ /** * An entity whose primary key is a foreign key to another entity. * - * @see http://doctrine-orm.readthedocs.org/en/latest/tutorials/composite-primary-keys.html#use-case-2-simple-derived-identity + * @see http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/tutorials/composite-primary-keys.html#identity-through-foreign-entities * @ORM\Entity */ class AssociationKeyEntity From 046f1e8e27fa2316f5f6c6400b012dc9de086fa1 Mon Sep 17 00:00:00 2001 From: Ian Phillips Date: Tue, 15 Sep 2015 09:34:18 -0700 Subject: [PATCH 4/4] put @ORM annotations on separate lines --- .../Bridge/Doctrine/Tests/Fixtures/AssociationKeyEntity.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Bridge/Doctrine/Tests/Fixtures/AssociationKeyEntity.php b/src/Symfony/Bridge/Doctrine/Tests/Fixtures/AssociationKeyEntity.php index 30dce3a47578f..6032fc79ba079 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/Fixtures/AssociationKeyEntity.php +++ b/src/Symfony/Bridge/Doctrine/Tests/Fixtures/AssociationKeyEntity.php @@ -22,7 +22,8 @@ class AssociationKeyEntity { /** - * @ORM\Id @ORM\OneToOne(targetEntity="SingleIntIdEntity") + * @ORM\Id + * @ORM\OneToOne(targetEntity="SingleIntIdEntity") * * @var SingleIntIdEntity */