17
17
use Doctrine \Common \Persistence \ObjectRepository ;
18
18
use Symfony \Bridge \Doctrine \Test \DoctrineTestHelper ;
19
19
use Symfony \Bridge \Doctrine \Test \TestRepositoryFactory ;
20
+ use Symfony \Bridge \Doctrine \Tests \Fixtures \CompositeObjectNoToStringIdEntity ;
20
21
use Symfony \Bridge \Doctrine \Tests \Fixtures \SingleIntIdEntity ;
21
22
use Symfony \Bridge \Doctrine \Tests \Fixtures \DoubleNameEntity ;
22
23
use Symfony \Bridge \Doctrine \Tests \Fixtures \AssociationEntity ;
@@ -140,6 +141,7 @@ private function createSchema(ObjectManager $em)
140
141
$ em ->getClassMetadata ('Symfony\Bridge\Doctrine\Tests\Fixtures\CompositeIntIdEntity ' ),
141
142
$ em ->getClassMetadata ('Symfony\Bridge\Doctrine\Tests\Fixtures\AssociationEntity ' ),
142
143
$ em ->getClassMetadata ('Symfony\Bridge\Doctrine\Tests\Fixtures\AssociationEntity2 ' ),
144
+ $ em ->getClassMetadata ('Symfony\Bridge\Doctrine\Tests\Fixtures\CompositeObjectNoToStringIdEntity ' ),
143
145
));
144
146
}
145
147
@@ -173,7 +175,7 @@ public function testValidateUniqueness()
173
175
$ this ->buildViolation ('myMessage ' )
174
176
->atPath ('property.path.name ' )
175
177
->setParameter ('{{ value }} ' , '"Foo" ' )
176
- ->setInvalidValue (' Foo ' )
178
+ ->setInvalidValue ($ entity2 )
177
179
->setCode (UniqueEntity::NOT_UNIQUE_ERROR )
178
180
->assertRaised ();
179
181
}
@@ -198,7 +200,7 @@ public function testValidateCustomErrorPath()
198
200
$ this ->buildViolation ('myMessage ' )
199
201
->atPath ('property.path.bar ' )
200
202
->setParameter ('{{ value }} ' , '"Foo" ' )
201
- ->setInvalidValue (' Foo ' )
203
+ ->setInvalidValue ($ entity2 )
202
204
->setCode (UniqueEntity::NOT_UNIQUE_ERROR )
203
205
->assertRaised ();
204
206
}
@@ -417,7 +419,7 @@ public function testAssociatedEntity()
417
419
418
420
$ this ->buildViolation ('myMessage ' )
419
421
->atPath ('property.path.single ' )
420
- ->setParameter ('{{ value }} ' , $ entity1 )
422
+ ->setParameter ('{{ value }} ' , ' object("Symfony\Bridge\Doctrine\Tests\Fixtures\SingleIntIdEntity") identified by (id => 1) ' )
421
423
->setInvalidValue ($ entity1 )
422
424
->setCode (UniqueEntity::NOT_UNIQUE_ERROR )
423
425
->assertRaised ();
@@ -450,12 +452,12 @@ public function testValidateUniquenessNotToStringEntityWithAssociatedEntity()
450
452
451
453
$ this ->validator ->validate ($ associated2 , $ constraint );
452
454
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) ' ;
454
456
455
457
$ this ->buildViolation ('myMessage ' )
456
458
->atPath ('property.path.single ' )
457
- ->setParameter ('{{ value }} ' , ' " ' . $ expectedValue. ' " ' )
458
- ->setInvalidValue ($ expectedValue )
459
+ ->setParameter ('{{ value }} ' , $ expectedValue )
460
+ ->setInvalidValue ($ entity1 )
459
461
->setCode (UniqueEntity::NOT_UNIQUE_ERROR )
460
462
->assertRaised ();
461
463
}
@@ -561,4 +563,38 @@ public function testEntityManagerNullObject()
561
563
562
564
$ this ->validator ->validate ($ entity , $ constraint );
563
565
}
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
+ }
564
600
}
0 commit comments