[ 'foo(); }', ], 'dropInReplacementForAssert' => [ ' [ 'bar(); $a->foo(); }', ], 'assertInstanceOfMultipleInterfaces' => [ 'bar(); $a->foo1(); }', ], 'assertInstanceOfBInClassMethod' => [ 'assertInstanceOfB($a); $a->foo(); } }', ], 'assertPropertyNotNull' => [ 'a) { throw new \Exception(); } } public function takesA(A $a): void { $this->assertNotNullProperty(); $a->foo(); } }', ], 'assertWithoutRedundantCondition' => [ ' [ 'foo(); }', ], 'assertIfTrueAnnotation' => [ ' [ ' [ ' [ 'sayHello();' ], 'dontBleedBadAssertVarIntoContext' => [ 'foo()); assertFalse($a->bar()); }' ], 'suppressRedundantCondition' => [ ' [ ' [ ' [ ' [ ' $i * * @param iterable $i */ function assertAllStrings(iterable $i): void { /** @psalm-suppress MixedAssignment */ foreach ($i as $s) { if (!is_string($s)) { throw new \UnexpectedValueException(""); } } } function getArray(): array { return []; } function getIterable(): iterable { return []; } $array = getArray(); assertAllStrings($array); $iterable = getIterable(); assertAllStrings($iterable);', [ '$array' => 'array', '$iterable' => 'iterable', ] ], 'assertAllArrayOfClass' => [ ' $i * * @param iterable $i * @param class-string $type */ function assertAllInstanceOf(iterable $i, string $type): void { /** @psalm-suppress MixedAssignment */ foreach ($i as $elt) { if (!$elt instanceof $type) { throw new \UnexpectedValueException(""); } } } class A {} function getArray(): array { return []; } $array = getArray(); assertAllInstanceOf($array, A::class);', [ '$array' => 'array', ] ], 'assertAllIterableOfClass' => [ ' $i * * @param iterable $i * @param class-string $type */ function assertAllInstanceOf(iterable $i, string $type): void { /** @psalm-suppress MixedAssignment */ foreach ($i as $elt) { if (!$elt instanceof $type) { throw new \UnexpectedValueException(""); } } } class A {} function getIterable(): iterable { return []; } $iterable = getIterable(); assertAllInstanceOf($iterable, A::class);', [ '$iterable' => 'iterable', ] ], 'complicatedAssertAllInstanceOf' => [ ' $i * * @param iterable $i * @param class-string $type */ function allInstanceOf(iterable $i, string $type): bool { /** @psalm-suppress MixedAssignment */ foreach ($i as $elt) { if (!$elt instanceof $type) { return false; } } return true; } interface IBlogPost { public function getId(): int; } function getData(): iterable { return []; } $data = getData(); assert(allInstanceOf($data, IBlogPost::class)); foreach ($data as $post) { echo $post->getId(); }', ], ]; } /** * @return array */ public function providerInvalidCodeParse() { return [ 'assertInstanceOfMultipleInterfaces' => [ 'bar(); $a->foo1(); }', 'error_message' => 'UndefinedMethod', ], 'assertIfTrueNoAnnotation' => [ ' 'PossiblyNullOperand', ], 'assertIfFalseNoAnnotation' => [ ' 'PossiblyNullOperand', ], 'assertIfTrueMethodCall' => [ 'isInt($p)) { strlen($p); } } }', 'error_message' => 'InvalidScalarArgument', ], 'assertIfStaticTrueMethodCall' => [ 'isInt($p)) { strlen($p); } } }', 'error_message' => 'InvalidScalarArgument', ], 'noFatalForUnknownAssertClass' => [ 'sayHello();', 'error_message' => 'UndefinedClass', ], 'detectRedundantCondition' => [ ' 'RedundantCondition' ], 'detectAssertSameTypeDoesNotContainType' => [ ' 'TypeDoesNotContainType' ], 'detectAssertAlwaysSame' => [ ' 'RedundantCondition' ], 'detectNeverCanBeSameAfterAssertion' => [ ' 'TypeDoesNotContainType' ], 'detectNeverCanBeNotSameAfterAssertion' => [ ' 'RedundantCondition' ], 'detectNeverCanBeEqualAfterAssertion' => [ ' 'TypeDoesNotContainType' ], 'detectIntFloatNeverCanBeEqualAfterAssertion' => [ ' 'TypeDoesNotContainType' ], 'detectFloatIntNeverCanBeEqualAfterAssertion' => [ ' 'TypeDoesNotContainType' ], ]; } }