Skip to content

Commit acb0d35

Browse files
Fix deprecations in tests
1 parent 50a9a76 commit acb0d35

File tree

2 files changed

+27
-6
lines changed

2 files changed

+27
-6
lines changed

Diff for: composer.json

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"doctrine/persistence": "<1.3"
1818
},
1919
"require-dev": {
20+
"composer/semver": "^3.3.2",
2021
"doctrine/annotations": "^1.11.0",
2122
"doctrine/collections": "^1.6",
2223
"doctrine/common": "^2.7 || ^3.0",

Diff for: tests/Type/Doctrine/Query/QueryResultTypeWalkerTest.php

+26-6
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
namespace PHPStan\Type\Doctrine\Query;
44

55
use Composer\InstalledVersions;
6+
use Composer\Semver\VersionParser;
67
use DateTime;
78
use DateTimeImmutable;
89
use Doctrine\Common\Collections\ArrayCollection;
9-
use Doctrine\DBAL\Platforms\SqlitePlatform;
1010
use Doctrine\ORM\EntityManagerInterface;
1111
use Doctrine\ORM\Mapping\Column;
1212
use Doctrine\ORM\Query\AST\TypedExpression;
@@ -49,7 +49,6 @@
4949
use function count;
5050
use function property_exists;
5151
use function sprintf;
52-
use function strpos;
5352
use function version_compare;
5453
use const PHP_VERSION_ID;
5554

@@ -188,7 +187,7 @@ public function setUp(): void
188187
}
189188

190189
/** @dataProvider getTestData */
191-
public function test(Type $expectedType, string $dql, ?string $expectedExceptionMessage = null): void
190+
public function test(Type $expectedType, string $dql, ?string $expectedExceptionMessage = null, ?string $expectedDeprecationMessage = null): void
192191
{
193192
$em = self::$em;
194193

@@ -199,6 +198,9 @@ public function test(Type $expectedType, string $dql, ?string $expectedException
199198
if ($expectedExceptionMessage !== null) {
200199
$this->expectException(Throwable::class);
201200
$this->expectExceptionMessage($expectedExceptionMessage);
201+
} elseif ($expectedDeprecationMessage !== null) {
202+
$this->expectDeprecation();
203+
$this->expectDeprecationMessage($expectedDeprecationMessage);
202204
}
203205

204206
QueryResultTypeWalker::walk($query, $typeBuilder, $this->descriptorRegistry);
@@ -1233,6 +1235,12 @@ public function getTestData(): iterable
12331235
SQRT(1)
12341236
FROM QueryResult\Entities\Many m
12351237
',
1238+
InstalledVersions::satisfies(new VersionParser(), 'doctrine/dbal', '<3') && PHP_VERSION_ID >= 80100
1239+
? 'sqrt(): Passing null to parameter #1 ($num) of type float is deprecated'
1240+
: null,
1241+
InstalledVersions::satisfies(new VersionParser(), 'doctrine/dbal', '>=3') && PHP_VERSION_ID >= 80100
1242+
? 'sqrt(): Passing null to parameter #1 ($num) of type float is deprecated'
1243+
: null,
12361244
];
12371245

12381246
yield 'length function' => [
@@ -1280,6 +1288,18 @@ public function getTestData(): iterable
12801288
LOCATE(\'f\', \'foo\', 0)
12811289
FROM QueryResult\Entities\Many m
12821290
',
1291+
null,
1292+
InstalledVersions::satisfies(new VersionParser(), 'doctrine/dbal', '>=3.4')
1293+
? null
1294+
: (
1295+
PHP_VERSION_ID >= 80100
1296+
? 'strpos(): Passing null to parameter #2 ($needle) of type string is deprecated'
1297+
: (
1298+
PHP_VERSION_ID >= 70300 && PHP_VERSION_ID < 80000
1299+
? 'strpos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior'
1300+
: null
1301+
)
1302+
),
12831303
];
12841304

12851305
yield 'lower function' => [
@@ -1312,8 +1332,6 @@ public function getTestData(): iterable
13121332
',
13131333
];
13141334

1315-
// There is no error after the merge of https://github.com/doctrine/dbal/pull/5755
1316-
$moduloError = strpos((new SqlitePlatform())->getModExpression('', ''), '%') === false;
13171335
yield 'mod function error' => [
13181336
$this->constantArray([
13191337
[new ConstantIntegerType(1), TypeCombinator::addNull($this->uintStringified())],
@@ -1322,7 +1340,9 @@ public function getTestData(): iterable
13221340
SELECT MOD(10, NULLIF(m.intColumn, m.intColumn))
13231341
FROM QueryResult\Entities\Many m
13241342
',
1325-
$moduloError ? 'Modulo by zero' : null,
1343+
InstalledVersions::satisfies(new VersionParser(), 'doctrine/dbal', '<3.5')
1344+
? 'Modulo by zero'
1345+
: null,
13261346
];
13271347

13281348
yield 'substring function' => [

0 commit comments

Comments
 (0)