1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-27 04:45:20 +01:00
psalm/tests/IntRangeTest.php
2021-07-31 15:47:12 +02:00

79 lines
2.2 KiB
PHP

<?php
namespace Psalm\Tests;
class IntRangeTest extends TestCase
{
use Traits\InvalidCodeAnalysisTestTrait;
use Traits\ValidCodeAnalysisTestTrait;
/**
* @return iterable<string,array{string,assertions?:array<string,string>,error_levels?:string[]}>
*/
public function providerValidCodeParse(): iterable
{
return [
'intRangeContained' => [
'<?php
/**
* @param int<1,12> $a
* @return int<-1, max>
*/
function scope(int $a){
return $a;
}',
],
'positiveIntRange' => [
'<?php
/**
* @param int<1,12> $a
* @return positive-int
*/
function scope(int $a){
return $a;
}',
],
'intRangeToInt' => [
'<?php
/**
* @param int<1,12> $a
* @return int
*/
function scope(int $a){
return $a;
}',
],
'intReduced' => [
'<?php
function getInt(): int{return 0;}
$a = getInt();
assert($a >= 500);
assert($a < 5000);',
'assertions' => [
'$a===' => 'int<500, 4999>'
]
],
];
}
/**
* @return iterable<string,array{string,error_message:string,1?:string[],2?:bool,3?:string}>
*/
public function providerInvalidCodeParse(): iterable
{
return [
'intRangeNotContained' => [
'<?php
/**
* @param int<1,12> $a
* @return int<-1, 11>
* @psalm-suppress InvalidReturnStatement
*/
function scope(int $a){
return $a;
}',
'error_message' => 'InvalidReturnType',
],
];
}
}