Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit af98688

Browse filesBrowse files
armetizfabpot
authored andcommitted
No Entity Manager defined exception
1 parent 0e57c7b commit af98688
Copy full SHA for af98688

File tree

2 files changed

+54
-0
lines changed
Filter options

2 files changed

+54
-0
lines changed

‎src/Symfony/Bridge/Doctrine/Tests/Validator/Constraints/UniqueValidatorTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Doctrine/Tests/Validator/Constraints/UniqueValidatorTest.php
+46Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,4 +367,50 @@ public function testAssociatedCompositeEntity()
367367
);
368368
$violationsList = $validator->validate($associated);
369369
}
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+
}
370416
}

‎src/Symfony/Bridge/Doctrine/Validator/Constraints/UniqueEntityValidator.php

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Doctrine/Validator/Constraints/UniqueEntityValidator.php
+8Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,16 @@ public function validate($entity, Constraint $constraint)
6262

6363
if ($constraint->em) {
6464
$em = $this->registry->getManager($constraint->em);
65+
66+
if (!$em) {
67+
throw new ConstraintDefinitionException(sprintf('Object manager "%s" does not exist.', $constraint->em));
68+
}
6569
} else {
6670
$em = $this->registry->getManagerForClass(get_class($entity));
71+
72+
if (!$em) {
73+
throw new ConstraintDefinitionException(sprintf('Unable to find the object manager associated with an entity of class "%s".', get_class($entity)));
74+
}
6775
}
6876

6977
$className = $this->context->getClassName();

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.