From 4dc74e9c10b978e5c160b9253f4c96733b3546ae Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Wed, 26 Jan 2022 12:18:05 +0100 Subject: [PATCH] Cleanup tests --- .../InvalidTraversableImplementation.md | 3 +++ tests/ArrayAccessTest.php | 6 +++++ tests/ArrayAssignmentTest.php | 6 +++++ tests/AttributeTest.php | 6 +++++ tests/FunctionCallTest.php | 8 +++++- tests/Loop/ForeachTest.php | 9 +++++++ tests/MagicMethodAnnotationTest.php | 1 + tests/MethodSignatureTest.php | 3 +++ tests/MixinAnnotationTest.php | 3 +++ tests/Php71Test.php | 3 +++ tests/Template/ClassTemplateTest.php | 27 +++++++++++++++++-- tests/UnusedCodeTest.php | 2 +- tests/UnusedVariableTest.php | 1 + 13 files changed, 74 insertions(+), 4 deletions(-) diff --git a/docs/running_psalm/issues/InvalidTraversableImplementation.md b/docs/running_psalm/issues/InvalidTraversableImplementation.md index 52fc8b02046..e275818f702 100644 --- a/docs/running_psalm/issues/InvalidTraversableImplementation.md +++ b/docs/running_psalm/issues/InvalidTraversableImplementation.md @@ -6,5 +6,8 @@ implemented by implementing either `IteratorAggregate` or `Iterator` ```php + */ final class C implements Traversable {} // will cause fatal error ``` diff --git a/tests/ArrayAccessTest.php b/tests/ArrayAccessTest.php index 76b07b1cb07..de1b02ece93 100644 --- a/tests/ArrayAccessTest.php +++ b/tests/ArrayAccessTest.php @@ -719,6 +719,9 @@ function getArray() : array { return []; } $c = isset($array["foo"]) ? $array["foo"] : null; + /** + * @psalm-suppress MissingTemplateParam + */ class C implements ArrayAccess { /** @@ -875,6 +878,9 @@ class A { public function foo() : void {} } + /** + * @psalm-suppress MissingTemplateParam + */ class C implements ArrayAccess { /** diff --git a/tests/ArrayAssignmentTest.php b/tests/ArrayAssignmentTest.php index 5a7c7f6c1ec..a5f4bf4f032 100644 --- a/tests/ArrayAssignmentTest.php +++ b/tests/ArrayAssignmentTest.php @@ -689,6 +689,9 @@ function getThings(): array { ], 'implementsArrayAccess' => [ ' + */ class A implements \ArrayAccess { /** * @param string|int $offset @@ -734,6 +737,9 @@ public function offsetGet($offset) { ], 'implementsArrayAccessInheritingDocblock' => [ ' + */ class A implements \ArrayAccess { /** diff --git a/tests/AttributeTest.php b/tests/AttributeTest.php index 25a8b1bcddd..92c190e98d1 100644 --- a/tests/AttributeTest.php +++ b/tests/AttributeTest.php @@ -208,6 +208,9 @@ class Baz {} use IteratorAggregate; use ReturnTypeWillChange; + /** + * @psalm-suppress MissingTemplateParam + */ final class EmptyCollection implements IteratorAggregate { #[ReturnTypeWillChange] @@ -229,6 +232,9 @@ public function getIterator() use IteratorAggregate; use ReturnTypeWillChange; + /** + * @psalm-suppress MissingTemplateParam + */ final class EmptyCollection implements IteratorAggregate { #[ReturnTypeWillChange] diff --git a/tests/FunctionCallTest.php b/tests/FunctionCallTest.php index 955cc9b13e3..df7d53fccc6 100644 --- a/tests/FunctionCallTest.php +++ b/tests/FunctionCallTest.php @@ -510,6 +510,9 @@ function generator(): Generator { ], 'iteratorToArrayWithGetIterator' => [ '> + */ class C implements IteratorAggregate { /** * @return Traversable @@ -525,9 +528,12 @@ public function getIterator() { ], 'iteratorToArrayWithGetIteratorReturningList' => [ '> + */ class C implements IteratorAggregate { /** - * @return Traversable + * @return Traversable */ public function getIterator() { yield 1 => "1"; diff --git a/tests/Loop/ForeachTest.php b/tests/Loop/ForeachTest.php index 815b51d673d..b6c8802cee9 100644 --- a/tests/Loop/ForeachTest.php +++ b/tests/Loop/ForeachTest.php @@ -686,6 +686,9 @@ function foo(array $arr): void { ], 'iteratorAggregateIteration' => [ '> + */ class Collection implements IteratorAggregate { /** * @var Item[] @@ -878,6 +884,9 @@ function Foo(int $a, int $b, int ...$ints) : array { ' [ ' [ ' + */ class Subject implements Iterator { /** * the index method exists diff --git a/tests/Php71Test.php b/tests/Php71Test.php index 3c581250b5e..8da79a54f20 100644 --- a/tests/Php71Test.php +++ b/tests/Php71Test.php @@ -197,6 +197,9 @@ function iterator(iterable $iter): void ], 'traversableObject' => [ ' + */ class IteratorObj implements Iterator { function rewind(): void {} /** @return mixed */ diff --git a/tests/Template/ClassTemplateTest.php b/tests/Template/ClassTemplateTest.php index 5a50e25d0db..509ec5bd94f 100644 --- a/tests/Template/ClassTemplateTest.php +++ b/tests/Template/ClassTemplateTest.php @@ -531,24 +531,37 @@ function(Collection $elt): bool { return true; } /** * @template TKey * @template TValue + * + * @extends \IteratorAggregate> */ interface ICollection extends \IteratorAggregate { /** @return \Traversable */ public function getIterator(); } + /** + * @template TKey as array-key + * @template TValue + * + * @implements ICollection + */ class Collection implements ICollection { - /** @var array */ + /** @var array */ private $data; + /** + * @param array $data + */ public function __construct(array $data) { $this->data = $data; } + /** + * @return \Traversable + */ public function getIterator(): \Traversable { return new \ArrayIterator($this->data); } } - /** @var ICollection */ $c = new Collection(["a" => 1]); foreach ($c as $k => $v) { atan($v); strlen($k); }', @@ -862,6 +875,7 @@ public function getValue() } /** + * @psalm-suppress MissingTemplateParam * @template TKey * @template TValue */ @@ -926,6 +940,8 @@ public function getValue() /** * @template TKey * @template Tv + * + * @psalm-suppress MissingTemplateParam */ class KeyValueContainer extends ValueContainer { @@ -985,6 +1001,9 @@ public function getID() } } + /** + * @psalm-suppress MissingTemplateParam + */ class AppUser extends User {} $au = new AppUser(-1); @@ -1732,6 +1751,7 @@ interface IParent { function foo(); } + /** @psalm-suppress MissingTemplateParam */ interface IChild extends IParent {} class C {} @@ -1766,6 +1786,8 @@ class C {} * @psalm-param class-string $className * * @psalm-return T&I + * + * @psalm-suppress MissingTemplateParam */ function makeConcrete(string $className) : object { @@ -1926,6 +1948,7 @@ class Foo { /** @psalm-param T $val */ public function set($val) : void { $this->value = $val; + /** @psalm-suppress MissingTemplateParam */ new class extends Foo {}; } diff --git a/tests/UnusedCodeTest.php b/tests/UnusedCodeTest.php index 341de7fe61c..9f9f7d93f8a 100644 --- a/tests/UnusedCodeTest.php +++ b/tests/UnusedCodeTest.php @@ -739,7 +739,7 @@ public function unserialize($_serialized) : void {} ], 'useIteratorMethodsWhenCallingForeach' => [ '