2017-02-18 02:50:47 +01:00
|
|
|
<?php
|
|
|
|
namespace Psalm\Tests;
|
|
|
|
|
2017-04-25 05:45:02 +02:00
|
|
|
class IssetTest extends TestCase
|
2017-02-18 02:50:47 +01:00
|
|
|
{
|
2017-04-25 05:45:02 +02:00
|
|
|
use Traits\FileCheckerValidCodeParseTestTrait;
|
2017-02-18 02:50:47 +01:00
|
|
|
|
|
|
|
/**
|
2017-04-25 05:45:02 +02:00
|
|
|
* @return array
|
2017-02-18 02:50:47 +01:00
|
|
|
*/
|
2017-04-25 05:45:02 +02:00
|
|
|
public function providerFileCheckerValidCodeParse()
|
2017-02-18 02:50:47 +01:00
|
|
|
{
|
2017-04-25 05:45:02 +02:00
|
|
|
return [
|
|
|
|
'isset' => [
|
|
|
|
'<?php
|
|
|
|
$a = isset($b) ? $b : null;',
|
|
|
|
'assertions' => [
|
2017-05-27 02:05:57 +02:00
|
|
|
['mixed' => '$a'],
|
2017-04-25 05:45:02 +02:00
|
|
|
],
|
2017-05-27 02:05:57 +02:00
|
|
|
'error_levels' => ['MixedAssignment'],
|
2017-04-25 05:45:02 +02:00
|
|
|
],
|
|
|
|
'nullCoalesce' => [
|
|
|
|
'<?php
|
|
|
|
$a = $b ?? null;',
|
|
|
|
'assertions' => [
|
2017-05-27 02:05:57 +02:00
|
|
|
['mixed' => '$a'],
|
2017-04-25 05:45:02 +02:00
|
|
|
],
|
2017-05-27 02:05:57 +02:00
|
|
|
'error_levels' => ['MixedAssignment'],
|
2017-04-25 05:45:02 +02:00
|
|
|
],
|
|
|
|
'nullCoalesceWithGoodVariable' => [
|
|
|
|
'<?php
|
|
|
|
$b = false;
|
|
|
|
$a = $b ?? null;',
|
|
|
|
'assertions' => [
|
2017-05-27 02:05:57 +02:00
|
|
|
['false|null' => '$a'],
|
|
|
|
],
|
2017-04-25 05:45:02 +02:00
|
|
|
],
|
|
|
|
'issetKeyedOffset' => [
|
|
|
|
'<?php
|
|
|
|
if (!isset($foo["a"])) {
|
|
|
|
$foo["a"] = "hello";
|
|
|
|
}',
|
|
|
|
'assertions' => [
|
2017-05-27 02:05:57 +02:00
|
|
|
['mixed' => '$foo[\'a\']'],
|
2017-04-25 05:45:02 +02:00
|
|
|
],
|
|
|
|
'error_levels' => [],
|
|
|
|
'scope_vars' => [
|
2017-05-27 02:05:57 +02:00
|
|
|
'$foo' => \Psalm\Type::getArray(),
|
|
|
|
],
|
2017-04-25 05:45:02 +02:00
|
|
|
],
|
|
|
|
'issetKeyedOffsetORFalse' => [
|
|
|
|
'<?php
|
|
|
|
/** @return void */
|
|
|
|
function takesString(string $str) {}
|
|
|
|
|
|
|
|
$bar = rand(0, 1) ? ["foo" => "bar"] : false;
|
|
|
|
|
|
|
|
if (isset($bar["foo"])) {
|
|
|
|
takesString($bar["foo"]);
|
|
|
|
}',
|
|
|
|
'assertions' => [],
|
|
|
|
'error_levels' => [],
|
|
|
|
'scope_vars' => [
|
2017-05-27 02:05:57 +02:00
|
|
|
'$foo' => \Psalm\Type::getArray(),
|
|
|
|
],
|
2017-04-25 05:45:02 +02:00
|
|
|
],
|
|
|
|
'nullCoalesceKeyedOffset' => [
|
|
|
|
'<?php
|
|
|
|
$foo["a"] = $foo["a"] ?? "hello";',
|
|
|
|
'assertions' => [
|
2017-05-27 02:05:57 +02:00
|
|
|
['mixed' => '$foo[\'a\']'],
|
2017-04-25 05:45:02 +02:00
|
|
|
],
|
|
|
|
'error_levels' => ['MixedAssignment'],
|
|
|
|
'scope_vars' => [
|
2017-05-27 02:05:57 +02:00
|
|
|
'$foo' => \Psalm\Type::getArray(),
|
|
|
|
],
|
|
|
|
],
|
2017-04-25 05:45:02 +02:00
|
|
|
];
|
2017-02-18 02:50:47 +01:00
|
|
|
}
|
|
|
|
}
|