Commit 96a79b62 authored by guilhermeblanco's avatar guilhermeblanco

[2.0][DDC-362] Fixed missing namespace declaration on __call method of...

[2.0][DDC-362] Fixed missing namespace declaration on __call method of EntityRepository. Thanks Marcel Walter for the patch.
parent 50190c64
......@@ -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);
}
}
}
\ No newline at end of file
......@@ -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');
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment