1
0
mirror of synced 2025-01-18 06:21:40 +03:00

test sql generation

This commit is contained in:
Fabio B. Silva 2012-08-11 12:56:47 -03:00
parent ddb2651691
commit e5e45a3a5c
4 changed files with 20 additions and 49 deletions

View File

@ -31,6 +31,7 @@ use Doctrine\ORM\Mapping\ClassMetadata;
* @author Jonathan Wage <jonwage@gmail.com>
* @author Roman Borschel <roman@code-factory.org>
* @author Janne Vanhala <jpvanhal@cc.hut.fi>
* @author Fabio B. Silva <fabio.bat.silva@gmail.com>
*/
class Parser
{
@ -1641,12 +1642,12 @@ class Parser
$className = $this->_lexer->token['value'];
if ( ! class_exists($className, true)) {
$this->semanticalError("Class '$className' is not defined.", $this->_lexer->token);
$this->semanticalError("Class \"$className\" is not defined.", $this->_lexer->token);
}
$class = new \ReflectionClass($className);
if($class->getConstructor() === null) {
$this->semanticalError("Class '$className' has not a valid contructor.", $this->_lexer->token);
$this->semanticalError("Class \"$className\" has not a valid contructor.", $this->_lexer->token);
}
$this->match(Lexer::T_OPEN_PARENTHESIS);
@ -1661,7 +1662,7 @@ class Parser
$this->match(Lexer::T_CLOSE_PARENTHESIS);
if($class->getConstructor()->getNumberOfRequiredParameters() > sizeof($args)) {
$this->semanticalError("Number of arguments does not match definition.", $this->_lexer->token);
$this->semanticalError("Number of arguments does not match.", $this->_lexer->token);
}
return new AST\NewObjectExpression($className, $args);;
@ -1680,9 +1681,6 @@ class Parser
return new AST\SimpleSelectExpression($expression);
case ($this->_lexer->lookahead['type'] === Lexer::T_NEW):
return $this->NewObjectExpression();
default:
if ( ! ($this->_isFunction() || $this->_isAggregateFunction($this->_lexer->lookahead))) {
$this->syntaxError();

View File

@ -34,6 +34,7 @@ use Doctrine\DBAL\LockMode,
* @author Roman Borschel <roman@code-factory.org>
* @author Benjamin Eberlei <kontakt@beberlei.de>
* @author Alexander <iam.asm89@gmail.com>
* @author Fabio B. Silva <fabio.bat.silva@gmail.com>
* @since 2.0
* @todo Rename: SQLWalker
*/
@ -1410,7 +1411,7 @@ class SqlWalker implements TreeWalker
foreach ($newObjectExpression->args as $argIndex => $e) {
$resultAlias = $this->scalarResultCounter++;
$columnAlias = $this->getSQLColumnAlias('sclr') . $resultAlias;
$columnAlias = $this->getSQLColumnAlias('sclr');
switch (true) {
case $e instanceof AST\NewObjectExpression:
@ -1418,13 +1419,13 @@ class SqlWalker implements TreeWalker
break;
default:
$sqlSelectExpressions[] = $e->dispatch($this) . ' AS ' . $columnAlias;
$sqlSelectExpressions[] = trim($e->dispatch($this)) . ' AS ' . $columnAlias;
break;
}
$this->scalarResultAliasMap[$resultAlias] = $columnAlias;
$this->rsm->addScalarResult($columnAlias, $resultAlias, 'string');
$this->rsm->addScalarResult($columnAlias, $resultAlias);
$this->rsm->newObjectMappings[$columnAlias] = array(
'className' => $newObjectExpression->className,
@ -1433,7 +1434,7 @@ class SqlWalker implements TreeWalker
);
}
return implode(',', $sqlSelectExpressions);
return implode(', ', $sqlSelectExpressions);
}
/**

View File

@ -2,12 +2,8 @@
namespace Doctrine\Tests\ORM\Functional;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\DBAL\Connection;
use Doctrine\Tests\Models\CMS\CmsUser;
use Doctrine\Tests\Models\CMS\CmsEmail;
use Doctrine\Tests\Models\CMS\CmsArticle;
use Doctrine\Tests\Models\CMS\CmsAddress;
use Doctrine\Tests\Models\CMS\CmsPhonenumber;
@ -133,40 +129,6 @@ class NewOperatorTest extends \Doctrine\Tests\OrmFunctionalTestCase
$this->assertEquals($this->fixtures[2]->address->city, $result[2]->address);
}
public function testShouldSupportNestedOperators()
{
$this->markTestIncomplete();
$dql = "
SELECT
new Doctrine\Tests\Models\CMS\CmsUserDTO(
u.name,
e.email,
new Doctrine\Tests\Models\CMS\CmsAddressDTO(
a.country,
a.city,
a.zip
)
)
FROM
Doctrine\Tests\Models\CMS\CmsUser u
JOIN
u.email e
JOIN
u.address a
ORDER BY
u.name";
$query = $this->_em->createQuery($dql);
$result = $query->getResult();
$this->assertCount(3, $result);
$this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUserDTO', $result[0]);
$this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUserDTO', $result[1]);
$this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUserDTO', $result[2]);
}
public function testShouldSupportAggregateFunctions()
{
$dql = "

View File

@ -1562,7 +1562,17 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase
{
$this->assertSqlGeneration(
'SELECT new Doctrine\Tests\Models\CMS\CmsUserDTO(u.name, e.email, a.city) FROM Doctrine\Tests\Models\CMS\CmsUser u JOIN u.email e JOIN u.address a',
'SELECT c0_.name AS sclr01, c1_.email AS sclr12, c2_.city AS sclr23 FROM cms_users c0_ INNER JOIN cms_emails c1_ ON c0_.email_id = c1_.id INNER JOIN cms_addresses c2_ ON c0_.id = c2_.user_id'
'SELECT c0_.name AS sclr0, c1_.email AS sclr1, c2_.city AS sclr2 FROM cms_users c0_ INNER JOIN cms_emails c1_ ON c0_.email_id = c1_.id INNER JOIN cms_addresses c2_ ON c0_.id = c2_.user_id'
);
$this->assertSqlGeneration(
'SELECT new Doctrine\Tests\Models\CMS\CmsUserDTO(u.name, e.email, a.city, COUNT(p)) FROM Doctrine\Tests\Models\CMS\CmsUser u JOIN u.email e JOIN u.address a JOIN u.phonenumbers p',
'SELECT c0_.name AS sclr0, c1_.email AS sclr1, c2_.city AS sclr2, COUNT(c3_.phonenumber) AS sclr3 FROM cms_users c0_ INNER JOIN cms_emails c1_ ON c0_.email_id = c1_.id INNER JOIN cms_addresses c2_ ON c0_.id = c2_.user_id INNER JOIN cms_phonenumbers c3_ ON c0_.id = c3_.user_id'
);
$this->assertSqlGeneration(
'SELECT new Doctrine\Tests\Models\CMS\CmsUserDTO(u.name, e.email, a.city, COUNT(p) + u.id) FROM Doctrine\Tests\Models\CMS\CmsUser u JOIN u.email e JOIN u.address a JOIN u.phonenumbers p',
'SELECT c0_.name AS sclr0, c1_.email AS sclr1, c2_.city AS sclr2, COUNT(c3_.phonenumber) + c0_.id AS sclr3 FROM cms_users c0_ INNER JOIN cms_emails c1_ ON c0_.email_id = c1_.id INNER JOIN cms_addresses c2_ ON c0_.id = c2_.user_id INNER JOIN cms_phonenumbers c3_ ON c0_.id = c3_.user_id'
);
}