1
0
mirror of synced 2025-02-02 21:41:45 +03:00

Write a test case for a custom function override.

This commit is contained in:
Mathew Davies 2017-06-09 10:00:07 +01:00 committed by Luís Cobucci
parent 914c400a7d
commit e4ff7a35a8
No known key found for this signature in database
GPG Key ID: EC61C5F01750ED3C
2 changed files with 39 additions and 1 deletions

View File

@ -3377,7 +3377,7 @@ class Parser
$funcName = strtolower($token['value']);
$customFunctionDeclaration = $this->CustomFunctionDeclaration();
// Check for custom functions functions first!
switch (true) {
case $customFunctionDeclaration !== null:

View File

@ -47,6 +47,24 @@ class CustomFunctionsTest extends OrmFunctionalTestCase
$this->assertEquals(1, count($users));
$this->assertSame($user, $users[0]);
}
public function testCustomFunctionOverride()
{
$user = new CmsUser();
$user->name = 'Bob';
$user->username = 'Dylan';
$this->_em->persist($user);
$this->_em->flush();
$this->_em->getConfiguration()->addCustomStringFunction('COUNT', 'Doctrine\Tests\ORM\Functional\CustomCount');
$query = $this->_em->createQuery('SELECT COUNT(u.id) FROM Doctrine\Tests\Models\CMS\CmsUser u');
$users = $query->getResult();
$this->assertEquals(1, count($users));
$this->assertSame($user, $users[0]);
}
}
class NoOp extends FunctionNode
@ -70,3 +88,23 @@ class NoOp extends FunctionNode
}
}
class CustomCount extends FunctionNode
{
/**
* @var PathExpression
*/
private $field;
public function parse(Parser $parser)
{
$parser->match(Lexer::T_IDENTIFIER);
$parser->match(Lexer::T_OPEN_PARENTHESIS);
$this->field = $parser->StringExpression();
$parser->match(Lexer::T_CLOSE_PARENTHESIS);
}
public function getSql(SqlWalker $sqlWalker)
{
return $this->field->dispatch($sqlWalker);
}
}