Skip to content

Commit

Permalink
tests: update diff SA tests
Browse files Browse the repository at this point in the history
  • Loading branch information
drupol committed Nov 2, 2022
1 parent 0af490e commit ece6067
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions tests/static-analysis/diff.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,26 @@ function diff_checkMap(CollectionInterface $collection): void
diff_checkMap(Collection::fromIterable(['foo' => 'f', 'bar' => 'b'])->diff(...$stringGen()));
diff_checkMap(Collection::fromIterable(['foo' => 'f', 'bar' => 'b'])->diff(...$stringCol));

diff_checkList(Collection::fromIterable([1, 2, 3])->diff(...$stringCol));
diff_checkMap(Collection::fromIterable(['foo' => 'f', 'bar' => 'b'])->diff(1, 'f'));
diff_checkMap(Collection::fromIterable(['foo' => 'f', 'bar' => 'b'])->diff(...$intCol));

// This is valid in PHP 8 but Psalm does not allow it (unpacking string keys)
/** @psalm-suppress InvalidArgument */
diff_checkMap(Collection::fromIterable(['foo' => 'f', 'bar' => 'b'])->diff(...Collection::fromIterable(['foo' => 'f'])));
/** @psalm-suppress InvalidArgument */
diff_checkMap(Collection::fromIterable(['foo' => 'f', 'bar' => 'b'])->diff(...(static fn (): Generator => yield 'bar' => 'b')()));

diff_checkList(Collection::fromIterable([1, 2, 3])->diff(...$stringCol));
diff_checkMap(Collection::fromIterable(['foo' => 'f', 'bar' => 'b'])->diff(...$intCol));

// VALID failures -> usage with wrong types
/** @psalm-suppress InvalidArgument */
diff_checkList(Collection::fromIterable([1, 2, 3])->diff('a'));
/** @psalm-suppress InvalidArgument */
diff_checkList(Collection::fromIterable([1, 2, 3])->diff(1, 'a'));
diff_checkList(Collection::fromIterable([1, 2, 3])->diff(...$stringCol));

/** @psalm-suppress InvalidArgument */
diff_checkMap(Collection::fromIterable(['foo' => 'f', 'bar' => 'b'])->diff(1));
/** @psalm-suppress InvalidArgument */
diff_checkMap(Collection::fromIterable(['foo' => 'f', 'bar' => 'b'])->diff(1, 'f'));
diff_checkMap(Collection::fromIterable(['foo' => 'f', 'bar' => 'b'])->diff(...$intCol));

0 comments on commit ece6067

Please sign in to comment.