diff --git a/src/Mutator/Unwrap/UnwrapArrayUdiff.php b/src/Mutator/Unwrap/UnwrapArrayUdiff.php new file mode 100644 index 000000000..3456a8ee6 --- /dev/null +++ b/src/Mutator/Unwrap/UnwrapArrayUdiff.php @@ -0,0 +1,54 @@ + Mutator\Unwrap\UnwrapArrayReverse::class, 'UnwrapArraySlice' => Mutator\Unwrap\UnwrapArraySlice::class, 'UnwrapArraySplice' => Mutator\Unwrap\UnwrapArraySplice::class, + 'UnwrapArrayUdiff' => Mutator\Unwrap\UnwrapArrayUdiff::class, 'UnwrapArrayUdiffAssoc' => Mutator\Unwrap\UnwrapArrayUdiffAssoc::class, 'UnwrapArrayUdiffUassoc' => Mutator\Unwrap\UnwrapArrayUdiffUassoc::class, 'UnwrapArrayUnique' => Mutator\Unwrap\UnwrapArrayUnique::class, diff --git a/tests/Mutator/Unwrap/UnwrapArrayUdiffTest.php b/tests/Mutator/Unwrap/UnwrapArrayUdiffTest.php new file mode 100644 index 000000000..baab5cce6 --- /dev/null +++ b/tests/Mutator/Unwrap/UnwrapArrayUdiffTest.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_udiff($a, ['baz' => 'bar'], $callback) === $a) { + return true; +} +PHP + , + <<<'PHP' + 'bar']; +if ($a === $a) { + return true; +} +PHP + ]; + + yield 'It mutates correctly when array_udiff is wrongly capitalized' => [ + <<<'PHP' + 'bar'], ['baz' => 'bar'], $callback); +PHP + , + <<<'PHP' + 'bar']; +PHP + ]; + + yield 'It mutates correctly when array_udiff 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_udiff' => [ + <<<'PHP' + [ + <<<'PHP' + 'bar'], ['baz' => 'bar'], $callback); +PHP + ]; + } +}