Skip to content

Commit b6b4cbc

Browse files
authored
Remove broken assertion from DateAddFunction and DateSubFunction (#11243)
* Remove wrong asserts in DATE_ADD and DATE_SUB query AST function handlers * Require DBAL 3.8.2
1 parent d5ba106 commit b6b4cbc

File tree

5 files changed

+38
-25
lines changed

5 files changed

+38
-25
lines changed

.github/workflows/static-analysis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ jobs:
3232
include:
3333
- dbal-version: default
3434
config: phpstan.neon
35-
- dbal-version: 3.7
35+
- dbal-version: 3.8.2
3636
config: phpstan-dbal3.neon
3737

3838
steps:
@@ -65,7 +65,7 @@ jobs:
6565
matrix:
6666
dbal-version:
6767
- default
68-
- 3.7
68+
- 3.8.2
6969

7070
steps:
7171
- name: "Checkout code"

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"composer-runtime-api": "^2",
2525
"ext-ctype": "*",
2626
"doctrine/collections": "^2.1",
27-
"doctrine/dbal": "^3.6 || ^4",
27+
"doctrine/dbal": "^3.8.2 || ^4",
2828
"doctrine/deprecations": "^0.5.3 || ^1",
2929
"doctrine/event-manager": "^1.2 || ^2",
3030
"doctrine/inflector": "^1.4 || ^2.0",

src/Query/AST/Functions/DateAddFunction.php

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
use Doctrine\ORM\Query\SqlWalker;
1212
use Doctrine\ORM\Query\TokenType;
1313

14-
use function assert;
15-
use function is_numeric;
1614
use function strtolower;
1715

1816
/**
@@ -63,17 +61,10 @@ public function getSql(SqlWalker $sqlWalker): string
6361
};
6462
}
6563

66-
/**
67-
* @return numeric-string
68-
*
69-
* @throws ASTException
70-
*/
64+
/** @throws ASTException */
7165
private function dispatchIntervalExpression(SqlWalker $sqlWalker): string
7266
{
73-
$sql = $this->intervalExpression->dispatch($sqlWalker);
74-
assert(is_numeric($sql));
75-
76-
return $sql;
67+
return $this->intervalExpression->dispatch($sqlWalker);
7768
}
7869

7970
public function parse(Parser $parser): void

src/Query/AST/Functions/DateSubFunction.php

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
use Doctrine\ORM\Query\QueryException;
99
use Doctrine\ORM\Query\SqlWalker;
1010

11-
use function assert;
12-
use function is_numeric;
1311
use function strtolower;
1412

1513
/**
@@ -56,16 +54,9 @@ public function getSql(SqlWalker $sqlWalker): string
5654
};
5755
}
5856

59-
/**
60-
* @return numeric-string
61-
*
62-
* @throws ASTException
63-
*/
57+
/** @throws ASTException */
6458
private function dispatchIntervalExpression(SqlWalker $sqlWalker): string
6559
{
66-
$sql = $this->intervalExpression->dispatch($sqlWalker);
67-
assert(is_numeric($sql));
68-
69-
return $sql;
60+
return $this->intervalExpression->dispatch($sqlWalker);
7061
}
7162
}

tests/Tests/ORM/Functional/QueryDqlFunctionTest.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use DateTimeImmutable;
88
use Doctrine\DBAL\Platforms\SQLitePlatform;
99
use Doctrine\ORM\AbstractQuery;
10+
use Doctrine\Tests\Models\Company\CompanyEmployee;
1011
use Doctrine\Tests\Models\Company\CompanyManager;
1112
use Doctrine\Tests\OrmFunctionalTestCase;
1213
use PHPUnit\Framework\Attributes\DataProvider;
@@ -487,4 +488,34 @@ protected function generateFixture(): void
487488
$this->_em->flush();
488489
$this->_em->clear();
489490
}
491+
492+
#[Group('GH-11240')]
493+
public function testDateAddWithColumnInterval(): void
494+
{
495+
$query = sprintf(
496+
'SELECT DATE_ADD(CURRENT_TIMESTAMP(), m.salary, \'day\') AS add FROM %s m',
497+
CompanyEmployee::class,
498+
);
499+
500+
$result = $this->_em->createQuery($query)
501+
->setMaxResults(1)
502+
->getSingleResult(AbstractQuery::HYDRATE_ARRAY);
503+
504+
self::assertArrayHasKey('add', $result);
505+
}
506+
507+
#[Group('GH-11240')]
508+
public function testDateSubWithColumnInterval(): void
509+
{
510+
$query = sprintf(
511+
'SELECT DATE_SUB(CURRENT_TIMESTAMP(), m.salary, \'day\') AS add FROM %s m',
512+
CompanyEmployee::class,
513+
);
514+
515+
$result = $this->_em->createQuery($query)
516+
->setMaxResults(1)
517+
->getSingleResult(AbstractQuery::HYDRATE_ARRAY);
518+
519+
self::assertArrayHasKey('add', $result);
520+
}
490521
}

0 commit comments

Comments
 (0)