Skip to content

Commit

Permalink
Merge branch '2.11.x' into 3.0.x
Browse files Browse the repository at this point in the history
* 2.11.x:
  Fix return type (doctrine#9295)
  Synchronize Psalm baseline (doctrine#9296)
  Fix union type on QueryExpressionVisitorTest::testWalkComparison() (doctrine#9294)
  Allow arithmetic expressions within IN operator (doctrine#9242)
  Bump reusable workflows
  • Loading branch information
derrabus committed Dec 28, 2021
2 parents 9c07649 + c94a9b1 commit a4340c7
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 15 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/release-on-milestone-closed.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ on:

jobs:
release:
uses: "doctrine/.github/.github/workflows/release-on-milestone-closed.yml@1.1.1"
uses: "doctrine/.github/.github/workflows/release-on-milestone-closed.yml@1.4.1"
secrets:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GIT_AUTHOR_EMAIL: ${{ secrets.GIT_AUTHOR_EMAIL }}
GIT_AUTHOR_NAME: ${{ secrets.GIT_AUTHOR_NAME }}
ORGANIZATION_ADMIN_TOKEN: ${{ secrets.ORGANIZATION_ADMIN_TOKEN }}
Expand Down
2 changes: 1 addition & 1 deletion docs/en/reference/dql-doctrine-query-language.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1724,7 +1724,7 @@ Literal Values
.. code-block:: php
Literal ::= string | char | integer | float | boolean
InParameter ::= Literal | InputParameter
InParameter ::= ArithmeticExpression | InputParameter
Input Parameter
~~~~~~~~~~~~~~~
Expand Down
6 changes: 3 additions & 3 deletions lib/Doctrine/ORM/Query/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -2758,17 +2758,17 @@ public function Literal()
}

/**
* InParameter ::= Literal | InputParameter
* InParameter ::= ArithmeticExpression | InputParameter
*
* @return AST\InputParameter|AST\Literal
* @return AST\InputParameter|AST\ArithmeticExpression
*/
public function InParameter()
{
if ($this->lexer->lookahead['type'] === Lexer::T_INPUT_PARAMETER) {
return $this->InputParameter();
}

return $this->Literal();
return $this->ArithmeticExpression();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/ORM/Query/SqlWalker.php
Original file line number Diff line number Diff line change
Expand Up @@ -2106,7 +2106,7 @@ public function walkInParameter($inParam)
{
return $inParam instanceof AST\InputParameter
? $this->walkInputParameter($inParam)
: $this->walkLiteral($inParam);
: $this->walkArithmeticExpression($inParam);
}

/**
Expand Down
5 changes: 0 additions & 5 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3242,11 +3242,6 @@
<code>$indexName</code>
</TypeDoesNotContainType>
</file>
<file src="lib/Doctrine/ORM/Tools/SchemaValidator.php">
<PossiblyNullReference occurrences="1">
<code>isAbstract</code>
</PossiblyNullReference>
</file>
<file src="lib/Doctrine/ORM/UnitOfWork.php">
<ArgumentTypeCoercion occurrences="6">
<code>$class</code>
Expand Down
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 @@ -420,6 +420,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 m_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]['m_name']);
self::assertEquals('Benjamin E.', $result[1]['m_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 m_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]['m_name']);
}

protected function generateFixture(): void
{
$manager1 = new CompanyManager();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function testInvalidEntityName($value, string $expectedMessage): void
}

/**
* @return string[][]
* @psalm-return list<array{mixed, string}>
*/
public function invalidEntityNames(): array
{
Expand Down
10 changes: 8 additions & 2 deletions tests/Doctrine/Tests/ORM/Query/QueryExpressionVisitorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ protected function setUp(): void
}

/**
* @param QueryBuilder\Comparison|string $queryExpr
* @param QueryBuilder\Comparison|QueryBuilder\Func|string $queryExpr
*
* @dataProvider comparisonData
*/
Expand All @@ -39,7 +39,13 @@ public function testWalkComparison(CriteriaComparison $criteriaExpr, $queryExpr,
}
}

/** @psalm-return list<array{CriteriaComparison, QueryBuilder\Comparison|string, ?Parameter} */
/**
* @psalm-return list<array{
* 0: CriteriaComparison,
* 1: QueryBuilder\Comparison|QueryBuilder\Func|string,
* 2?: Parameter,
* }>
*/
public function comparisonData(): array
{
$cb = new CriteriaBuilder();
Expand Down
14 changes: 14 additions & 0 deletions tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,20 @@ public function testInvalidInExpressionWithSingleValuedAssociationPathExpression
);
}

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)",
"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)',
'SELECT f0_.id AS id_0, f0_.username AS username_1 FROM forum_users f0_ WHERE f0_.id IN (1 + 1)'
);
}

public function testSupportsConcatFunctionForMysqlAndPostgresql(): void
{
$connMock = $this->entityManager->getConnection();
Expand Down

0 comments on commit a4340c7

Please sign in to comment.