Skip to content

Commit

Permalink
Fix deprecations in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentLanglet authored Jan 7, 2023
1 parent 50a9a76 commit acb0d35
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
32 changes: 26 additions & 6 deletions tests/Type/Doctrine/Query/QueryResultTypeWalkerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand All @@ -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);
Expand Down Expand Up @@ -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' => [
Expand Down Expand Up @@ -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' => [
Expand Down Expand Up @@ -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())],
Expand All @@ -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' => [
Expand Down

0 comments on commit acb0d35

Please sign in to comment.