1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-22 05:41:20 +01:00

fix tests for the last time............................................... maybe?

This commit is contained in:
orklah 2021-08-05 21:48:37 +02:00
parent ba2f623754
commit 10049450f8

View File

@ -25,7 +25,7 @@ class AnnotationTest extends TestCase
$this->addFile( $this->addFile(
'somefile.php', 'somefile.php',
'<?php '<?php
function takesString(string $s): void {} function takesString(string $_s): void {}
/** @param ArrayIterator|string[] $i */ /** @param ArrayIterator|string[] $i */
function takesArrayIteratorOfString(ArrayIterator $i): void { function takesArrayIteratorOfString(ArrayIterator $i): void {
@ -48,7 +48,7 @@ class AnnotationTest extends TestCase
$this->addFile( $this->addFile(
'somefile.php', 'somefile.php',
'<?php '<?php
function takesString(string $s): void {} function takesString(string $_s): void {}
/** @param Traversable|string[] $i */ /** @param Traversable|string[] $i */
function takesTraversableOfString(Traversable $i): void { function takesTraversableOfString(Traversable $i): void {
@ -113,7 +113,7 @@ class AnnotationTest extends TestCase
$this->addFile( $this->addFile(
'somefile.php', 'somefile.php',
'<?php '<?php
function takesString(string $s): void {} function takesString(string $_s): void {}
/** @param iterable|string[] $i */ /** @param iterable|string[] $i */
function takesArrayIteratorOfString(iterable $i): void { function takesArrayIteratorOfString(iterable $i): void {
@ -193,10 +193,10 @@ class AnnotationTest extends TestCase
'somefile.php', 'somefile.php',
'<?php '<?php
/** /**
* @param array $arr * @param array $_arr
* @return void * @return void
*/ */
function foo($arr = false) {} function foo($_arr = false) {}
foo(false); foo(false);
foo(["hello"]);' foo(["hello"]);'
); );
@ -228,11 +228,11 @@ class AnnotationTest extends TestCase
return [ return [
'nopType' => [ 'nopType' => [
'<?php '<?php
$a = "hello"; $_a = "hello";
/** @var int $a */', /** @var int $_a */',
'assertions' => [ 'assertions' => [
'$a' => 'int', '$_a' => 'int',
], ],
], ],
'validDocblockReturn' => [ 'validDocblockReturn' => [
@ -326,7 +326,7 @@ class AnnotationTest extends TestCase
return rand(0, 1) ? new A(): null; return rand(0, 1) ? new A(): null;
} }
function takeA(A $a): void { } function takeA(A $_a): void { }
$a = makeA(); $a = makeA();
$a->foo(); $a->foo();
@ -336,10 +336,10 @@ class AnnotationTest extends TestCase
'invalidDocblockParamSuppress' => [ 'invalidDocblockParamSuppress' => [
'<?php '<?php
/** /**
* @param int $bar * @param int $_bar
* @psalm-suppress MismatchingDocblockParamType * @psalm-suppress MismatchingDocblockParamType
*/ */
function fooFoo(array $bar): void { function fooFoo(array $_bar): void {
}', }',
], ],
'differentDocblockParamClassSuppress' => [ 'differentDocblockParamClassSuppress' => [
@ -348,10 +348,10 @@ class AnnotationTest extends TestCase
class B {} class B {}
/** /**
* @param B $bar * @param B $_bar
* @psalm-suppress MismatchingDocblockParamType * @psalm-suppress MismatchingDocblockParamType
*/ */
function fooFoo(A $bar): void { function fooFoo(A $_bar): void {
}', }',
], ],
'varDocblock' => [ 'varDocblock' => [
@ -359,7 +359,7 @@ class AnnotationTest extends TestCase
/** @var array<Exception> */ /** @var array<Exception> */
$a = []; $a = [];
$a[0]->getMessage();', echo $a[0]->getMessage();',
], ],
'ignoreVarDocblock' => [ 'ignoreVarDocblock' => [
'<?php '<?php
@ -434,14 +434,14 @@ class AnnotationTest extends TestCase
], ],
'psalmParam' => [ 'psalmParam' => [
'<?php '<?php
function takesInt(int $a): void {} function takesInt(int $_a): void {}
/** /**
* @psalm-param array<int, string> $a * @psalm-param array<int, string> $a
* @param string[] $a * @param string[] $a
*/ */
function foo(array $a): void { function foo(array $a): void {
foreach ($a as $key => $value) { foreach ($a as $key => $_value) {
takesInt($key); takesInt($key);
} }
}', }',
@ -459,42 +459,42 @@ class AnnotationTest extends TestCase
return ["hello" => new stdClass, "goodbye" => new stdClass]; return ["hello" => new stdClass, "goodbye" => new stdClass];
} }
$a = null; $_a = null;
$b = null; $_b = null;
/** /**
* @var string $key * @var string $_key
* @var stdClass $value * @var stdClass $_value
*/ */
foreach (foo() as $key => $value) { foreach (foo() as $_key => $_value) {
$a = $key; $_a = $_key;
$b = $value; $_b = $_value;
}', }',
'assertions' => [ 'assertions' => [
'$a' => 'null|string', '$_a' => 'null|string',
'$b' => 'null|stdClass', '$_b' => 'null|stdClass',
], ],
], ],
'allowOptionalParamsToBeEmptyArray' => [ 'allowOptionalParamsToBeEmptyArray' => [
'<?php '<?php
/** @param array{b?: int, c?: string} $a */ /** @param array{b?: int, c?: string} $_a */
function foo(array $a = []) : void {}', function foo(array $_a = []) : void {}',
], ],
'allowEmptyVarAnnotation' => [ 'allowEmptyVarAnnotation' => [
'<?php '<?php
/** /**
* @param $x * @param $_x
*/ */
function example(array $x) : void {}', function example(array $_x) : void {}',
], ],
'allowCapitalisedNamespacedString' => [ 'allowCapitalisedNamespacedString' => [
'<?php '<?php
namespace Foo; namespace Foo;
/** /**
* @param String $x * @param String $_x
*/ */
function example(string $x) : void {}', function example(string $_x) : void {}',
], ],
'megaClosureAnnotationWithoutSpacing' => [ 'megaClosureAnnotationWithoutSpacing' => [
'<?php '<?php
@ -579,8 +579,8 @@ class AnnotationTest extends TestCase
'<?php '<?php
namespace ns; namespace ns;
/** @param ?\stdClass $s */ /** @param ?\stdClass $_s */
function foo($s) : void { function foo($_s) : void {
} }
foo(null); foo(null);
@ -600,10 +600,10 @@ class AnnotationTest extends TestCase
], ],
'spreadOperatorAnnotation' => [ 'spreadOperatorAnnotation' => [
'<?php '<?php
/** @param string[] $s */ /** @param string[] $_s */
function foo(string ...$s) : void {} function foo(string ...$_s) : void {}
/** @param string ...$s */ /** @param string ...$_s */
function bar(string ...$s) : void {} function bar(string ...$_s) : void {}
foo("hello", "goodbye"); foo("hello", "goodbye");
bar("hello", "goodbye"); bar("hello", "goodbye");
foo(...["hello", "goodbye"]); foo(...["hello", "goodbye"]);
@ -668,8 +668,8 @@ class AnnotationTest extends TestCase
return null; return null;
} }
/** @param CoolType $a **/ /** @param CoolType $_a **/
function bar ($a) : void { } function bar ($_a) : void { }
bar(foo());', bar(foo());',
], ],
@ -695,8 +695,8 @@ class AnnotationTest extends TestCase
class A {} class A {}
class B {} class B {}
/** @param CoolType $a **/ /** @param CoolType $_a **/
function bar ($a) : void { } function bar ($_a) : void { }
bar(foo());', bar(foo());',
], ],
@ -723,8 +723,8 @@ class AnnotationTest extends TestCase
class A {} class A {}
class B {} class B {}
/** @param CoolType $a **/ /** @param CoolType $_a **/
function bar ($a) : void { } function bar ($_a) : void { }
bar(foo());', bar(foo());',
], ],
@ -752,8 +752,8 @@ class AnnotationTest extends TestCase
return null; return null;
} }
/** @param CoolType $a **/ /** @param CoolType $_a **/
function bar ($a) : void { } function bar ($_a) : void { }
bar(foo());', bar(foo());',
], ],
@ -806,7 +806,7 @@ class AnnotationTest extends TestCase
} }
/** @var A $a1 */ /** @var A $a1 */
[$a1, $a2] = foo(); [$a1, $_a2] = foo();
$a1->bar();', $a1->bar();',
], ],
@ -921,11 +921,11 @@ class AnnotationTest extends TestCase
'extraneousDocblockParamName' => [ 'extraneousDocblockParamName' => [
'<?php '<?php
/** /**
* @param string $foo * @param string $_foo
* @param string[] $bar * @param string[] $bar
* @param string[] $barb * @param string[] $_barb
*/ */
function f(string $foo, array $barb): void {}', function f(string $_foo, array $_barb): void {}',
], ],
'nonEmptyArray' => [ 'nonEmptyArray' => [
'<?php '<?php
@ -1020,9 +1020,9 @@ class AnnotationTest extends TestCase
* foo:string, * foo:string,
* bar:string, * bar:string,
* baz:string, * baz:string,
* } $foo * } $_foo
*/ */
$foo = ["foo" => "", "bar" => "", "baz" => ""];', $_foo = ["foo" => "", "bar" => "", "baz" => ""];',
], ],
'returnNumber' => [ 'returnNumber' => [
'<?php '<?php
@ -1145,17 +1145,17 @@ class AnnotationTest extends TestCase
], ],
'arrayWithKeySlashesAndNewline' => [ 'arrayWithKeySlashesAndNewline' => [
'<?php '<?php
$arr = ["foo\\bar\nbaz" => "literal"];', $_arr = ["foo\\bar\nbaz" => "literal"];',
[ [
'$arr' => 'array{\'foo\\\\bar\nbaz\': string}' '$_arr' => 'array{\'foo\\\\bar\nbaz\': string}'
] ]
], ],
'doubleSpaceBeforeAt' => [ 'doubleSpaceBeforeAt' => [
'<?php '<?php
/** /**
* @param string $c * @param string $_c
*/ */
function foo($c) : void {}' function foo($_c) : void {}'
], ],
'throwsAnnotationWithBarAndSpace' => [ 'throwsAnnotationWithBarAndSpace' => [
'<?php '<?php
@ -1174,7 +1174,7 @@ class AnnotationTest extends TestCase
} }
} }
function takesString(string $s): void {}' function takesString(string $_s): void {}'
], ],
'noCrashWithoutAssignment' => [ 'noCrashWithoutAssignment' => [
'<?php '<?php