3
3
namespace PHPStan \Platform ;
4
4
5
5
use Cache \Adapter \PHPArray \ArrayCachePool ;
6
+ use DateTimeImmutable ;
6
7
use Doctrine \Common \Annotations \AnnotationReader ;
7
8
use Doctrine \DBAL \Connection ;
8
9
use Doctrine \DBAL \Driver ;
@@ -203,6 +204,24 @@ public static function provideCases(): iterable
203
204
},
204
205
];
205
206
207
+ yield ' 0.1 ' => [
208
+ 'data ' => self ::dataDefault (),
209
+ 'select ' => 'SELECT 0.1 FROM %s t ' ,
210
+ 'mysql ' => new ConstantStringType ('0.1 ' ),
211
+ 'sqlite ' => new ConstantFloatType (0.1 ),
212
+ 'pdo_pgsql ' => new ConstantStringType ('0.1 ' ),
213
+ 'pgsql ' => new ConstantStringType ('0.1 ' ),
214
+ 'mssql ' => new MixedType (),
215
+ 'mysqlResult ' => '0.1 ' ,
216
+ 'sqliteResult ' => 0.1 ,
217
+ 'pdoPgsqlResult ' => '0.1 ' ,
218
+ 'pgsqlResult ' => '0.1 ' ,
219
+ 'mssqlResult ' => '.1 ' ,
220
+ 'shouldStringify ' => static function (Driver $ driver , int $ php , string $ configName ): bool {
221
+ return self ::defaultStringification ($ driver , $ php , $ configName );
222
+ },
223
+ ];
224
+
206
225
yield ' 1e0 ' => [
207
226
'data ' => self ::dataDefault (),
208
227
'select ' => 'SELECT 1e0 FROM %s t ' ,
@@ -3425,6 +3444,27 @@ public static function provideCases(): iterable
3425
3444
},
3426
3445
];
3427
3446
3447
+ yield 'COALESCE(t.col_datetime, t.col_datetime) ' => [
3448
+ 'data ' => self ::dataDefault (),
3449
+ 'select ' => 'SELECT COALESCE(t.col_datetime, t.col_datetime) FROM %s t ' ,
3450
+ 'mysql ' => self ::string (),
3451
+ 'sqlite ' => self ::string (),
3452
+ 'pdo_pgsql ' => self ::string (),
3453
+ 'pgsql ' => self ::string (),
3454
+ 'mssql ' => self ::mixed (),
3455
+ 'mysqlResult ' => '2024-01-31 12:59:59 ' ,
3456
+ 'sqliteResult ' => '2024-01-31 12:59:59 ' ,
3457
+ 'pdoPgsqlResult ' => '2024-01-31 12:59:59 ' ,
3458
+ 'pgsqlResult ' => '2024-01-31 12:59:59 ' ,
3459
+ 'mssqlResult ' => '2024-01-31 12:59:59.000000 ' , // doctrine/dbal changes default ReturnDatesAsStrings to true
3460
+ 'shouldStringify ' => static function (): bool {
3461
+ return false ;
3462
+ },
3463
+ ];
3464
+
3465
+ // TODO postgres ->setUseBooleanTrueFalseStrings()
3466
+ // TODO string TypedExpression does not cast to string
3467
+ // TODO sqlsrv uses native DateTime
3428
3468
// TODO would col_numeric_string differ from col_string results ?
3429
3469
// TODO dbal/orm versions
3430
3470
// TODO unknown driver to return mixed everywhere
@@ -3777,6 +3817,11 @@ private static function numericString(): Type
3777
3817
]);
3778
3818
}
3779
3819
3820
+ private static function string (): Type
3821
+ {
3822
+ return new StringType ();
3823
+ }
3824
+
3780
3825
private static function numericStringOrNull (): Type
3781
3826
{
3782
3827
return TypeCombinator::addNull (new IntersectionType ([
@@ -3854,6 +3899,7 @@ public static function dataDefault(): array
3854
3899
'col_string ' => 'foobar ' ,
3855
3900
'col_string_nullable ' => null ,
3856
3901
'col_mixed ' => 1 ,
3902
+ 'col_datetime ' => new DateTimeImmutable ('2024-01-31 12:59:59 ' ),
3857
3903
],
3858
3904
];
3859
3905
}
@@ -3879,6 +3925,7 @@ public static function dataAllIntLike(): array
3879
3925
'col_string ' => '1 ' ,
3880
3926
'col_string_nullable ' => null ,
3881
3927
'col_mixed ' => 1 ,
3928
+ 'col_datetime ' => new DateTimeImmutable ('2024-01-31 12:59:59 ' ),
3882
3929
],
3883
3930
];
3884
3931
}
@@ -3905,6 +3952,7 @@ public static function dataSqrt(): array
3905
3952
'col_string ' => 'foobar ' ,
3906
3953
'col_string_nullable ' => null ,
3907
3954
'col_mixed ' => 1 ,
3955
+ 'col_datetime ' => new DateTimeImmutable ('2024-01-31 12:59:59 ' ),
3908
3956
],
3909
3957
];
3910
3958
}
0 commit comments