-
-
Notifications
You must be signed in to change notification settings - Fork 154
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enhancement: Implement UnwrapArrayReverse mutator #527
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
/** | ||
* Copyright Β© 2017-2018 Maks Rafalko | ||
* | ||
* License: https://opensource.org/licenses/BSD-3-Clause New BSD License | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Infection\Mutator\Unwrap; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class UnwrapArrayReverse extends AbstractUnwrapMutator | ||
{ | ||
protected function getFunctionName(): string | ||
{ | ||
return 'array_reverse'; | ||
} | ||
|
||
protected function getParameterIndex(): int | ||
{ | ||
return 0; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -161,8 +161,9 @@ final class MutatorProfile | |
]; | ||
|
||
public const UNWRAP = [ | ||
Mutator\Unwrap\UnwrapArrayMap::class, | ||
Mutator\Unwrap\UnwrapArrayFilter::class, | ||
Mutator\Unwrap\UnwrapArrayMap::class, | ||
Mutator\Unwrap\UnwrapArrayReverse::class, | ||
]; | ||
|
||
public const DEFAULT = [ | ||
|
@@ -286,7 +287,8 @@ final class MutatorProfile | |
'CastString' => Mutator\Cast\CastString::class, | ||
|
||
// Unwrap | ||
'UnwrapArrayMap' => Mutator\Unwrap\UnwrapArrayMap::class, | ||
'UnwrapArrayFilter' => Mutator\Unwrap\UnwrapArrayFilter::class, | ||
'UnwrapArrayMap' => Mutator\Unwrap\UnwrapArrayMap::class, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
'UnwrapArrayReverse' => Mutator\Unwrap\UnwrapArrayReverse::class, | ||
]; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,165 @@ | ||
<?php | ||
/** | ||
* Copyright Β© 2017-2018 Maks Rafalko | ||
* | ||
* License: https://opensource.org/licenses/BSD-3-Clause New BSD License | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Infection\Tests\Mutator\Unwrap; | ||
|
||
use Infection\Tests\Mutator\AbstractMutatorTestCase; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class UnwrapArrayReverseTest extends AbstractMutatorTestCase | ||
{ | ||
/** | ||
* @dataProvider provideMutationCases | ||
*/ | ||
public function test_mutator($input, $expected = null): void | ||
{ | ||
$this->doTest($input, $expected); | ||
} | ||
|
||
public function provideMutationCases(): \Generator | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should I add any cases that involve the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For the sake of completeness, sure why not. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure about the number of tests, do we need to have three instead of one data set
or will two more test cases suffice? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd leave it with just one test with an extra argument. It can be a variable like so:
|
||
{ | ||
yield 'It mutates correctly when provided with an array' => [ | ||
<<<'PHP' | ||
<?php | ||
|
||
$a = array_reverse(['A', 1, 'C']); | ||
PHP | ||
, | ||
<<<'PHP' | ||
<?php | ||
|
||
$a = ['A', 1, 'C']; | ||
PHP | ||
]; | ||
|
||
yield 'It mutates correctly when provided with a constant' => [ | ||
<<<'PHP' | ||
<?php | ||
|
||
$a = array_reverse(\Class_With_Const::Const); | ||
PHP | ||
, | ||
<<<'PHP' | ||
<?php | ||
|
||
$a = \Class_With_Const::Const; | ||
PHP | ||
]; | ||
|
||
yield 'It mutates correctly when a backslash is in front of array_reverse' => [ | ||
<<<'PHP' | ||
<?php | ||
|
||
$a = \array_reverse(['A', 1, 'C']); | ||
PHP | ||
, | ||
<<<'PHP' | ||
<?php | ||
|
||
$a = ['A', 1, 'C']; | ||
PHP | ||
]; | ||
|
||
yield 'It does not mutate other array_ calls' => [ | ||
<<<'PHP' | ||
<?php | ||
|
||
$a = array_map('strtolower', ['A', 'B', 'C']); | ||
PHP | ||
]; | ||
|
||
yield 'It does not mutate functions named array_reverse' => [ | ||
<<<'PHP' | ||
<?php | ||
|
||
function array_reverse($array) | ||
{ | ||
} | ||
PHP | ||
]; | ||
|
||
yield 'It mutates correctly within if statements' => [ | ||
<<<'PHP' | ||
<?php | ||
|
||
$a = ['A', 1, 'C']; | ||
if (array_reverse($a) === $a) { | ||
return true; | ||
} | ||
PHP | ||
, | ||
<<<'PHP' | ||
<?php | ||
|
||
$a = ['A', 1, 'C']; | ||
if ($a === $a) { | ||
return true; | ||
} | ||
PHP | ||
]; | ||
|
||
yield 'It mutates correctly when array_reverse is wrongly capitalized' => [ | ||
<<<'PHP' | ||
<?php | ||
|
||
$a = aRrAy_ReVeRsE(['A', 1, 'C']); | ||
PHP | ||
, | ||
<<<'PHP' | ||
<?php | ||
|
||
$a = ['A', 1, 'C']; | ||
PHP | ||
]; | ||
|
||
yield 'It mutates correctly when array_reverse uses another function as input' => [ | ||
<<<'PHP' | ||
<?php | ||
|
||
$a = array_reverse($foo->bar()); | ||
PHP | ||
, | ||
<<<'PHP' | ||
<?php | ||
|
||
$a = $foo->bar(); | ||
PHP | ||
]; | ||
|
||
yield 'It mutates correctly when provided with a more complex situation' => [ | ||
<<<'PHP' | ||
<?php | ||
|
||
$a = array_map('strtolower', array_reverse(['A', 1, 'C'])); | ||
PHP | ||
, | ||
<<<'PHP' | ||
<?php | ||
|
||
$a = array_map('strtolower', ['A', 1, 'C']); | ||
PHP | ||
]; | ||
|
||
yield 'It mutates correctly when the $preserve_keys parameter is present' => [ | ||
<<<'PHP' | ||
<?php | ||
|
||
$a = array_reverse(['A', 1, 'C'], $preserve_keys); | ||
PHP | ||
, | ||
<<<'PHP' | ||
<?php | ||
|
||
$a = ['A', 1, 'C']; | ||
PHP | ||
]; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See https://github.com/infection/infection/pull/513/files#r229116382.