diff --git a/lib/Doctrine/ORM/Query.php b/lib/Doctrine/ORM/Query.php index 519b2a230..46f002b3e 100644 --- a/lib/Doctrine/ORM/Query.php +++ b/lib/Doctrine/ORM/Query.php @@ -209,12 +209,12 @@ final class Query extends AbstractQuery $paramMappings = $this->_parserResult->getParameterMappings(); if(count($paramMappings) != count($params)) { - throw new QueryException("Invalid parameter number: number of bound variables does not match number of tokens"); + throw QueryException::invalidParameterNumber(); } foreach ($params as $key => $value) { if(!isset($paramMappings[$key])) { - throw new QueryException("Invalid parameter: token ".$key." is not defined in the query."); + throw QueryException::unknownParameter($key); } if (is_object($value)) { diff --git a/lib/Doctrine/ORM/Query/AST/InputParameter.php b/lib/Doctrine/ORM/Query/AST/InputParameter.php index 54d70f93c..cf04d7035 100644 --- a/lib/Doctrine/ORM/Query/AST/InputParameter.php +++ b/lib/Doctrine/ORM/Query/AST/InputParameter.php @@ -43,10 +43,7 @@ class InputParameter extends Node public function __construct($value) { if (strlen($value) == 1) { - throw new \InvalidArgumentException( - "Invalid parameter format, '".$value."' given, ". - "but : or ? expected." - ); + throw \Doctrine\ORM\Query\QueryException::invalidParameterFormat($value); } $param = substr($value, 1); diff --git a/lib/Doctrine/ORM/Query/QueryException.php b/lib/Doctrine/ORM/Query/QueryException.php index 2663b09dd..151c9fa97 100644 --- a/lib/Doctrine/ORM/Query/QueryException.php +++ b/lib/Doctrine/ORM/Query/QueryException.php @@ -34,12 +34,11 @@ namespace Doctrine\ORM\Query; */ class QueryException extends \Doctrine\Common\DoctrineException { - public static function syntaxError($message) + public static function syntaxError($message) { return new self('[Syntax Error] ' . $message); } - public static function semanticalError($message) { return new self('[Semantical Error] ' . $message); @@ -49,4 +48,19 @@ class QueryException extends \Doctrine\Common\DoctrineException { return new self('Invalid parameter position: ' . $pos); } + + public static function invalidParameterNumber() + { + return new self("Invalid parameter number: number of bound variables does not match number of tokens"); + } + + public static function invalidParameterFormat($value) + { + return new self('Invalid parameter format, '.$value.' given, but : or ? expected.'); + } + + public static function unknownParameter($key) + { + return new self("Invalid parameter: token ".$key." is not defined in the query."); + } } \ No newline at end of file diff --git a/tests/Doctrine/Tests/ORM/Functional/QueryTest.php b/tests/Doctrine/Tests/ORM/Functional/QueryTest.php index 108b883f9..614a9d989 100644 --- a/tests/Doctrine/Tests/ORM/Functional/QueryTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/QueryTest.php @@ -130,7 +130,7 @@ class QueryTest extends \Doctrine\Tests\OrmFunctionalTestCase public function testInvalidInputParameterThrowsException() { - $this->setExpectedException("InvalidArgumentException"); + $this->setExpectedException("Doctrine\ORM\Query\QueryException"); $q = $this->_em->createQuery('SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.name = ?'); $q->setParameter(1, 'jwage');