diff --git a/src/Symfony/Bridge/Doctrine/Form/DataTransformer/EntityToIdTransformer.php b/src/Symfony/Bridge/Doctrine/Form/DataTransformer/EntityToIdTransformer.php index 4be501a425..ccd532917e 100644 --- a/src/Symfony/Bridge/Doctrine/Form/DataTransformer/EntityToIdTransformer.php +++ b/src/Symfony/Bridge/Doctrine/Form/DataTransformer/EntityToIdTransformer.php @@ -65,7 +65,7 @@ class EntityToIdTransformer implements DataTransformerInterface return null; } - if (!is_numeric($key)) { + if (count($this->choiceList->getIdentifier()) > 1 && !is_numeric($key)) { throw new UnexpectedTypeException($key, 'numeric'); } diff --git a/src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/Compiler/RegisterEventListenersAndSubscribersPassTest.php b/src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/Compiler/RegisterEventListenersAndSubscribersPassTest.php new file mode 100644 index 0000000000..daf5b48000 --- /dev/null +++ b/src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/Compiler/RegisterEventListenersAndSubscribersPassTest.php @@ -0,0 +1,26 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ +/* +namespace Symfony\Bundle\DoctrineBundle\Tests\DependencyInjection\Compiler; + +use Symfony\Bundle\DoctrineBundle\DependencyInjection\Compiler\RegisterEventListenersAndSubscribersPass; + +class RegisterEventListenersAndSubscribersPassTest extends TestCase +{ + public function test() + { + $container->getCompilerPassConfig()->setOptimizationPasses(array()); + $container->getCompilerPassConfig()->setBeforeOptimizationPasses(array(new RegisterEventListenersAndSubscribersPass())); + $container->getCompilerPassConfig()->setRemovingPasses(array()); + $container->compile(); + } +} +*/ diff --git a/tests/Symfony/Tests/Bridge/Doctrine/Fixtures/CompositeStringIdentEntity.php b/tests/Symfony/Tests/Bridge/Doctrine/Fixtures/CompositeStringIdentEntity.php new file mode 100644 index 0000000000..2d58dac4d5 --- /dev/null +++ b/tests/Symfony/Tests/Bridge/Doctrine/Fixtures/CompositeStringIdentEntity.php @@ -0,0 +1,22 @@ +id1 = $id1; + $this->id2 = $id2; + $this->name = $name; + } +} diff --git a/tests/Symfony/Tests/Bridge/Doctrine/Fixtures/SingleStringIdentEntity.php b/tests/Symfony/Tests/Bridge/Doctrine/Fixtures/SingleStringIdentEntity.php new file mode 100644 index 0000000000..1e627f0b43 --- /dev/null +++ b/tests/Symfony/Tests/Bridge/Doctrine/Fixtures/SingleStringIdentEntity.php @@ -0,0 +1,18 @@ +id = $id; + $this->name = $name; + } +} diff --git a/tests/Symfony/Tests/Bridge/Doctrine/Form/Type/EntityTypeTest.php b/tests/Symfony/Tests/Bridge/Doctrine/Form/Type/EntityTypeTest.php index 8f8cc60313..f772d71be6 100644 --- a/tests/Symfony/Tests/Bridge/Doctrine/Form/Type/EntityTypeTest.php +++ b/tests/Symfony/Tests/Bridge/Doctrine/Form/Type/EntityTypeTest.php @@ -13,13 +13,17 @@ namespace Symfony\Tests\Bridge\Doctrine\Form\Type; require_once __DIR__.'/../DoctrineOrmTestCase.php'; require_once __DIR__.'/../../Fixtures/SingleIdentEntity.php'; +require_once __DIR__.'/../../Fixtures/SingleStringIdentEntity.php'; require_once __DIR__.'/../../Fixtures/CompositeIdentEntity.php'; +require_once __DIR__.'/../../Fixtures/CompositeStringIdentEntity.php'; use Symfony\Component\Form\Exception\UnexpectedTypeException; use Symfony\Tests\Component\Form\Extension\Core\Type\TypeTestCase; use Symfony\Tests\Bridge\Doctrine\Form\DoctrineOrmTestCase; use Symfony\Tests\Bridge\Doctrine\Form\Fixtures\SingleIdentEntity; +use Symfony\Tests\Bridge\Doctrine\Form\Fixtures\SingleStringIdentEntity; use Symfony\Tests\Bridge\Doctrine\Form\Fixtures\CompositeIdentEntity; +use Symfony\Tests\Bridge\Doctrine\Form\Fixtures\CompositeStringIdentEntity; use Symfony\Bridge\Doctrine\Form\DoctrineOrmExtension; use Doctrine\ORM\Tools\SchemaTool; use Doctrine\ORM\EntityManager; @@ -28,8 +32,9 @@ use Doctrine\Common\Collections\ArrayCollection; class EntityTypeTest extends TypeTestCase { const SINGLE_IDENT_CLASS = 'Symfony\Tests\Bridge\Doctrine\Form\Fixtures\SingleIdentEntity'; - + const SINGLE_STRING_IDENT_CLASS = 'Symfony\Tests\Bridge\Doctrine\Form\Fixtures\SingleStringIdentEntity'; const COMPOSITE_IDENT_CLASS = 'Symfony\Tests\Bridge\Doctrine\Form\Fixtures\CompositeIdentEntity'; + const COMPOSITE_STRING_IDENT_CLASS = 'Symfony\Tests\Bridge\Doctrine\Form\Fixtures\CompositeStringIdentEntity'; private $em; @@ -46,7 +51,9 @@ class EntityTypeTest extends TypeTestCase $schemaTool = new SchemaTool($this->em); $classes = array( $this->em->getClassMetadata(self::SINGLE_IDENT_CLASS), + $this->em->getClassMetadata(self::SINGLE_STRING_IDENT_CLASS), $this->em->getClassMetadata(self::COMPOSITE_IDENT_CLASS), + $this->em->getClassMetadata(self::COMPOSITE_STRING_IDENT_CLASS), ); try { @@ -558,4 +565,47 @@ class EntityTypeTest extends TypeTestCase $this->assertFalse($field->isSynchronized()); $this->assertNull($field->getData()); } -} \ No newline at end of file + + public function testSubmitSingleStringIdentifier() + { + $entity1 = new SingleStringIdentEntity('foo', 'Foo'); + + $this->persist(array($entity1)); + + $field = $this->factory->createNamed('entity', 'name', null, array( + 'multiple' => false, + 'expanded' => false, + 'em' => $this->em, + 'class' => self::SINGLE_STRING_IDENT_CLASS, + 'property' => 'name', + )); + + $field->bind('foo'); + + $this->assertTrue($field->isSynchronized()); + $this->assertEquals($entity1, $field->getData()); + $this->assertEquals('foo', $field->getClientData()); + } + + public function testSubmitCompositeStringIdentifier() + { + $entity1 = new CompositeStringIdentEntity('foo1', 'foo2', 'Foo'); + + $this->persist(array($entity1)); + + $field = $this->factory->createNamed('entity', 'name', null, array( + 'multiple' => false, + 'expanded' => false, + 'em' => $this->em, + 'class' => self::COMPOSITE_STRING_IDENT_CLASS, + 'property' => 'name', + )); + + // the collection key is used here + $field->bind('0'); + + $this->assertTrue($field->isSynchronized()); + $this->assertEquals($entity1, $field->getData()); + $this->assertEquals(0, $field->getClientData()); + } +}