33namespace PHPStan \Type \Doctrine \Query ;
44
55use Composer \InstalledVersions ;
6+ use Composer \Semver \VersionParser ;
67use DateTime ;
78use DateTimeImmutable ;
89use Doctrine \Common \Collections \ArrayCollection ;
9- use Doctrine \DBAL \Platforms \SqlitePlatform ;
1010use Doctrine \ORM \EntityManagerInterface ;
1111use Doctrine \ORM \Mapping \Column ;
1212use Doctrine \ORM \Query \AST \TypedExpression ;
4949use function count ;
5050use function property_exists ;
5151use function sprintf ;
52- use function strpos ;
5352use function version_compare ;
5453use 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