From c796e5980a3fa025e30418fa2b76ca096dc9a58d Mon Sep 17 00:00:00 2001 From: Pol Dellaiera Date: Tue, 6 Jul 2021 17:59:32 +0200 Subject: [PATCH] Add static analysis tests - basically a ripoff of filter. --- tests/static-analysis/reject.php | 48 ++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 tests/static-analysis/reject.php diff --git a/tests/static-analysis/reject.php b/tests/static-analysis/reject.php new file mode 100644 index 000000000..2beb2ad6d --- /dev/null +++ b/tests/static-analysis/reject.php @@ -0,0 +1,48 @@ + $collection + */ +function reject_checkList(CollectionInterface $collection): void +{ +} +/** + * @param CollectionInterface $collection + */ +function reject_checkMap(CollectionInterface $collection): void +{ +} + +$intValueCallback = static fn (int $value): bool => $value % 2 === 0; +$intValueCallback2 = static fn (int $value): bool => 2 < $value; +$intKeyValueCallback1 = static fn (int $value, int $key): bool => $value % 2 === 0 && $key % 2 === 0; +$intKeyValueCallback2 = static fn (int $value, int $key): bool => 2 < $value && 2 < $key; + +$stringValueCallback = static fn (string $value): bool => 'bar' === $value; +$stringValueCallback2 = static fn (string $value): bool => '' === $value; +$stringKeyValueCallback1 = static fn (string $value, string $key): bool => 'bar' !== $value && 'foo' !== $key; +$stringKeyValueCallback2 = static fn (string $value, string $key): bool => 'bar' !== $value && '' === $key; + +reject_checkList(Collection::fromIterable([1, 2, 3])->filter()); +reject_checkList(Collection::fromIterable([1, 2, 3])->filter($intValueCallback)); +reject_checkList(Collection::fromIterable([1, 2, 3])->filter($intValueCallback, $intValueCallback2)); +reject_checkList(Collection::fromIterable([1, 2, 3])->filter($intKeyValueCallback1)); +reject_checkList(Collection::fromIterable([1, 2, 3])->filter($intKeyValueCallback1, $intKeyValueCallback2)); + +reject_checkMap(Collection::fromIterable(['foo' => 'bar', 'baz' => ''])->filter()); +reject_checkMap(Collection::fromIterable(['foo' => 'bar', 'baz' => ''])->filter($stringValueCallback)); +reject_checkMap(Collection::fromIterable(['foo' => 'bar', 'baz' => ''])->filter($stringValueCallback, $stringValueCallback2)); +reject_checkMap(Collection::fromIterable(['foo' => 'bar', 'baz' => ''])->filter($stringKeyValueCallback1)); +reject_checkMap(Collection::fromIterable(['foo' => 'bar', 'baz' => ''])->filter($stringKeyValueCallback1, $stringKeyValueCallback2));