1717use Doctrine \Common \Persistence \ObjectRepository ;
1818use Symfony \Bridge \Doctrine \Test \DoctrineTestHelper ;
1919use Symfony \Bridge \Doctrine \Test \TestRepositoryFactory ;
20+ use Symfony \Bridge \Doctrine \Tests \Fixtures \CompositeObjectNoToStringIdEntity ;
2021use Symfony \Bridge \Doctrine \Tests \Fixtures \SingleIntIdEntity ;
2122use Symfony \Bridge \Doctrine \Tests \Fixtures \DoubleNameEntity ;
2223use Symfony \Bridge \Doctrine \Tests \Fixtures \AssociationEntity ;
@@ -140,6 +141,7 @@ private function createSchema(ObjectManager $em)
140141 $ em ->getClassMetadata ('Symfony\Bridge\Doctrine\Tests\Fixtures\CompositeIntIdEntity ' ),
141142 $ em ->getClassMetadata ('Symfony\Bridge\Doctrine\Tests\Fixtures\AssociationEntity ' ),
142143 $ em ->getClassMetadata ('Symfony\Bridge\Doctrine\Tests\Fixtures\AssociationEntity2 ' ),
144+ $ em ->getClassMetadata ('Symfony\Bridge\Doctrine\Tests\Fixtures\CompositeObjectNoToStringIdEntity ' ),
143145 ));
144146 }
145147
@@ -173,7 +175,7 @@ public function testValidateUniqueness()
173175 $ this ->buildViolation ('myMessage ' )
174176 ->atPath ('property.path.name ' )
175177 ->setParameter ('{{ value }} ' , '"Foo" ' )
176- ->setInvalidValue (' Foo ' )
178+ ->setInvalidValue ($ entity2 )
177179 ->setCode (UniqueEntity::NOT_UNIQUE_ERROR )
178180 ->assertRaised ();
179181 }
@@ -198,7 +200,7 @@ public function testValidateCustomErrorPath()
198200 $ this ->buildViolation ('myMessage ' )
199201 ->atPath ('property.path.bar ' )
200202 ->setParameter ('{{ value }} ' , '"Foo" ' )
201- ->setInvalidValue (' Foo ' )
203+ ->setInvalidValue ($ entity2 )
202204 ->setCode (UniqueEntity::NOT_UNIQUE_ERROR )
203205 ->assertRaised ();
204206 }
@@ -417,7 +419,7 @@ public function testAssociatedEntity()
417419
418420 $ this ->buildViolation ('myMessage ' )
419421 ->atPath ('property.path.single ' )
420- ->setParameter ('{{ value }} ' , $ entity1 )
422+ ->setParameter ('{{ value }} ' , ' object("Symfony\Bridge\Doctrine\Tests\Fixtures\SingleIntIdEntity") identified by (id => 1) ' )
421423 ->setInvalidValue ($ entity1 )
422424 ->setCode (UniqueEntity::NOT_UNIQUE_ERROR )
423425 ->assertRaised ();
@@ -450,12 +452,12 @@ public function testValidateUniquenessNotToStringEntityWithAssociatedEntity()
450452
451453 $ this ->validator ->validate ($ associated2 , $ constraint );
452454
453- $ expectedValue = 'Object of class "Symfony\Bridge\Doctrine\Tests\Fixtures\AssociationEntity2" identified by "2" ' ;
455+ $ expectedValue = 'object( "Symfony\Bridge\Doctrine\Tests\Fixtures\SingleIntIdNoToStringEntity") identified by (id => 1) ' ;
454456
455457 $ this ->buildViolation ('myMessage ' )
456458 ->atPath ('property.path.single ' )
457- ->setParameter ('{{ value }} ' , ' " ' . $ expectedValue. ' " ' )
458- ->setInvalidValue ($ expectedValue )
459+ ->setParameter ('{{ value }} ' , $ expectedValue )
460+ ->setInvalidValue ($ entity1 )
459461 ->setCode (UniqueEntity::NOT_UNIQUE_ERROR )
460462 ->assertRaised ();
461463 }
@@ -561,4 +563,38 @@ public function testEntityManagerNullObject()
561563
562564 $ this ->validator ->validate ($ entity , $ constraint );
563565 }
566+
567+ public function testValidateUniquenessWithCompositeObjectNoToStringIdEntity ()
568+ {
569+ $ constraint = new UniqueEntity (array (
570+ 'message ' => 'myMessage ' ,
571+ 'fields ' => array ('objectOne ' , 'objectTwo ' ),
572+ 'em ' => self ::EM_NAME ,
573+ ));
574+
575+ $ objectOne = new SingleIntIdNoToStringEntity (1 , 'foo ' );
576+ $ objectTwo = new SingleIntIdNoToStringEntity (2 , 'bar ' );
577+
578+ $ this ->em ->persist ($ objectOne );
579+ $ this ->em ->persist ($ objectTwo );
580+ $ this ->em ->flush ();
581+
582+ $ entity = new CompositeObjectNoToStringIdEntity ($ objectOne , $ objectTwo );
583+
584+ $ this ->em ->persist ($ entity );
585+ $ this ->em ->flush ();
586+
587+ $ newEntity = new CompositeObjectNoToStringIdEntity ($ objectOne , $ objectTwo );
588+
589+ $ this ->validator ->validate ($ newEntity , $ constraint );
590+
591+ $ expectedValue = 'object("Symfony\Bridge\Doctrine\Tests\Fixtures\SingleIntIdNoToStringEntity") identified by (id => 1) ' ;
592+
593+ $ this ->buildViolation ('myMessage ' )
594+ ->atPath ('property.path.objectOne ' )
595+ ->setParameter ('{{ value }} ' , $ expectedValue )
596+ ->setInvalidValue ($ objectOne )
597+ ->setCode (UniqueEntity::NOT_UNIQUE_ERROR )
598+ ->assertRaised ();
599+ }
564600}
0 commit comments