2016-12-09 18:07:47 +01:00
|
|
|
<?php
|
|
|
|
namespace Psalm\Tests;
|
|
|
|
|
2017-04-25 05:45:02 +02:00
|
|
|
class ArgTest extends TestCase
|
2016-12-09 18:07:47 +01:00
|
|
|
{
|
2017-04-25 05:45:02 +02:00
|
|
|
use Traits\FileCheckerInvalidCodeParseTestTrait;
|
|
|
|
use Traits\FileCheckerValidCodeParseTestTrait;
|
2017-01-02 21:31:18 +01:00
|
|
|
|
2017-01-13 20:07:23 +01:00
|
|
|
/**
|
2017-04-25 05:45:02 +02:00
|
|
|
* @return array
|
2017-01-13 20:07:23 +01:00
|
|
|
*/
|
2017-04-25 05:45:02 +02:00
|
|
|
public function providerFileCheckerValidCodeParse()
|
2016-12-09 18:07:47 +01:00
|
|
|
{
|
2017-04-25 05:45:02 +02:00
|
|
|
return [
|
|
|
|
'callMapClassOptionalArg' => [
|
|
|
|
'<?php
|
|
|
|
$m = new ReflectionMethod("hello", "goodbye");
|
2017-05-27 02:05:57 +02:00
|
|
|
$m->invoke("cool");',
|
|
|
|
],
|
2017-10-28 19:56:29 +02:00
|
|
|
'sortFunctions' => [
|
|
|
|
'<?php
|
|
|
|
$a = ["b" => 5, "a" => 8];
|
|
|
|
ksort($a);
|
|
|
|
$b = ["b" => 5, "a" => 8];
|
|
|
|
sort($b);
|
|
|
|
',
|
|
|
|
'assertions' => [
|
|
|
|
'$a' => 'array<string, int>',
|
|
|
|
'$b' => 'array<int, int>',
|
|
|
|
],
|
|
|
|
],
|
|
|
|
'arrayModificationFunctions' => [
|
|
|
|
'<?php
|
|
|
|
$a = ["b" => 5, "a" => 8];
|
2017-12-09 20:53:39 +01:00
|
|
|
array_unshift($a, (bool)rand(0, 1));
|
2017-10-28 19:56:29 +02:00
|
|
|
$b = ["b" => 5, "a" => 8];
|
2017-12-09 20:53:39 +01:00
|
|
|
array_push($b, (bool)rand(0, 1));
|
2017-10-28 19:56:29 +02:00
|
|
|
',
|
|
|
|
'assertions' => [
|
|
|
|
'$a' => 'array<string|int, int|bool>',
|
|
|
|
'$b' => 'array<string|int, int|bool>',
|
|
|
|
],
|
|
|
|
],
|
2017-10-28 21:33:29 +02:00
|
|
|
'byRefArgAssignment' => [
|
|
|
|
'<?php
|
|
|
|
$a = ["hello", "goodbye"];
|
|
|
|
shuffle($a);
|
|
|
|
$a = [0, 1];',
|
|
|
|
],
|
2017-04-25 05:45:02 +02:00
|
|
|
];
|
2016-12-09 18:07:47 +01:00
|
|
|
}
|
2017-04-08 15:28:02 +02:00
|
|
|
|
|
|
|
/**
|
2017-04-25 05:45:02 +02:00
|
|
|
* @return array
|
2017-04-08 15:28:02 +02:00
|
|
|
*/
|
2017-04-25 05:45:02 +02:00
|
|
|
public function providerFileCheckerInvalidCodeParse()
|
2017-04-08 15:28:02 +02:00
|
|
|
{
|
2017-04-25 05:45:02 +02:00
|
|
|
return [
|
|
|
|
'possiblyInvalidArgument' => [
|
|
|
|
'<?php
|
|
|
|
$foo = [
|
|
|
|
"a",
|
|
|
|
["b"],
|
|
|
|
];
|
2017-10-28 19:56:29 +02:00
|
|
|
|
2017-04-25 05:45:02 +02:00
|
|
|
$a = array_map(
|
|
|
|
function (string $uuid) : string {
|
|
|
|
return $uuid;
|
|
|
|
},
|
|
|
|
$foo[rand(0, 1)]
|
|
|
|
);',
|
2017-05-27 02:05:57 +02:00
|
|
|
'error_message' => 'PossiblyInvalidArgument',
|
|
|
|
],
|
2017-04-08 15:28:02 +02:00
|
|
|
];
|
|
|
|
}
|
2016-12-09 18:07:47 +01:00
|
|
|
}
|