Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove broken assertion from DateAddFunction and DateSubFunction #11243

Merged
merged 2 commits into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -65,7 +65,7 @@ jobs:
matrix:
dbal-version:
- default
- 3.7
- 3.8.2

steps:
- name: "Checkout code"
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
13 changes: 2 additions & 11 deletions src/Query/AST/Functions/DateAddFunction.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
use Doctrine\ORM\Query\SqlWalker;
use Doctrine\ORM\Query\TokenType;

use function assert;
use function is_numeric;
use function strtolower;

/**
Expand Down Expand Up @@ -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
Expand Down
13 changes: 2 additions & 11 deletions src/Query/AST/Functions/DateSubFunction.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
use Doctrine\ORM\Query\QueryException;
use Doctrine\ORM\Query\SqlWalker;

use function assert;
use function is_numeric;
use function strtolower;

/**
Expand Down Expand Up @@ -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);
}
}
31 changes: 31 additions & 0 deletions tests/Tests/ORM/Functional/QueryDqlFunctionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
Loading