From 1b5fc04327d6cc195ca41620510c335e0b8e63fa Mon Sep 17 00:00:00 2001 From: Ondrej Mirtes Date: Fri, 9 Feb 2024 17:14:06 +0100 Subject: [PATCH 1/2] Remove wrong asserts in DATE_ADD and DATE_SUB query AST function handlers --- src/Query/AST/Functions/DateAddFunction.php | 13 ++------ src/Query/AST/Functions/DateSubFunction.php | 13 ++------ .../ORM/Functional/QueryDqlFunctionTest.php | 31 +++++++++++++++++++ 3 files changed, 35 insertions(+), 22 deletions(-) diff --git a/src/Query/AST/Functions/DateAddFunction.php b/src/Query/AST/Functions/DateAddFunction.php index 385ebac99c9..12920dcbd0f 100644 --- a/src/Query/AST/Functions/DateAddFunction.php +++ b/src/Query/AST/Functions/DateAddFunction.php @@ -11,8 +11,6 @@ use Doctrine\ORM\Query\SqlWalker; use Doctrine\ORM\Query\TokenType; -use function assert; -use function is_numeric; use function strtolower; /** @@ -63,17 +61,10 @@ public function getSql(SqlWalker $sqlWalker): string }; } - /** - * @return numeric-string - * - * @throws ASTException - */ + /** @throws ASTException */ private function dispatchIntervalExpression(SqlWalker $sqlWalker): string { - $sql = $this->intervalExpression->dispatch($sqlWalker); - assert(is_numeric($sql)); - - return $sql; + return $this->intervalExpression->dispatch($sqlWalker); } public function parse(Parser $parser): void diff --git a/src/Query/AST/Functions/DateSubFunction.php b/src/Query/AST/Functions/DateSubFunction.php index 254f1219277..5363680e2a4 100644 --- a/src/Query/AST/Functions/DateSubFunction.php +++ b/src/Query/AST/Functions/DateSubFunction.php @@ -8,8 +8,6 @@ use Doctrine\ORM\Query\QueryException; use Doctrine\ORM\Query\SqlWalker; -use function assert; -use function is_numeric; use function strtolower; /** @@ -56,16 +54,9 @@ public function getSql(SqlWalker $sqlWalker): string }; } - /** - * @return numeric-string - * - * @throws ASTException - */ + /** @throws ASTException */ private function dispatchIntervalExpression(SqlWalker $sqlWalker): string { - $sql = $this->intervalExpression->dispatch($sqlWalker); - assert(is_numeric($sql)); - - return $sql; + return $this->intervalExpression->dispatch($sqlWalker); } } diff --git a/tests/Tests/ORM/Functional/QueryDqlFunctionTest.php b/tests/Tests/ORM/Functional/QueryDqlFunctionTest.php index 9fdc7d64516..5a6aa5da3ab 100644 --- a/tests/Tests/ORM/Functional/QueryDqlFunctionTest.php +++ b/tests/Tests/ORM/Functional/QueryDqlFunctionTest.php @@ -7,6 +7,7 @@ use DateTimeImmutable; use Doctrine\DBAL\Platforms\SQLitePlatform; use Doctrine\ORM\AbstractQuery; +use Doctrine\Tests\Models\Company\CompanyEmployee; use Doctrine\Tests\Models\Company\CompanyManager; use Doctrine\Tests\OrmFunctionalTestCase; use PHPUnit\Framework\Attributes\DataProvider; @@ -487,4 +488,34 @@ protected function generateFixture(): void $this->_em->flush(); $this->_em->clear(); } + + #[Group('GH-11240')] + public function testDateAddWithColumnInterval(): void + { + $query = sprintf( + 'SELECT DATE_ADD(CURRENT_TIMESTAMP(), m.salary, \'day\') AS add FROM %s m', + CompanyEmployee::class, + ); + + $result = $this->_em->createQuery($query) + ->setMaxResults(1) + ->getSingleResult(AbstractQuery::HYDRATE_ARRAY); + + self::assertArrayHasKey('add', $result); + } + + #[Group('GH-11240')] + public function testDateSubWithColumnInterval(): void + { + $query = sprintf( + 'SELECT DATE_SUB(CURRENT_TIMESTAMP(), m.salary, \'day\') AS add FROM %s m', + CompanyEmployee::class, + ); + + $result = $this->_em->createQuery($query) + ->setMaxResults(1) + ->getSingleResult(AbstractQuery::HYDRATE_ARRAY); + + self::assertArrayHasKey('add', $result); + } } From 687252beb0343ab639b2c7fdba3cf639d065df93 Mon Sep 17 00:00:00 2001 From: Ondrej Mirtes Date: Thu, 15 Feb 2024 07:30:25 +0000 Subject: [PATCH 2/2] Require DBAL 3.8.2 --- .github/workflows/static-analysis.yml | 4 ++-- composer.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml index 025f29ea02d..75f46a70e60 100644 --- a/.github/workflows/static-analysis.yml +++ b/.github/workflows/static-analysis.yml @@ -32,7 +32,7 @@ jobs: include: - dbal-version: default config: phpstan.neon - - dbal-version: 3.7 + - dbal-version: 3.8.2 config: phpstan-dbal3.neon steps: @@ -65,7 +65,7 @@ jobs: matrix: dbal-version: - default - - 3.7 + - 3.8.2 steps: - name: "Checkout code" diff --git a/composer.json b/composer.json index 6aefbec39e4..2a002989c21 100644 --- a/composer.json +++ b/composer.json @@ -24,7 +24,7 @@ "composer-runtime-api": "^2", "ext-ctype": "*", "doctrine/collections": "^2.1", - "doctrine/dbal": "^3.6 || ^4", + "doctrine/dbal": "^3.8.2 || ^4", "doctrine/deprecations": "^0.5.3 || ^1", "doctrine/event-manager": "^1.2 || ^2", "doctrine/inflector": "^1.4 || ^2.0",