Skip to content

Commit

Permalink
Add functional tests
Browse files Browse the repository at this point in the history
  • Loading branch information
webda2l committed Dec 14, 2021
1 parent 8181c75 commit 1f7aa62
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 8 deletions.
33 changes: 33 additions & 0 deletions tests/Doctrine/Tests/ORM/Functional/QueryDqlFunctionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,39 @@ public function testBitAndComparison(): void
self::assertEquals($result[3][0]['salary'] / 100000 & 2, $result[3]['salary_bit_and']);
}

public function testInArithmeticExpression1(): void
{
$dql = <<<SQL
SELECT m, m.name AS name
FROM Doctrine\Tests\Models\Company\CompanyManager m
WHERE m.salary IN (800000/8, 100000*2)
SQL;

$result = $this->_em->createQuery($dql)->getArrayResult();

self::assertCount(2, $result);
self::assertEquals('Roman B.', $result[0]['name']);
self::assertEquals('Benjamin E.', $result[1]['name']);
}

public function testInArithmeticExpression2(): void
{
$this->_em->getConfiguration()->addCustomStringFunction('FOO', static function ($funcName) {
return new NoOp($funcName); // See Doctrine/Tests/ORM/Functional/CustomFunctionsTest
});

$dql = <<<SQL
SELECT m, m.name AS name
FROM Doctrine\Tests\Models\Company\CompanyManager m
WHERE m.department IN (FOO('Administration'))
SQL;

$result = $this->_em->createQuery($dql)->getArrayResult();

self::assertCount(1, $result);
self::assertEquals('Jonathan W.', $result[0]['name']);
}

protected function generateFixture(): void
{
$manager1 = new CompanyManager();
Expand Down
13 changes: 5 additions & 8 deletions tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -643,20 +643,17 @@ public function testInvalidInExpressionWithSingleValuedAssociationPathExpression
);
}

public function testCustomFunctionWithinInExpression() : void
public function testInExpressionWithArithmeticExpression(): void
{
$this->entityManager->getConfiguration()->addCustomStringFunction('FOO', MyAbsFunction::class);

$this->assertSqlGeneration(
"SELECT u FROM Doctrine\Tests\Models\Forum\ForumUser u WHERE u.username IN (FOO('Lo'), 'Lo', :name)",
<<<'SQL'
SELECT f0_.id AS id_0, f0_.username AS username_1 FROM forum_users f0_ WHERE f0_.username IN (ABS('Lo'), 'Lo', ?)
SQL
"SELECT f0_.id AS id_0, f0_.username AS username_1 FROM forum_users f0_ WHERE f0_.username IN (ABS('Lo'), 'Lo', ?)"
);
$this->assertSqlGeneration(
'SELECT u FROM Doctrine\Tests\Models\Forum\ForumUser u WHERE u.id IN (1+1)',
<<<'SQL'
SELECT f0_.id AS id_0, f0_.username AS username_1 FROM forum_users f0_ WHERE f0_.id IN (1 + 1)
SQL
'SELECT u FROM Doctrine\Tests\Models\Forum\ForumUser u WHERE u.id IN (1 + 1)',
'SELECT f0_.id AS id_0, f0_.username AS username_1 FROM forum_users f0_ WHERE f0_.id IN (1 + 1)'
);
}

Expand Down

0 comments on commit 1f7aa62

Please sign in to comment.