1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-22 13:51:54 +01:00
psalm/tests/AssignmentTest.php

67 lines
1.7 KiB
PHP
Raw Normal View History

<?php
namespace Psalm\Tests;
class AssignmentTest extends TestCase
{
2018-11-05 21:57:36 -05:00
use Traits\InvalidCodeAnalysisTestTrait;
use Traits\ValidCodeAnalysisTestTrait;
2017-01-13 14:07:23 -05:00
/**
* @return array
2017-01-13 14:07:23 -05:00
*/
2018-11-05 21:57:36 -05:00
public function providerValidCodeParse()
{
return [
'nestedAssignment' => [
'<?php
$a = $b = $c = 5;',
'assertions' => [
2017-06-29 10:22:49 -04:00
'$a' => 'int',
2017-05-26 20:05:57 -04:00
],
],
2019-01-11 14:57:21 -05:00
'assignmentInByRefParams' => [
'<?php
function foo(?string $s, ?string $t): void {}
foo($s = null, $t = null);
echo $s;
echo $t;
function foo2(?string &$u, ?string &$v): void {}
foo2($u = null, $v = null);
echo $u;
echo $v;
$read = [fopen(\'php://stdin\', \'rb\')];
$return = stream_select($read, $w = null, $e = null, 0);
echo $w;
echo $e;',
],
'bitwiseAssignment' => [
'<?php
$x = 0;
$x |= (int) (rand(0, 1) !== 2);
$x |= 1;
if ($x) {
echo $x;
}',
],
];
}
/**
* @return array
*/
2018-11-05 21:57:36 -05:00
public function providerInvalidCodeParse()
{
return [
'mixedAssignment' => [
'<?php
/** @var mixed */
$a = 5;
$b = $a;',
2017-05-26 20:05:57 -04:00
'error_message' => 'MixedAssignment',
],
];
2017-02-12 18:06:18 -05:00
}
}