Skip to content

Commit

Permalink
infection#597 some tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
majkel89 committed Mar 6, 2019
1 parent 8c7fa3b commit 2681bd2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
14 changes: 8 additions & 6 deletions src/Mutator/Removal/ArrayItemRemoval.php
Expand Up @@ -66,15 +66,17 @@ public function __construct(MutatorConfig $config)
$this->limit = $settings['limit'];
}

/**
* @param Node|Node\Expr\Array_ $arrayNode
* @return Node|Node[]|\Generator
*/
public function mutate(Node $arrayNode): Generator
{
if ($arrayNode instanceof Node\Expr\Array_) {
foreach ($this->getItemsIndexes($arrayNode->items) as $indexToRemove) {
$newArrayNode = clone $arrayNode;
unset($newArrayNode->items[$indexToRemove]);
foreach ($this->getItemsIndexes($arrayNode->items) as $indexToRemove) {
$newArrayNode = clone $arrayNode;
unset($newArrayNode->items[$indexToRemove]);

yield $newArrayNode;
}
yield $newArrayNode;
}
}

Expand Down
7 changes: 5 additions & 2 deletions tests/Mutator/Removal/ArrayItemRemovalTest.php
Expand Up @@ -56,7 +56,6 @@ public function provideMutationCases(): Generator
{
yield 'It does not mutate empty arrays' => [
'<?php $a = [];',
null,
];

yield 'It removes only first item by default' => [
Expand Down Expand Up @@ -113,7 +112,11 @@ public function provideMutationCases(): Generator
public function test_settings_validation(string $setting, $value, string $valueInError): void
{
$this->expectException(InvalidConfigException::class);
$this->expectExceptionMessage("Invalid configuration of ArrayItemRemoval mutator. Setting `$setting` is invalid ($valueInError)");
$this->expectExceptionMessage(sprintf(
'Invalid configuration of ArrayItemRemoval mutator. Setting `%s` is invalid (%s)',
$setting,
$valueInError
));
$this->doTest(
'<?php $a = [1, 2, 3];',
"<?php\n\n\$a = [2, 3];",
Expand Down

0 comments on commit 2681bd2

Please sign in to comment.