@@ -367,4 +367,50 @@ public function testAssociatedCompositeEntity()
367
367
);
368
368
$ violationsList = $ validator ->validate ($ associated );
369
369
}
370
+
371
+ public function testDedicatedEntityManagerNullObject ()
372
+ {
373
+ $ uniqueFields = array ('name ' );
374
+ $ entityManagerName = 'foo ' ;
375
+
376
+ $ registry = $ this ->getMock ('Doctrine\Common\Persistence\ManagerRegistry ' );
377
+
378
+ $ constraint = new UniqueEntity (array (
379
+ 'fields ' => $ uniqueFields ,
380
+ 'em ' => $ entityManagerName ,
381
+ ));
382
+
383
+ $ uniqueValidator = new UniqueEntityValidator ($ registry );
384
+
385
+ $ entity = new SingleIntIdEntity (1 , null );
386
+
387
+ $ this ->setExpectedException (
388
+ 'Symfony\Component\Validator\Exception\ConstraintDefinitionException ' ,
389
+ 'Object manager "foo" does not exist. '
390
+ );
391
+
392
+ $ uniqueValidator ->validate ($ entity , $ constraint );
393
+ }
394
+
395
+ public function testEntityManagerNullObject ()
396
+ {
397
+ $ uniqueFields = array ('name ' );
398
+
399
+ $ registry = $ this ->getMock ('Doctrine\Common\Persistence\ManagerRegistry ' );
400
+
401
+ $ constraint = new UniqueEntity (array (
402
+ 'fields ' => $ uniqueFields ,
403
+ ));
404
+
405
+ $ uniqueValidator = new UniqueEntityValidator ($ registry );
406
+
407
+ $ entity = new SingleIntIdEntity (1 , null );
408
+
409
+ $ this ->setExpectedException (
410
+ 'Symfony\Component\Validator\Exception\ConstraintDefinitionException ' ,
411
+ 'Unable to find the object manager associated with an entity of class "Symfony\Bridge\Doctrine\Tests\Fixtures\SingleIntIdEntity" '
412
+ );
413
+
414
+ $ uniqueValidator ->validate ($ entity , $ constraint );
415
+ }
370
416
}
0 commit comments