1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-27 04:45:20 +01:00
psalm/tests/IssetTest.php
Jon Ursenbach 11bc153deb Rewriting and streamlining every unit test with data providers. (#147)
* Rewriting and streamlining every unit test with data providers.

All unit tests have been rewritten into PHPUnit data providers
to reduce the amount of unnecessary code-reuse through out the
test suite.
2017-04-24 23:45:02 -04:00

81 lines
2.4 KiB
PHP

<?php
namespace Psalm\Tests;
class IssetTest extends TestCase
{
use Traits\FileCheckerValidCodeParseTestTrait;
/**
* @return array
*/
public function providerFileCheckerValidCodeParse()
{
return [
'isset' => [
'<?php
$a = isset($b) ? $b : null;',
'assertions' => [
['mixed' => '$a']
],
'error_levels' => ['MixedAssignment']
],
'nullCoalesce' => [
'<?php
$a = $b ?? null;',
'assertions' => [
['mixed' => '$a']
],
'error_levels' => ['MixedAssignment']
],
'nullCoalesceWithGoodVariable' => [
'<?php
$b = false;
$a = $b ?? null;',
'assertions' => [
['false|null' => '$a']
]
],
'issetKeyedOffset' => [
'<?php
if (!isset($foo["a"])) {
$foo["a"] = "hello";
}',
'assertions' => [
['mixed' => '$foo[\'a\']']
],
'error_levels' => [],
'scope_vars' => [
'$foo' => \Psalm\Type::getArray()
]
],
'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' => [
'$foo' => \Psalm\Type::getArray()
]
],
'nullCoalesceKeyedOffset' => [
'<?php
$foo["a"] = $foo["a"] ?? "hello";',
'assertions' => [
['mixed' => '$foo[\'a\']']
],
'error_levels' => ['MixedAssignment'],
'scope_vars' => [
'$foo' => \Psalm\Type::getArray()
]
]
];
}
}