mirror of
https://github.com/danog/psalm.git
synced 2024-11-27 04:45:20 +01:00
More closed inheritance assertion tests
This commit is contained in:
parent
b7b20771c0
commit
38c93db889
@ -2304,6 +2304,56 @@ class AssertAnnotationTest extends TestCase
|
||||
}
|
||||
}',
|
||||
],
|
||||
'assertObjectWithClosedInheritanceWithMatch' => [
|
||||
'code' => '<?php
|
||||
/**
|
||||
* @psalm-inheritors FirstChoice|SecondChoice|ThirdChoice
|
||||
*/
|
||||
interface Choice
|
||||
{
|
||||
}
|
||||
|
||||
final class FirstChoice implements Choice {}
|
||||
final class SecondChoice implements Choice {}
|
||||
final class ThirdChoice implements Choice {}
|
||||
|
||||
/**
|
||||
* @psalm-assert-if-true FirstChoice $choice
|
||||
*/
|
||||
function isFirstChoice(Choice $choice): bool
|
||||
{
|
||||
return $choice instanceof FirstChoice;
|
||||
}
|
||||
|
||||
/**
|
||||
* @psalm-assert-if-true SecondChoice $choice
|
||||
*/
|
||||
function isSecondChoice(Choice $choice): bool
|
||||
{
|
||||
return $choice instanceof SecondChoice;
|
||||
}
|
||||
|
||||
function testFirstChoice(FirstChoice $_first): string
|
||||
{
|
||||
return "first";
|
||||
}
|
||||
|
||||
function testSecondOrThirdChoice(SecondChoice|ThirdChoice $_first): string
|
||||
{
|
||||
return "second or third";
|
||||
}
|
||||
|
||||
function getLabel(Choice $choice): string
|
||||
{
|
||||
return match (true) {
|
||||
isFirstChoice($choice) => testFirstChoice($choice),
|
||||
default => testSecondOrThirdChoice($choice),
|
||||
};
|
||||
}',
|
||||
'assertions' => [],
|
||||
'ignored_issues' => [],
|
||||
'php_version' => '8.1',
|
||||
],
|
||||
'assertTemplatedObjectWithClosedInheritance' => [
|
||||
'code' => '<?php
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user