mirror of
https://github.com/danog/psalm.git
synced 2024-12-14 02:07:37 +01:00
425d9fa8bf
Previously `(array)(object)['a' => 1, 'b' => 'foo']` would result in `array<array-key, mixed>`. Now it would be inferred as `array{a:1,b:foo,...<array-key,mixed>}`
54 lines
1.5 KiB
PHP
54 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace Psalm\Tests;
|
|
|
|
use Psalm\Tests\Traits\ValidCodeAnalysisTestTrait;
|
|
|
|
class CastTest extends TestCase
|
|
{
|
|
use ValidCodeAnalysisTestTrait;
|
|
|
|
public function providerValidCodeParse(): iterable
|
|
{
|
|
yield 'SKIPPED-castFalseOrIntToInt' => [
|
|
'code' => '<?php
|
|
/** @var false|int<10, 20> */
|
|
$intOrFalse = 10;
|
|
$int = (int) $intOrFalse;
|
|
',
|
|
'assertions' => [
|
|
'$int===' => '0|int<10, 20>',
|
|
],
|
|
];
|
|
yield 'SKIPPED-castTrueOrIntToInt' => [
|
|
'code' => '<?php
|
|
/** @var true|int<10, 20> */
|
|
$intOrTrue = 10;
|
|
$int = (int) $intOrTrue;
|
|
',
|
|
'assertions' => [
|
|
'$int===' => '1|int<10, 20>',
|
|
],
|
|
];
|
|
yield 'SKIPPED-castBoolOrIntToInt' => [
|
|
'code' => '<?php
|
|
/** @var bool|int<10, 20> */
|
|
$intOrBool = 10;
|
|
$int = (int) $intOrBool;
|
|
',
|
|
'assertions' => [
|
|
'$int===' => '0|1|int<10, 20>',
|
|
],
|
|
];
|
|
yield 'castObjectWithPropertiesToArray' => [
|
|
'code' => '<?php
|
|
/** @var object{a:int,b:string} $o */
|
|
$a = (array) $o;
|
|
',
|
|
'assertions' => [
|
|
'$a===' => 'array{a: int, b: string, ...<array-key, mixed>}',
|
|
],
|
|
];
|
|
}
|
|
}
|