1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-27 12:55:26 +01:00

Add expected behaviour tests

This commit is contained in:
Jack Robertson 2021-07-26 08:50:12 +01:00
parent aa23aa5387
commit 8bec5fc743
2 changed files with 32 additions and 0 deletions

View File

@ -110,6 +110,8 @@ class ReconcilerTest extends \Psalm\Tests\TestCase
'notSomeClassWithSomeClassPipeBool' => ['bool', '!SomeClass', 'SomeClass|bool'],
'notSomeClassWithSomeClassPipeNull' => ['null', '!SomeClass', 'SomeClass|null'],
'notSomeClassWithAPipeB' => ['B', '!A', 'A|B'],
'notDateTimeWithDateTimeInterface' => ['DateTimeImmutable', '!DateTime', 'DateTimeInterface'],
'notDateTimeImmutableWithDateTimeInterface' => ['DateTime', '!DateTimeImmutable', 'DateTimeInterface'],
'myObjectWithSomeClassPipeBool' => ['SomeClass', 'SomeClass', 'SomeClass|bool'],
'myObjectWithAPipeB' => ['A', 'A', 'A|B'],

View File

@ -1073,6 +1073,36 @@ class TypeTest extends \Psalm\Tests\TestCase
*/
function consume($input): void{}'
],
'notDateTimeWithDateTimeInterface' => [
'<?php
function foo(\DateTimeInterface $dateTime): DateTimeInterface {
$dateInterval = new DateInterval("P1D");
if ($dateTime instanceof \DateTime) {
$dateTime->add($dateInterval);
return $dateTime;
} else {
return $dateTime->add($dateInterval);
}
}
',
],
'notDateTimeImmutableWithDateTimeInterface' => [
'<?php
function foo(\DateTimeInterface $dateTime): DateTimeInterface {
$dateInterval = new DateInterval("P1D");
if ($dateTime instanceof \DateTimeImmutable) {
return $dateTime->add($dateInterval);
} else {
$dateTime->add($dateInterval);
return $dateTime;
}
}
',
],
];
}