-
-
Notifications
You must be signed in to change notification settings - Fork 154
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enhancement: Implement UnwrapArrayFlip mutator
- Loading branch information
1 parent
6b80024
commit 90bdf62
Showing
3 changed files
with
181 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 UnwrapArrayFlip extends AbstractUnwrapMutator | ||
{ | ||
protected function getFunctionName(): string | ||
{ | ||
return 'array_flip'; | ||
} | ||
|
||
protected function getParameterIndex(): int | ||
{ | ||
return 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
<?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 UnwrapArrayFlipTest extends AbstractMutatorTestCase | ||
{ | ||
/** | ||
* @dataProvider provideMutationCases | ||
*/ | ||
public function test_mutator($input, $expected = null): void | ||
{ | ||
$this->doTest($input, $expected); | ||
} | ||
|
||
public function provideMutationCases(): \Generator | ||
{ | ||
yield 'It mutates correctly when provided with an array' => [ | ||
<<<'PHP' | ||
<?php | ||
$a = array_flip(['A', 1, 'C']); | ||
PHP | ||
, | ||
<<<'PHP' | ||
<?php | ||
$a = ['A', 1, 'C']; | ||
PHP | ||
]; | ||
|
||
yield 'It mutates correctly when provided with a constant' => [ | ||
<<<'PHP' | ||
<?php | ||
$a = array_flip(\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_flip' => [ | ||
<<<'PHP' | ||
<?php | ||
$a = \array_flip(['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_flip' => [ | ||
<<<'PHP' | ||
<?php | ||
function array_flip($text) | ||
{ | ||
} | ||
PHP | ||
]; | ||
|
||
yield 'It mutates correctly within if statements' => [ | ||
<<<'PHP' | ||
<?php | ||
$a = ['A', 1, 'C']; | ||
if (array_flip($a) === $a) { | ||
return true; | ||
} | ||
PHP | ||
, | ||
<<<'PHP' | ||
<?php | ||
$a = ['A', 1, 'C']; | ||
if ($a === $a) { | ||
return true; | ||
} | ||
PHP | ||
]; | ||
|
||
yield 'It mutates correctly when array_flip is wrongly capitalized' => [ | ||
<<<'PHP' | ||
<?php | ||
$a = aRrAy_FlIp(['A', 1, 'C']); | ||
PHP | ||
, | ||
<<<'PHP' | ||
<?php | ||
$a = ['A', 1, 'C']; | ||
PHP | ||
]; | ||
|
||
yield 'It mutates correctly when array_flip uses another function as input' => [ | ||
<<<'PHP' | ||
<?php | ||
$a = array_flip($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_flip(['A', 1, 'C']); | ||
PHP | ||
, | ||
<<<'PHP' | ||
<?php | ||
$a = array_map('strtolower', ['A', 1, 'C']); | ||
PHP | ||
]; | ||
} | ||
} |