Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Prev Previous commit
Next Next commit
Add nsrt tests for mutation testing coverage
- Add GMP + string test to catch TrinaryLogicMutator on isNumericString
- Add unary operator tests on object type to catch mutations in GmpUnaryOperatorTypeSpecifyingExtension

Co-Authored-By: Claude Opus 4.5 <[email protected]>
  • Loading branch information
Firehed and claude committed Mar 26, 2026
commit 7b42b42af65e8cfea3140e733f28f0fecd452395
31 changes: 31 additions & 0 deletions tests/PHPStan/Analyser/nsrt/gmp-operators.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,15 @@ function gmpWithNumericString(\GMP $a, string $s): void
// GMP functions accept numeric strings
assertType('GMP', gmp_add($a, '123'));
assertType('GMP', gmp_mul($a, '456'));

// General string (not numeric-string) has isNumericString()=Maybe
// This catches TrinaryLogicMutator on line 53: isNumericString()->yes() → !isNumericString()->no()
// Without mutation: Maybe.yes()=false → ErrorType
// With mutation: !Maybe.no()=true → GMP (incorrect!)
/** @phpstan-ignore binaryOp.invalid */
assertType('*ERROR*', $a + $s);
/** @phpstan-ignore binaryOp.invalid */
assertType('*ERROR*', $s + $a);
}

/**
Expand All @@ -204,3 +213,25 @@ function nonGmpObjectsDoNotGetGmpTreatment($obj, int $i): void
/** @phpstan-ignore binaryOp.invalid */
assertType('*ERROR*', $i + $obj);
}

/**
* Tests for unary operators on non-GMP objects.
* This catches IsSuperTypeOfCalleeAndArgumentMutator and TrinaryLogicMutator
* on GmpUnaryOperatorTypeSpecifyingExtension line 27.
*
* When mutation swaps $gmpType->isSuperTypeOf($operand) to $operand->isSuperTypeOf($gmpType),
* `object` would incorrectly activate the extension and return GMP.
*
* @param object $obj
*/
function unaryOperatorsOnObjectShouldError($obj): void
{
// Without mutation: extension doesn't activate (GMP not supertype of object)
// With mutation: extension activates (object IS supertype of GMP), returns GMP!
/** @phpstan-ignore unaryOp.invalid */
assertType('*ERROR*', -$obj);
/** @phpstan-ignore unaryOp.invalid */
assertType('*ERROR*', +$obj);
/** @phpstan-ignore unaryOp.invalid */
assertType('*ERROR*', ~$obj);
}
Loading