1
0
mirror of synced 2024-12-14 07:06:04 +03:00
doctrine2/tests/Doctrine/Tests/ORM/Query/LanguageRecognitionTest.php

602 lines
22 KiB
PHP
Raw Normal View History

2008-05-24 22:18:37 +04:00
<?php
namespace Doctrine\Tests\ORM\Query;
use Doctrine\ORM\Query,
Doctrine\ORM\Query\QueryException;
require_once __DIR__ . '/../../TestInit.php';
class LanguageRecognitionTest extends \Doctrine\Tests\OrmTestCase
2008-05-24 22:18:37 +04:00
{
private $_em;
protected function setUp()
{
$this->_em = $this->_getTestEntityManager();
}
public function assertValidDQL($dql, $debug = false)
2008-05-24 22:18:37 +04:00
{
try {
$parserResult = $this->parseDql($dql);
} catch (QueryException $e) {
if ($debug) {
echo $e->getTraceAsString() . PHP_EOL;
}
2011-12-20 01:56:19 +04:00
2008-05-24 22:18:37 +04:00
$this->fail($e->getMessage());
}
}
public function assertInvalidDQL($dql, $debug = false)
2008-05-24 22:18:37 +04:00
{
try {
$parserResult = $this->parseDql($dql);
2011-12-20 01:56:19 +04:00
2008-05-24 22:18:37 +04:00
$this->fail('No syntax errors were detected, when syntax errors were expected');
} catch (QueryException $e) {
if ($debug) {
echo $e->getMessage() . PHP_EOL;
echo $e->getTraceAsString() . PHP_EOL;
}
2008-05-24 22:18:37 +04:00
}
}
2011-12-20 01:56:19 +04:00
public function parseDql($dql, $hints = array())
{
$query = $this->_em->createQuery($dql);
$query->setHint(Query::HINT_FORCE_PARTIAL_LOAD, true);
$query->setDql($dql);
2011-12-20 01:56:19 +04:00
foreach ($hints as $key => $value) {
$query->setHint($key, $value);
}
2011-12-20 01:56:19 +04:00
$parser = new \Doctrine\ORM\Query\Parser($query);
2011-12-20 01:56:19 +04:00
// We do NOT test SQL output here. That only unnecessarily slows down the tests!
$parser->setCustomOutputTreeWalker('Doctrine\Tests\Mocks\MockTreeWalker');
2011-12-20 01:56:19 +04:00
return $parser->parse();
}
2011-12-20 01:56:19 +04:00
2008-05-24 22:18:37 +04:00
public function testEmptyQueryString()
{
$this->assertInvalidDQL('');
2008-05-24 22:18:37 +04:00
}
public function testPlainFromClauseWithAlias()
{
$this->assertValidDQL('SELECT u.id FROM Doctrine\Tests\Models\CMS\CmsUser u');
2008-05-24 22:18:37 +04:00
}
public function testSelectSingleComponentWithAsterisk()
{
$this->assertValidDQL('SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u');
2008-05-24 22:18:37 +04:00
}
public function testSelectSingleComponentWithMultipleColumns()
{
$this->assertValidDQL('SELECT u.name, u.username FROM Doctrine\Tests\Models\CMS\CmsUser u');
2008-05-24 22:18:37 +04:00
}
public function testSelectMultipleComponentsUsingMultipleFrom()
{
$this->assertValidDQL('SELECT u, p FROM Doctrine\Tests\Models\CMS\CmsUser u, Doctrine\Tests\Models\CMS\CmsPhonenumber p WHERE u = p.user');
}
2008-05-24 22:18:37 +04:00
public function testSelectMultipleComponentsWithAsterisk()
{
$this->assertValidDQL('SELECT u, p FROM Doctrine\Tests\Models\CMS\CmsUser u JOIN u.phonenumbers p');
2008-05-24 22:18:37 +04:00
}
public function testSelectDistinctIsSupported()
{
$this->assertValidDQL('SELECT DISTINCT u.name FROM Doctrine\Tests\Models\CMS\CmsUser u');
2008-05-24 22:18:37 +04:00
}
public function testAggregateFunctionInSelect()
{
$this->assertValidDQL('SELECT COUNT(u.id) FROM Doctrine\Tests\Models\CMS\CmsUser u');
}
2011-12-20 01:56:19 +04:00
public function testDuplicatedAliasInAggregateFunction()
{
$this->assertInvalidDQL('SELECT COUNT(u.id) AS num, SUM(u.id) AS num FROM Doctrine\Tests\Models\CMS\CmsUser u');
2008-05-24 22:18:37 +04:00
}
public function testAggregateFunctionWithDistinctInSelect()
{
$this->assertValidDQL('SELECT COUNT(DISTINCT u.name) FROM Doctrine\Tests\Models\CMS\CmsUser u');
2008-05-24 22:18:37 +04:00
}
2009-03-15 00:19:50 +03:00
2008-05-24 22:18:37 +04:00
public function testFunctionalExpressionsSupportedInWherePart()
{
$this->assertValidDQL("SELECT u.name FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE TRIM(u.name) = 'someone'");
2008-05-24 22:18:37 +04:00
}
2009-03-15 00:19:50 +03:00
2008-05-24 22:18:37 +04:00
public function testArithmeticExpressionsSupportedInWherePart()
{
$this->assertValidDQL('SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE ((u.id + 5000) * u.id + 3) < 10000000');
2008-05-24 22:18:37 +04:00
}
2011-12-20 01:56:19 +04:00
2008-05-24 22:18:37 +04:00
public function testInExpressionSupportedInWherePart()
{
$this->assertValidDQL('SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id IN (1, 2)');
2008-05-24 22:18:37 +04:00
}
2011-12-20 01:56:19 +04:00
public function testInExpressionWithoutSpacesSupportedInWherePart()
{
$this->assertValidDQL('SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id IN (1,2,3)');
}
2008-05-24 22:18:37 +04:00
public function testNotInExpressionSupportedInWherePart()
{
$this->assertValidDQL('SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id NOT IN (1)');
2008-05-24 22:18:37 +04:00
}
2009-03-17 01:12:38 +03:00
public function testInExpressionWithSingleValuedAssociationPathExpression()
{
$this->assertValidDQL("SELECT u FROM Doctrine\Tests\Models\Forum\ForumUser u WHERE u.avatar IN (?1, ?2)");
}
public function testInvalidInExpressionWithCollectionValuedAssociationPathExpression()
{
$this->assertInvalidDQL("SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.phonenumbers IN (?1, ?2)");
}
public function testInstanceOfExpressionSupportedInWherePart()
{
$this->assertValidDQL('SELECT u FROM Doctrine\Tests\Models\Company\CompanyPerson u WHERE u INSTANCE OF Doctrine\Tests\Models\Company\CompanyEmployee');
}
public function testInstanceOfExpressionWithInputParamSupportedInWherePart()
{
$this->assertValidDQL('SELECT u FROM Doctrine\Tests\Models\Company\CompanyPerson u WHERE u INSTANCE OF ?1');
}
public function testNotInstanceOfExpressionSupportedInWherePart()
{
$this->assertValidDQL('SELECT u FROM Doctrine\Tests\Models\Company\CompanyPerson u WHERE u NOT INSTANCE OF ?1');
}
2011-12-20 01:56:19 +04:00
2009-03-15 00:19:50 +03:00
public function testExistsExpressionSupportedInWherePart()
2008-05-24 22:18:37 +04:00
{
$this->assertValidDQL('SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE EXISTS (SELECT p.phonenumber FROM Doctrine\Tests\Models\CMS\CmsPhonenumber p WHERE p.phonenumber = 1234)');
2008-05-24 22:18:37 +04:00
}
2009-03-19 15:43:48 +03:00
2008-05-24 22:18:37 +04:00
public function testNotExistsExpressionSupportedInWherePart()
{
$this->assertValidDQL('SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE NOT EXISTS (SELECT p.phonenumber FROM Doctrine\Tests\Models\CMS\CmsPhonenumber p WHERE p.phonenumber = 1234)');
2008-05-24 22:18:37 +04:00
}
2009-03-19 15:43:48 +03:00
public function testAggregateFunctionInHavingClause()
2008-05-24 22:18:37 +04:00
{
$this->assertValidDQL('SELECT u.name FROM Doctrine\Tests\Models\CMS\CmsUser u LEFT JOIN u.phonenumbers p HAVING COUNT(p.phonenumber) > 2');
$this->assertValidDQL("SELECT u.name FROM Doctrine\Tests\Models\CMS\CmsUser u LEFT JOIN u.phonenumbers p HAVING MAX(u.name) = 'romanb'");
2008-05-24 22:18:37 +04:00
}
2009-03-19 15:43:48 +03:00
public function testLeftJoin()
2008-05-24 22:18:37 +04:00
{
$this->assertValidDQL('SELECT u, p FROM Doctrine\Tests\Models\CMS\CmsUser u LEFT JOIN u.phonenumbers p');
2008-05-24 22:18:37 +04:00
}
2009-03-19 15:43:48 +03:00
public function testJoin()
2008-05-24 22:18:37 +04:00
{
$this->assertValidDQL('SELECT u,p FROM Doctrine\Tests\Models\CMS\CmsUser u JOIN u.phonenumbers p');
2008-05-24 22:18:37 +04:00
}
2009-03-19 15:43:48 +03:00
public function testInnerJoin()
2008-05-24 22:18:37 +04:00
{
$this->assertValidDQL('SELECT u, p FROM Doctrine\Tests\Models\CMS\CmsUser u INNER JOIN u.phonenumbers p');
2008-05-24 22:18:37 +04:00
}
2009-03-19 15:43:48 +03:00
public function testMultipleLeftJoin()
2008-05-24 22:18:37 +04:00
{
$this->assertValidDQL('SELECT u, a, p FROM Doctrine\Tests\Models\CMS\CmsUser u LEFT JOIN u.articles a LEFT JOIN u.phonenumbers p');
2008-05-24 22:18:37 +04:00
}
2009-03-19 15:43:48 +03:00
public function testMultipleInnerJoin()
2008-05-24 22:18:37 +04:00
{
$this->assertValidDQL('SELECT u.name FROM Doctrine\Tests\Models\CMS\CmsUser u INNER JOIN u.articles a INNER JOIN u.phonenumbers p');
2008-05-24 22:18:37 +04:00
}
2009-03-19 15:43:48 +03:00
public function testMixingOfJoins()
2008-05-24 22:18:37 +04:00
{
$this->assertValidDQL('SELECT u.name, a.topic, p.phonenumber FROM Doctrine\Tests\Models\CMS\CmsUser u INNER JOIN u.articles a LEFT JOIN u.phonenumbers p');
2008-05-24 22:18:37 +04:00
}
2009-03-19 15:43:48 +03:00
public function testOrderBySingleColumn()
2008-05-24 22:18:37 +04:00
{
$this->assertValidDQL('SELECT u.name FROM Doctrine\Tests\Models\CMS\CmsUser u ORDER BY u.name');
2008-05-24 22:18:37 +04:00
}
2009-03-19 15:43:48 +03:00
public function testOrderBySingleColumnAscending()
2008-05-24 22:18:37 +04:00
{
$this->assertValidDQL('SELECT u.name FROM Doctrine\Tests\Models\CMS\CmsUser u ORDER BY u.name ASC');
2008-05-24 22:18:37 +04:00
}
2009-03-19 15:43:48 +03:00
public function testOrderBySingleColumnDescending()
2008-05-24 22:18:37 +04:00
{
$this->assertValidDQL('SELECT u.name FROM Doctrine\Tests\Models\CMS\CmsUser u ORDER BY u.name DESC');
2008-05-24 22:18:37 +04:00
}
2009-03-19 15:43:48 +03:00
public function testOrderByMultipleColumns()
2008-05-24 22:18:37 +04:00
{
$this->assertValidDQL('SELECT u.name, u.username FROM Doctrine\Tests\Models\CMS\CmsUser u ORDER BY u.username DESC, u.name DESC');
2008-05-24 22:18:37 +04:00
}
2009-03-19 15:43:48 +03:00
public function testSubselectInInExpression()
2008-05-24 22:18:37 +04:00
{
$this->assertValidDQL("SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id NOT IN (SELECT u2.id FROM Doctrine\Tests\Models\CMS\CmsUser u2 WHERE u2.name = 'zYne')");
2008-05-24 22:18:37 +04:00
}
2009-03-19 15:43:48 +03:00
public function testSubselectInSelectPart()
2008-05-24 22:18:37 +04:00
{
$this->assertValidDQL("SELECT u.name, (SELECT COUNT(p.phonenumber) FROM Doctrine\Tests\Models\CMS\CmsPhonenumber p WHERE p.phonenumber = 1234) pcount FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.name = 'jon'");
2008-05-24 22:18:37 +04:00
}
public function testArithmeticExpressionInSelectPart()
2010-07-15 17:55:35 +04:00
{
$this->assertValidDQL("SELECT SUM(u.id) / COUNT(u.id) FROM Doctrine\Tests\Models\CMS\CmsUser u");
}
2010-07-15 17:55:35 +04:00
public function testArithmeticExpressionInSubselectPart()
2010-07-15 17:55:35 +04:00
{
$this->assertValidDQL("SELECT (SELECT SUM(u.id) / COUNT(u.id) FROM Doctrine\Tests\Models\CMS\CmsUser u2) value FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.name = 'jon'");
}
public function testArithmeticExpressionWithParenthesisInSubselectPart()
{
$this->assertValidDQL("SELECT (SELECT (SUM(u.id) / COUNT(u.id)) FROM Doctrine\Tests\Models\CMS\CmsUser u2) value FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.name = 'jon'");
}
/**
* @group DDC-1079
*/
public function testSelectLiteralInSubselect()
{
$this->assertValidDQL('SELECT (SELECT 1 FROM Doctrine\Tests\Models\CMS\CmsUser u2) value FROM Doctrine\Tests\Models\CMS\CmsUser u');
$this->assertValidDQL('SELECT (SELECT 0 FROM Doctrine\Tests\Models\CMS\CmsUser u2) value FROM Doctrine\Tests\Models\CMS\CmsUser u');
}
/**
* @group DDC-1077
*/
public function testConstantValueInSelect()
{
$this->assertValidDQL("SELECT u.name, 'foo' AS bar FROM Doctrine\Tests\Models\CMS\CmsUser u", true);
}
public function testDuplicateAliasInSubselectPart()
{
$this->assertInvalidDQL("SELECT (SELECT SUM(u.id) / COUNT(u.id) AS foo FROM Doctrine\Tests\Models\CMS\CmsUser u2) foo FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.name = 'jon'");
}
2010-07-15 17:55:35 +04:00
2009-03-19 15:43:48 +03:00
public function testPositionalInputParameter()
2008-05-24 22:18:37 +04:00
{
$this->assertValidDQL('SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id = ?1');
2008-05-24 22:18:37 +04:00
}
2009-03-19 15:43:48 +03:00
public function testNamedInputParameter()
2008-05-24 22:18:37 +04:00
{
$this->assertValidDQL('SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id = :id');
2008-05-24 22:18:37 +04:00
}
public function testJoinConditionOverrideNotSupported()
2008-05-24 22:18:37 +04:00
{
$this->assertInvalidDQL("SELECT u.name, p FROM Doctrine\Tests\Models\CMS\CmsUser u LEFT JOIN u.phonenumbers p ON p.phonenumber = '123 123'");
2008-05-24 22:18:37 +04:00
}
2009-03-19 15:43:48 +03:00
public function testIndexByClauseWithOneComponent()
2008-05-24 22:18:37 +04:00
{
$this->assertValidDQL('SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u INDEX BY u.id');
2008-05-24 22:18:37 +04:00
}
2009-03-19 15:43:48 +03:00
public function testIndexBySupportsJoins()
2008-05-24 22:18:37 +04:00
{
$this->assertValidDQL('SELECT u, a FROM Doctrine\Tests\Models\CMS\CmsUser u LEFT JOIN u.articles a INDEX BY a.id'); // INDEX BY is now referring to articles
2008-05-24 22:18:37 +04:00
}
2009-03-19 15:43:48 +03:00
public function testIndexBySupportsJoins2()
2008-05-24 22:18:37 +04:00
{
$this->assertValidDQL('SELECT u, p FROM Doctrine\Tests\Models\CMS\CmsUser u INDEX BY u.id LEFT JOIN u.phonenumbers p INDEX BY p.phonenumber');
2008-05-24 22:18:37 +04:00
}
2009-03-19 15:43:48 +03:00
public function testBetweenExpressionSupported()
2008-05-24 22:18:37 +04:00
{
$this->assertValidDQL("SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.name BETWEEN 'jepso' AND 'zYne'");
2008-05-24 22:18:37 +04:00
}
2009-03-19 15:43:48 +03:00
public function testNotBetweenExpressionSupported()
2008-05-24 22:18:37 +04:00
{
$this->assertValidDQL("SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.name NOT BETWEEN 'jepso' AND 'zYne'");
2008-05-24 22:18:37 +04:00
}
2009-03-19 15:43:48 +03:00
public function testLikeExpression()
2008-05-24 22:18:37 +04:00
{
$this->assertValidDQL("SELECT u.id FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.name LIKE 'z%'");
2008-05-24 22:18:37 +04:00
}
2009-03-19 15:43:48 +03:00
public function testNotLikeExpression()
2008-05-24 22:18:37 +04:00
{
$this->assertValidDQL("SELECT u.id FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.name NOT LIKE 'z%'");
2008-05-24 22:18:37 +04:00
}
2009-03-19 15:43:48 +03:00
public function testLikeExpressionWithCustomEscapeCharacter()
2008-05-24 22:18:37 +04:00
{
$this->assertValidDQL("SELECT u.id FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.name LIKE 'z|%' ESCAPE '|'");
2008-05-24 22:18:37 +04:00
}
public function testFieldComparisonWithoutAlias()
{
$this->assertInvalidDQL("SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE id = 1");
}
2011-12-20 01:56:19 +04:00
public function testDuplicatedAliasDeclaration()
{
$this->assertInvalidDQL("SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u INNER JOIN u.articles u WHERE u.id = 1");
}
public function testImplicitJoinInWhereOnSingleValuedAssociationPathExpression()
2008-05-24 22:18:37 +04:00
{
2009-03-19 15:43:48 +03:00
// This should be allowed because avatar is a single-value association.
// SQL: SELECT ... FROM forum_user fu INNER JOIN forum_avatar fa ON fu.avatar_id = fa.id WHERE fa.id = ?
$this->assertValidDQL("SELECT u FROM Doctrine\Tests\Models\Forum\ForumUser u JOIN u.avatar a WHERE a.id = ?1");
}
2009-03-19 15:43:48 +03:00
public function testImplicitJoinInWhereOnCollectionValuedPathExpression()
2008-05-24 22:18:37 +04:00
{
2009-03-19 15:43:48 +03:00
// This should be forbidden, because articles is a collection
$this->assertInvalidDQL("SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u JOIN u.articles a WHERE a.title = ?");
2008-05-24 22:18:37 +04:00
}
2009-03-19 15:43:48 +03:00
public function testInvalidSyntaxIsRejected()
2008-05-24 22:18:37 +04:00
{
$this->assertInvalidDQL("FOOBAR CmsUser");
$this->assertInvalidDQL("DELETE FROM Doctrine\Tests\Models\CMS\CmsUser.articles");
$this->assertInvalidDQL("SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u JOIN u.articles.comments");
2009-03-19 15:43:48 +03:00
// Currently UNDEFINED OFFSET error
$this->assertInvalidDQL("SELECT c FROM CmsUser.articles.comments c");
2008-05-24 22:18:37 +04:00
}
2009-03-19 15:43:48 +03:00
public function testUpdateWorksWithOneField()
2008-05-24 22:18:37 +04:00
{
$this->assertValidDQL("UPDATE Doctrine\Tests\Models\CMS\CmsUser u SET u.name = 'someone'");
2008-05-24 22:18:37 +04:00
}
2009-03-19 15:43:48 +03:00
public function testUpdateWorksWithMultipleFields()
2008-05-24 22:18:37 +04:00
{
$this->assertValidDQL("UPDATE Doctrine\Tests\Models\CMS\CmsUser u SET u.name = 'someone', u.username = 'some'");
2008-05-24 22:18:37 +04:00
}
2009-03-19 15:43:48 +03:00
public function testUpdateSupportsConditions()
2008-05-24 22:18:37 +04:00
{
$this->assertValidDQL("UPDATE Doctrine\Tests\Models\CMS\CmsUser u SET u.name = 'someone' WHERE u.id = 5");
2008-05-24 22:18:37 +04:00
}
2009-03-19 15:43:48 +03:00
public function testDeleteAll()
2008-05-24 22:18:37 +04:00
{
$this->assertValidDQL('DELETE FROM Doctrine\Tests\Models\CMS\CmsUser u');
2008-05-24 22:18:37 +04:00
}
2009-03-19 15:43:48 +03:00
public function testDeleteWithCondition()
2008-05-24 22:18:37 +04:00
{
$this->assertValidDQL('DELETE FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id = 3');
2008-05-24 22:18:37 +04:00
}
2009-03-19 15:43:48 +03:00
/**
* The main use case for this generalized style of join is when a join condition
* does not involve a foreign key relationship that is mapped to an entity relationship.
*/
public function testImplicitJoinWithCartesianProductAndConditionInWhere()
2008-05-24 22:18:37 +04:00
{
$this->assertValidDQL("SELECT u, a FROM Doctrine\Tests\Models\CMS\CmsUser u, Doctrine\Tests\Models\CMS\CmsArticle a WHERE u.name = a.topic");
2008-05-24 22:18:37 +04:00
}
public function testAllExpressionWithCorrelatedSubquery()
2008-05-24 22:18:37 +04:00
{
$this->assertValidDQL('SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id > ALL (SELECT u2.id FROM Doctrine\Tests\Models\CMS\CmsUser u2 WHERE u2.name = u.name)');
2008-05-24 22:18:37 +04:00
}
public function testCustomJoinsAndWithKeywordSupported()
2008-05-24 22:18:37 +04:00
{
$this->assertValidDQL('SELECT u, p FROM Doctrine\Tests\Models\CMS\CmsUser u INNER JOIN u.phonenumbers p WITH p.phonenumber = 123 WHERE u.id = 1');
2008-05-24 22:18:37 +04:00
}
public function testAnyExpressionWithCorrelatedSubquery()
2008-05-24 22:18:37 +04:00
{
$this->assertValidDQL('SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id > ANY (SELECT u2.id FROM Doctrine\Tests\Models\CMS\CmsUser u2 WHERE u2.name = u.name)');
2008-05-24 22:18:37 +04:00
}
public function testSomeExpressionWithCorrelatedSubquery()
2008-05-24 22:18:37 +04:00
{
$this->assertValidDQL('SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id > SOME (SELECT u2.id FROM Doctrine\Tests\Models\CMS\CmsUser u2 WHERE u2.name = u.name)');
2008-05-24 22:18:37 +04:00
}
2010-02-20 21:27:05 +03:00
public function testArithmeticExpressionWithoutParenthesisInWhereClause()
{
$this->assertValidDQL('SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE SIZE(u.phonenumbers) + 1 > 10');
}
2009-06-14 21:34:28 +04:00
public function testMemberOfExpression()
{
$this->assertValidDQL('SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE :param MEMBER OF u.phonenumbers');
//$this->assertValidDQL("SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE 'Joe' MEMBER OF u.nicknames");
2009-06-14 21:34:28 +04:00
}
2011-12-20 01:56:19 +04:00
public function testSizeFunction()
{
$this->assertValidDQL('SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE SIZE(u.phonenumbers) > 1');
}
2011-12-20 01:56:19 +04:00
public function testEmptyCollectionComparisonExpression()
{
$this->assertValidDQL('SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.phonenumbers IS EMPTY');
}
2011-12-20 01:56:19 +04:00
public function testSingleValuedAssociationFieldInWhere()
{
$this->assertValidDQL('SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.address = ?1');
$this->assertValidDQL('SELECT p FROM Doctrine\Tests\Models\CMS\CmsPhonenumber p WHERE p.user = ?1');
}
2011-12-20 01:56:19 +04:00
2009-10-13 14:48:46 +04:00
public function testBooleanLiteralInWhere()
{
$this->assertValidDQL('SELECT b FROM Doctrine\Tests\Models\Generic\BooleanModel b WHERE b.booleanField = true');
2009-10-13 14:48:46 +04:00
}
2011-12-20 01:56:19 +04:00
public function testSubqueryInSelectExpression()
{
$this->assertValidDQL('select u, (select max(p.phonenumber) from Doctrine\Tests\Models\CMS\CmsPhonenumber p) maxId from Doctrine\Tests\Models\CMS\CmsUser u');
}
2011-12-20 01:56:19 +04:00
public function testUsageOfQComponentOutsideSubquery()
{
$this->assertInvalidDQL('select u, (select max(p.phonenumber) from Doctrine\Tests\Models\CMS\CmsPhonenumber p) maxId from Doctrine\Tests\Models\CMS\CmsUser u WHERE p.user = ?1');
}
2011-12-20 01:56:19 +04:00
public function testUnknownAbstractSchemaName()
{
$this->assertInvalidDQL('SELECT u FROM UnknownClassName u');
}
2011-12-20 01:56:19 +04:00
public function testCorrectPartialObjectLoad()
{
$this->assertValidDQL('SELECT PARTIAL u.{id,name} FROM Doctrine\Tests\Models\CMS\CmsUser u');
}
2011-12-20 01:56:19 +04:00
public function testIncorrectPartialObjectLoadBecauseOfMissingIdentifier()
{
$this->assertInvalidDQL('SELECT PARTIAL u.{name} FROM Doctrine\Tests\Models\CMS\CmsUser u');
}
2011-12-20 01:56:19 +04:00
public function testScalarExpressionInSelect()
{
$this->assertValidDQL('SELECT u, 42 + u.id AS someNumber FROM Doctrine\Tests\Models\CMS\CmsUser u');
}
2011-12-20 01:56:19 +04:00
public function testInputParameterInSelect()
{
$this->assertValidDQL('SELECT u, u.id + ?1 AS someNumber FROM Doctrine\Tests\Models\CMS\CmsUser u');
}
/**
* @group DDC-1091
*/
public function testCustomFunctionsReturningStringInStringPrimary()
{
$this->_em->getConfiguration()->addCustomStringFunction('CC', 'Doctrine\ORM\Query\AST\Functions\ConcatFunction');
$this->assertValidDQL("SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE CC('%', u.name) LIKE '%foo%'", true);
}
/**
* @group DDC-505
*/
2010-02-20 21:27:05 +03:00
public function testDQLKeywordInJoinIsAllowed()
{
$this->assertValidDQL('SELECT u FROM ' . __NAMESPACE__ . '\DQLKeywordsModelUser u JOIN u.group g');
2010-02-20 21:27:05 +03:00
}
/**
* @group DDC-505
*/
public function testDQLKeywordInConditionIsAllowed()
{
$this->assertValidDQL('SELECT g FROM ' . __NAMESPACE__ . '\DQLKeywordsModelGroup g WHERE g.from=0');
}
/* The exception is currently thrown in the SQLWalker, not earlier.
public function testInverseSideSingleValuedAssociationPathNotAllowed()
{
$this->assertInvalidDQL('SELECT u.id FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.address = ?1');
}
*/
2011-12-20 01:56:19 +04:00
/**
* @group DDC-617
*/
public function testSelectOnlyNonRootEntityAlias()
{
$this->assertInvalidDQL('SELECT g FROM Doctrine\Tests\Models\CMS\CmsUser u JOIN u.groups g');
}
/**
* @group DDC-1108
*/
public function testInputParameterSingleChar()
{
$this->assertValidDQL('SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.name = :q');
}
/**
* @group DDC-1053
*/
public function testGroupBy()
{
$this->assertValidDQL('SELECT g.id, count(u.id) FROM Doctrine\Tests\Models\CMS\CmsGroup g JOIN g.users u GROUP BY g.id');
}
/**
* @group DDC-1053
*/
public function testGroupByIdentificationVariable()
{
$this->assertValidDQL('SELECT g, count(u.id) FROM Doctrine\Tests\Models\CMS\CmsGroup g JOIN g.users u GROUP BY g');
}
/**
* @group DDC-1053
*/
public function testGroupByUnknownIdentificationVariable()
{
$this->assertInvalidDQL('SELECT g, count(u.id) FROM Doctrine\Tests\Models\CMS\CmsGroup g JOIN g.users u GROUP BY m');
}
/**
* @group DDC-117
*/
public function testSizeOfForeignKeyOneToManyPrimaryKeyEntity()
{
$this->assertValidDQL("SELECT a, t FROM Doctrine\Tests\Models\DDC117\DDC117Article a JOIN a.translations t WHERE SIZE(a.translations) > 0");
}
/**
* @group DDC-117
*/
public function testSizeOfForeignKeyManyToManyPrimaryKeyEntity()
{
$this->assertValidDQL("SELECT e, t FROM Doctrine\Tests\Models\DDC117\DDC117Editor e JOIN e.reviewingTranslations t WHERE SIZE(e.reviewingTranslations) > 0");
}
2011-12-20 01:56:19 +04:00
public function testCaseSupportContainingNullIfExpression()
{
$this->assertValidDQL("SELECT u.id, NULLIF(u.name, u.name) AS shouldBeNull FROM Doctrine\Tests\Models\CMS\CmsUser u");
}
2011-12-20 01:56:19 +04:00
public function testCaseSupportContainingCoalesceExpression()
{
$this->assertValidDQL("select COALESCE(NULLIF(u.name, ''), u.username) as Display FROM Doctrine\Tests\Models\CMS\CmsUser u");
}
2010-02-20 21:27:05 +03:00
}
/** @Entity */
class DQLKeywordsModelUser
{
/** @Id @Column(type="integer") @GeneratedValue */
private $id;
/** @OneToOne(targetEntity="DQLKeywordsModelGroup") */
private $group;
}
/** @Entity */
class DQLKeywordsModelGroup
{
/** @Id @Column(type="integer") @GeneratedValue */
private $id;
/** @Column */
private $from;
2010-02-20 21:27:05 +03:00
}