[2.0][DDC-362] Fixed missing namespace declaration on __call method of EntityRepository. Thanks Marcel Walter for the patch.
This commit is contained in:
parent
50190c64d3
commit
96a79b62b9
@ -160,11 +160,14 @@ class EntityRepository
|
||||
$by = substr($method, 9, strlen($method));
|
||||
$method = 'findOneBy';
|
||||
} else {
|
||||
throw new \BadMethodCallException("Undefined method '$method'.");
|
||||
throw new \BadMethodCallException(
|
||||
"Undefined method '$method'. The method name must start with ".
|
||||
"either findBy or findOneBy!"
|
||||
);
|
||||
}
|
||||
|
||||
if ( ! isset($arguments[0])) {
|
||||
throw DoctrineException::findByNameRequired();
|
||||
throw ORMException::findByRequiresParameter($method.$by);
|
||||
}
|
||||
|
||||
$fieldName = lcfirst(\Doctrine\Common\Util\Inflector::classify($by));
|
||||
@ -172,7 +175,7 @@ class EntityRepository
|
||||
if ($this->_class->hasField($fieldName)) {
|
||||
return $this->$method(array($fieldName => $arguments[0]));
|
||||
} else {
|
||||
throw \Doctrine\Common\DoctrineException::invalidFindBy($by);
|
||||
throw ORMException::invalidFindByCall($this->_entityName, $fieldName, $method.$by);
|
||||
}
|
||||
}
|
||||
}
|
@ -56,4 +56,15 @@ class ORMException extends \Exception
|
||||
{
|
||||
return new self("Cannot use different EventManager instances for EntityManager and Connection.");
|
||||
}
|
||||
|
||||
public static function findByRequiresParameter($methodName) {
|
||||
return new self("You need to pass a parameter to '".$methodName."'");
|
||||
}
|
||||
|
||||
public static function invalidFindByCall($entityName, $fieldName, $method) {
|
||||
return new self(
|
||||
"Entity '".$entityName."' has no field '".$fieldName."'. ".
|
||||
"You can therefore not call '".$method."' on the entities' repository"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -66,5 +66,21 @@ class EntityRepositoryTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
$users = $repos->findAll();
|
||||
$this->assertEquals(2, count($users));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Doctrine\ORM\ORMException
|
||||
*/
|
||||
public function testExceptionIsThrownWhenCallingFindByWithoutParameter() {
|
||||
$this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser')
|
||||
->findByStatus();
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Doctrine\ORM\ORMException
|
||||
*/
|
||||
public function testExceptionIsThrownWhenUsingInvalidFieldName() {
|
||||
$this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser')
|
||||
->findByThisFieldDoesNotExist('testvalue');
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user