From e346f741342405214ae0b6fdee6ad2c29f1791f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Tue, 12 Feb 2019 22:08:05 +0100 Subject: [PATCH] Enhancement: Implement UnwrapArrayUintersectAssoc mutator --- .../Unwrap/UnwrapArrayUintersectAssoc.php | 54 +++++ src/Mutator/Util/MutatorProfile.php | 2 + .../Unwrap/UnwrapArrayUintersectAssocTest.php | 201 ++++++++++++++++++ 3 files changed, 257 insertions(+) create mode 100644 src/Mutator/Unwrap/UnwrapArrayUintersectAssoc.php create mode 100644 tests/Mutator/Unwrap/UnwrapArrayUintersectAssocTest.php diff --git a/src/Mutator/Unwrap/UnwrapArrayUintersectAssoc.php b/src/Mutator/Unwrap/UnwrapArrayUintersectAssoc.php new file mode 100644 index 0000000000..123f6e6b44 --- /dev/null +++ b/src/Mutator/Unwrap/UnwrapArrayUintersectAssoc.php @@ -0,0 +1,54 @@ + Mutator\Unwrap\UnwrapArrayUdiff::class, 'UnwrapArrayUdiffAssoc' => Mutator\Unwrap\UnwrapArrayUdiffAssoc::class, 'UnwrapArrayUdiffUassoc' => Mutator\Unwrap\UnwrapArrayUdiffUassoc::class, + 'UnwrapArrayUintersectAssoc' => Mutator\Unwrap\UnwrapArrayUintersectAssoc::class, 'UnwrapArrayUnique' => Mutator\Unwrap\UnwrapArrayUnique::class, 'UnwrapArrayValues' => Mutator\Unwrap\UnwrapArrayValues::class, 'UnwrapStrRepeat' => Mutator\Unwrap\UnwrapStrRepeat::class, diff --git a/tests/Mutator/Unwrap/UnwrapArrayUintersectAssocTest.php b/tests/Mutator/Unwrap/UnwrapArrayUintersectAssocTest.php new file mode 100644 index 0000000000..1ac7a0f88a --- /dev/null +++ b/tests/Mutator/Unwrap/UnwrapArrayUintersectAssocTest.php @@ -0,0 +1,201 @@ +doTest($input, $expected); + } + + public function provideMutationCases(): \Generator + { + yield 'It mutates correctly when provided with an array' => [ + <<<'PHP' + 'bar'], ['baz' => 'bar'], $callback); +PHP + , + <<<'PHP' + 'bar']; +PHP + ]; + + yield 'It mutates correctly when provided with a constant' => [ + <<<'PHP' + 'bar'], $callback); +PHP + , + <<<'PHP' + [ + <<<'PHP' + 'bar'], ['baz' => 'bar'], $callback); +PHP + , + <<<'PHP' + 'bar']; +PHP + ]; + + yield 'It mutates correctly within if statements' => [ + <<<'PHP' + 'bar']; +if (array_uintersect_assoc($a, ['baz' => 'bar'], $callback) === $a) { + return true; +} +PHP + , + <<<'PHP' + 'bar']; +if ($a === $a) { + return true; +} +PHP + ]; + + yield 'It mutates correctly when array_uintersect_assoc is wrongly capitalized' => [ + <<<'PHP' + 'bar'], ['baz' => 'bar'], $callback); +PHP + , + <<<'PHP' + 'bar']; +PHP + ]; + + yield 'It mutates correctly when array_uintersect_assoc uses functions as input' => [ + <<<'PHP' +bar(), $foo->baz()); +PHP + , + <<<'PHP' +bar(); +PHP + ]; + + yield 'It mutates correctly when provided with a more complex situation' => [ + <<<'PHP' + 'bar'], ['baz' => 'bar'], $callback)); +PHP + , + <<<'PHP' + 'bar']); +PHP + ]; + + yield 'It mutates correctly when more than two parameters are present' => [ + <<<'PHP' + 'bar'], ['baz' => 'bar'], ['qux' => 'bar'], $callback); +PHP + , + <<<'PHP' + 'bar']; +PHP + ]; + + yield 'It does not mutate other array_ calls' => [ + <<<'PHP' + 'bar']); +PHP + ]; + + yield 'It does not mutate functions named array_uintersect_assoc' => [ + <<<'PHP' + [ + <<<'PHP' + 'bar'], ['baz' => 'bar'], $callback); +PHP + ]; + } +}