From be1e34dedea2beeb0fcea0193af41d4eb7732caf Mon Sep 17 00:00:00 2001 From: Oleg Zhulnev Date: Mon, 22 Feb 2021 18:05:39 +0300 Subject: [PATCH] Do not decrement min integer value --- src/Mutator/Number/DecrementInteger.php | 5 +++++ tests/phpunit/Mutator/Number/DecrementIntegerTest.php | 10 ++++++++++ 2 files changed, 15 insertions(+) diff --git a/src/Mutator/Number/DecrementInteger.php b/src/Mutator/Number/DecrementInteger.php index 16c521375..8a2ebdb95 100644 --- a/src/Mutator/Number/DecrementInteger.php +++ b/src/Mutator/Number/DecrementInteger.php @@ -40,6 +40,7 @@ use Infection\Mutator\GetMutatorName; use Infection\Mutator\MutatorCategory; use Infection\PhpParser\Visitor\ParentConnector; +use const PHP_INT_MIN; use PhpParser\Node; /** @@ -97,6 +98,10 @@ public function canMutate(Node $node): bool return false; } + if ($node->value === PHP_INT_MIN) { + return false; + } + if ( $node->value === 1 && ($this->isPartOfComparison($node) || ParentConnector::getParent($node) instanceof Node\Expr\Assign) diff --git a/tests/phpunit/Mutator/Number/DecrementIntegerTest.php b/tests/phpunit/Mutator/Number/DecrementIntegerTest.php index b4b00a079..2f3e1d9f0 100644 --- a/tests/phpunit/Mutator/Number/DecrementIntegerTest.php +++ b/tests/phpunit/Mutator/Number/DecrementIntegerTest.php @@ -504,6 +504,16 @@ public function mutationsProvider(): iterable [ + <<<'PHP' +