From acb0d35c8abddb507a0a4358d6493feb368f4c4c Mon Sep 17 00:00:00 2001 From: Vincent Langlet Date: Sat, 7 Jan 2023 21:49:07 +0100 Subject: [PATCH] Fix deprecations in tests --- composer.json | 1 + .../Query/QueryResultTypeWalkerTest.php | 32 +++++++++++++++---- 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/composer.json b/composer.json index f7415b52..4dcaf24d 100644 --- a/composer.json +++ b/composer.json @@ -17,6 +17,7 @@ "doctrine/persistence": "<1.3" }, "require-dev": { + "composer/semver": "^3.3.2", "doctrine/annotations": "^1.11.0", "doctrine/collections": "^1.6", "doctrine/common": "^2.7 || ^3.0", diff --git a/tests/Type/Doctrine/Query/QueryResultTypeWalkerTest.php b/tests/Type/Doctrine/Query/QueryResultTypeWalkerTest.php index 914d6d12..cdb575ec 100644 --- a/tests/Type/Doctrine/Query/QueryResultTypeWalkerTest.php +++ b/tests/Type/Doctrine/Query/QueryResultTypeWalkerTest.php @@ -3,10 +3,10 @@ namespace PHPStan\Type\Doctrine\Query; use Composer\InstalledVersions; +use Composer\Semver\VersionParser; use DateTime; use DateTimeImmutable; use Doctrine\Common\Collections\ArrayCollection; -use Doctrine\DBAL\Platforms\SqlitePlatform; use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\Mapping\Column; use Doctrine\ORM\Query\AST\TypedExpression; @@ -49,7 +49,6 @@ use function count; use function property_exists; use function sprintf; -use function strpos; use function version_compare; use const PHP_VERSION_ID; @@ -188,7 +187,7 @@ public function setUp(): void } /** @dataProvider getTestData */ - public function test(Type $expectedType, string $dql, ?string $expectedExceptionMessage = null): void + public function test(Type $expectedType, string $dql, ?string $expectedExceptionMessage = null, ?string $expectedDeprecationMessage = null): void { $em = self::$em; @@ -199,6 +198,9 @@ public function test(Type $expectedType, string $dql, ?string $expectedException if ($expectedExceptionMessage !== null) { $this->expectException(Throwable::class); $this->expectExceptionMessage($expectedExceptionMessage); + } elseif ($expectedDeprecationMessage !== null) { + $this->expectDeprecation(); + $this->expectDeprecationMessage($expectedDeprecationMessage); } QueryResultTypeWalker::walk($query, $typeBuilder, $this->descriptorRegistry); @@ -1233,6 +1235,12 @@ public function getTestData(): iterable SQRT(1) FROM QueryResult\Entities\Many m ', + InstalledVersions::satisfies(new VersionParser(), 'doctrine/dbal', '<3') && PHP_VERSION_ID >= 80100 + ? 'sqrt(): Passing null to parameter #1 ($num) of type float is deprecated' + : null, + InstalledVersions::satisfies(new VersionParser(), 'doctrine/dbal', '>=3') && PHP_VERSION_ID >= 80100 + ? 'sqrt(): Passing null to parameter #1 ($num) of type float is deprecated' + : null, ]; yield 'length function' => [ @@ -1280,6 +1288,18 @@ public function getTestData(): iterable LOCATE(\'f\', \'foo\', 0) FROM QueryResult\Entities\Many m ', + null, + InstalledVersions::satisfies(new VersionParser(), 'doctrine/dbal', '>=3.4') + ? null + : ( + PHP_VERSION_ID >= 80100 + ? 'strpos(): Passing null to parameter #2 ($needle) of type string is deprecated' + : ( + PHP_VERSION_ID >= 70300 && PHP_VERSION_ID < 80000 + ? 'strpos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior' + : null + ) + ), ]; yield 'lower function' => [ @@ -1312,8 +1332,6 @@ public function getTestData(): iterable ', ]; - // There is no error after the merge of https://github.com/doctrine/dbal/pull/5755 - $moduloError = strpos((new SqlitePlatform())->getModExpression('', ''), '%') === false; yield 'mod function error' => [ $this->constantArray([ [new ConstantIntegerType(1), TypeCombinator::addNull($this->uintStringified())], @@ -1322,7 +1340,9 @@ public function getTestData(): iterable SELECT MOD(10, NULLIF(m.intColumn, m.intColumn)) FROM QueryResult\Entities\Many m ', - $moduloError ? 'Modulo by zero' : null, + InstalledVersions::satisfies(new VersionParser(), 'doctrine/dbal', '<3.5') + ? 'Modulo by zero' + : null, ]; yield 'substring function' => [