Skip to content

Commit

Permalink
Do not increment max integer value (fixes #1484) (#1486)
Browse files Browse the repository at this point in the history
  • Loading branch information
DeepDiver1975 authored and maks-rafalko committed Feb 22, 2021
1 parent dfacb1e commit 3248417
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Mutator/Number/IncrementInteger.php
Expand Up @@ -39,6 +39,7 @@
use Infection\Mutator\GetMutatorName;
use Infection\Mutator\MutatorCategory;
use Infection\PhpParser\Visitor\ParentConnector;
use const PHP_INT_MAX;
use PhpParser\Node;

/**
Expand Down Expand Up @@ -87,6 +88,10 @@ public function canMutate(Node $node): bool
return false;
}

if ($node->value === PHP_INT_MAX) {
return false;
}

if (
$node->value === 0
&& ($this->isPartOfComparison($node) || ParentConnector::getParent($node) instanceof Node\Expr\Assign)
Expand Down
14 changes: 14 additions & 0 deletions tests/phpunit/Mutator/Number/IncrementIntegerTest.php
Expand Up @@ -239,6 +239,20 @@ public function mutationsProvider(): iterable
<?php
preg_split('//', 'string', -1);
PHP
];

yield 'It does not increment max int' => [
<<<'PHP'
<?php
random_int(10000000, 9223372036854775807);
PHP
,
<<<'PHP'
<?php
random_int(10000001, 9223372036854775807);
PHP
];
}
Expand Down

0 comments on commit 3248417

Please sign in to comment.