8000 [Form] [DoctrineBridge] added a failing test for EntityType by ianfp · Pull Request #15328 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Form] [DoctrineBridge] added a failing test for EntityType #15328

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Bridge\Doctrine\Tests\Fixtures;

use Doctrine\ORM\Mapping AS ORM;

/**
* An entity whose primary key is a foreign key to another entity.
*
* @see http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/tutorials/composite-primary-keys.html#identity-through-foreign-entities
* @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;
}
}
23 changes: 23 additions & 0 deletions src/Symfony/Bridge/Doctrine/Tests/Form/Type/EntityTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"entity" needs to be replaced by the entity form type FQCN

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hm, actually that only needs to be changed in 2.8 where this has been deprecated. So the merger would need to make the changes.

'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');
Expand Down
0