From 5e651f99f663154d7e929184065530e0bbab20ad Mon Sep 17 00:00:00 2001 From: Punyapal Shah Date: Fri, 30 Oct 2026 18:55:40 +0530 Subject: [PATCH 1/5] fix: set Composer root version in CI --- .github/workflows/static.yml | 3 +++ .github/workflows/tests.yml | 3 +++ 2 files changed, 6 insertions(+) diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml index 378f1a2..5678ef3 100644 --- a/.github/workflows/static.yml +++ b/.github/workflows/static.yml @@ -5,6 +5,9 @@ on: ['push', 'pull_request'] permissions: contents: read +env: + COMPOSER_ROOT_VERSION: 5.x-dev + jobs: static: name: Static Tests diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 10af2ce..c589673 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -5,6 +5,9 @@ on: ['push', 'pull_request'] permissions: contents: read +env: + COMPOSER_ROOT_VERSION: 5.x-dev + jobs: ci: runs-on: ${{ matrix.os }} From a97eb029780a50d8c701c78e87a2a08bc6105ea6 Mon Sep 17 00:00:00 2001 From: Punyapal Shah Date: Fri, 30 Oct 2026 19:10:12 +0530 Subject: [PATCH 2/5] fix: resolve remaining CI checks and exercise matrix options --- .github/workflows/static.yml | 2 +- .github/workflows/tests.yml | 2 +- phpunit.xml | 1 - .../Abstract/AbstractFunctionCallUnwrapMutator.php | 4 ++-- src/Mutators/Removal/RemoveEarlyReturn.php | 2 +- tests/Helpers.php | 2 +- tests/Mutators/String/UnwrapTrimTest.php | 13 +++++++++++++ 7 files changed, 19 insertions(+), 7 deletions(-) diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml index 5678ef3..29865a0 100644 --- a/.github/workflows/static.yml +++ b/.github/workflows/static.yml @@ -29,7 +29,7 @@ jobs: coverage: none - name: Install Dependencies - run: composer update --prefer-stable --no-interaction --no-progress --ansi + run: composer update --${{ matrix.dependency-version }} --no-interaction --no-progress --ansi - name: Types run: composer test:types diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index c589673..deda951 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -40,4 +40,4 @@ jobs: run: composer update --${{ matrix.dependency-version }} --no-interaction --no-progress --ansi - name: Unit Tests - run: composer test:unit + run: composer test:unit -- ${{ matrix.parallel }} diff --git a/phpunit.xml b/phpunit.xml index 7448eb7..146de9f 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -5,7 +5,6 @@ beStrictAboutTestsThatDoNotTestAnything="true" beStrictAboutOutputDuringTests="true" bootstrap="vendor/autoload.php" - cacheResult="false" colors="true" failOnRisky="true" failOnWarning="true" diff --git a/src/Mutators/Abstract/AbstractFunctionCallUnwrapMutator.php b/src/Mutators/Abstract/AbstractFunctionCallUnwrapMutator.php index 455e28a..5676448 100644 --- a/src/Mutators/Abstract/AbstractFunctionCallUnwrapMutator.php +++ b/src/Mutators/Abstract/AbstractFunctionCallUnwrapMutator.php @@ -5,12 +5,12 @@ namespace Pest\Mutate\Mutators\Abstract; use PhpParser\Node; +use PhpParser\Node\Arg; use PhpParser\Node\Expr\ArrowFunction; use PhpParser\Node\Expr\FuncCall; use PhpParser\Node\Expr\Variable; use PhpParser\Node\Name; use PhpParser\Node\Param; -use PhpParser\Node\VariadicPlaceholder; abstract class AbstractFunctionCallUnwrapMutator extends AbstractMutator { @@ -37,7 +37,7 @@ public static function mutate(Node $node): Node { assert($node instanceof FuncCall); - if ($node->args[0] instanceof VariadicPlaceholder) { + if (! $node->args[0] instanceof Arg) { return new ArrowFunction([ 'params' => [new Param(new Variable('value'))], 'expr' => new Variable('value'), diff --git a/src/Mutators/Removal/RemoveEarlyReturn.php b/src/Mutators/Removal/RemoveEarlyReturn.php index 024e199..2e09c57 100644 --- a/src/Mutators/Removal/RemoveEarlyReturn.php +++ b/src/Mutators/Removal/RemoveEarlyReturn.php @@ -44,7 +44,7 @@ public static function can(Node $node): bool if ($classMethod instanceof ClassMethod) { break; } - } while ($classMethod !== null); + } while ($classMethod instanceof Node); if (! $classMethod instanceof ClassMethod) { return false; diff --git a/tests/Helpers.php b/tests/Helpers.php index 612f4bb..71800e7 100644 --- a/tests/Helpers.php +++ b/tests/Helpers.php @@ -18,7 +18,7 @@ function mutationTestOutput(string $fixture): string $process = new Process( ['php', 'vendor/bin/pest', 'tests/.tests/'.$fixture, '--mutate'], dirname(__DIR__), - ['COLUMNS' => 80, 'XDEBUG_MODE' => 'coverage', 'PEST_PLUGIN_INTERNAL_TEST_SUITE' => 1], + ['COLUMNS' => 80, 'XDEBUG_MODE' => 'coverage', 'PEST_PLUGIN_INTERNAL_TEST_SUITE' => 1, 'PARATEST' => false], ); $process->run(); diff --git a/tests/Mutators/String/UnwrapTrimTest.php b/tests/Mutators/String/UnwrapTrimTest.php index ecb5385..7782de9 100644 --- a/tests/Mutators/String/UnwrapTrimTest.php +++ b/tests/Mutators/String/UnwrapTrimTest.php @@ -3,6 +3,7 @@ declare(strict_types=1); use Pest\Mutate\Mutators\String\UnwrapTrim; +use PhpParser\Node\ArgPlaceholder; it('unwraps the trim function', function (): void { expect(mutateCode(UnwrapTrim::class, <<<'CODE' @@ -27,3 +28,15 @@ array_map(fn($value) => $value, $array); CODE); }); + +it('replaces a trim argument placeholder with an empty callable', function (): void { + expect(mutateCode(UnwrapTrim::class, <<<'CODE' + toBe(<<<'CODE' + $value; + CODE); +})->skip(! class_exists(ArgPlaceholder::class), 'Argument placeholders require PHP-Parser 5.9.'); From 5b3aaad790d84544fd8a2d4912dbcda2e9cb6b15 Mon Sep 17 00:00:00 2001 From: Punyapal Shah Date: Fri, 30 Oct 2026 19:19:38 +0530 Subject: [PATCH 3/5] test: serialize snapshot subprocesses sharing coverage --- tests/Helpers.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/tests/Helpers.php b/tests/Helpers.php index 71800e7..588890d 100644 --- a/tests/Helpers.php +++ b/tests/Helpers.php @@ -21,7 +21,16 @@ function mutationTestOutput(string $fixture): string ['COLUMNS' => 80, 'XDEBUG_MODE' => 'coverage', 'PEST_PLUGIN_INTERNAL_TEST_SUITE' => 1, 'PARATEST' => false], ); - $process->run(); + // Snapshot subprocesses share Pest's coverage report path. + $lock = fopen(__DIR__.'/../.temp/mutation-snapshots.lock', 'c'); + flock($lock, LOCK_EX); + + try { + $process->run(); + } finally { + flock($lock, LOCK_UN); + fclose($lock); + } return (string) preg_replace([ '#\x1b[[][^A-Za-z]*[A-Za-z]#', // colors From 37d858cbfc23f95179fa484fa45d2eae8ca57fbc Mon Sep 17 00:00:00 2001 From: Punyapal Shah Date: Fri, 30 Oct 2026 19:24:31 +0530 Subject: [PATCH 4/5] test: keep mutation snapshots in one parallel worker --- ...snapshot_of_mutation_tests_on_success.snap | 0 ..._mutation_tests_when_a_mutant_escaped.snap | 0 ...ation_tests_with_describe_on_success.snap} | 0 tests/Helpers.php | 11 +---------- tests/Visual/MutationOutputTest.php | 19 +++++++++++++++++++ tests/Visual/Tested.php | 8 -------- tests/Visual/TestedWithDescribe.php | 8 -------- tests/Visual/Untested.php | 8 -------- 8 files changed, 20 insertions(+), 34 deletions(-) rename tests/.pest/snapshots/Visual/{Tested => MutationOutputTest}/visual_snapshot_of_mutation_tests_on_success.snap (100%) rename tests/.pest/snapshots/Visual/{Untested => MutationOutputTest}/visual_snapshot_of_mutation_tests_when_a_mutant_escaped.snap (100%) rename tests/.pest/snapshots/Visual/{TestedWithDescribe/visual_snapshot_of_mutation_tests_on_success.snap => MutationOutputTest/visual_snapshot_of_mutation_tests_with_describe_on_success.snap} (100%) create mode 100644 tests/Visual/MutationOutputTest.php delete mode 100644 tests/Visual/Tested.php delete mode 100644 tests/Visual/TestedWithDescribe.php delete mode 100644 tests/Visual/Untested.php diff --git a/tests/.pest/snapshots/Visual/Tested/visual_snapshot_of_mutation_tests_on_success.snap b/tests/.pest/snapshots/Visual/MutationOutputTest/visual_snapshot_of_mutation_tests_on_success.snap similarity index 100% rename from tests/.pest/snapshots/Visual/Tested/visual_snapshot_of_mutation_tests_on_success.snap rename to tests/.pest/snapshots/Visual/MutationOutputTest/visual_snapshot_of_mutation_tests_on_success.snap diff --git a/tests/.pest/snapshots/Visual/Untested/visual_snapshot_of_mutation_tests_when_a_mutant_escaped.snap b/tests/.pest/snapshots/Visual/MutationOutputTest/visual_snapshot_of_mutation_tests_when_a_mutant_escaped.snap similarity index 100% rename from tests/.pest/snapshots/Visual/Untested/visual_snapshot_of_mutation_tests_when_a_mutant_escaped.snap rename to tests/.pest/snapshots/Visual/MutationOutputTest/visual_snapshot_of_mutation_tests_when_a_mutant_escaped.snap diff --git a/tests/.pest/snapshots/Visual/TestedWithDescribe/visual_snapshot_of_mutation_tests_on_success.snap b/tests/.pest/snapshots/Visual/MutationOutputTest/visual_snapshot_of_mutation_tests_with_describe_on_success.snap similarity index 100% rename from tests/.pest/snapshots/Visual/TestedWithDescribe/visual_snapshot_of_mutation_tests_on_success.snap rename to tests/.pest/snapshots/Visual/MutationOutputTest/visual_snapshot_of_mutation_tests_with_describe_on_success.snap diff --git a/tests/Helpers.php b/tests/Helpers.php index 588890d..71800e7 100644 --- a/tests/Helpers.php +++ b/tests/Helpers.php @@ -21,16 +21,7 @@ function mutationTestOutput(string $fixture): string ['COLUMNS' => 80, 'XDEBUG_MODE' => 'coverage', 'PEST_PLUGIN_INTERNAL_TEST_SUITE' => 1, 'PARATEST' => false], ); - // Snapshot subprocesses share Pest's coverage report path. - $lock = fopen(__DIR__.'/../.temp/mutation-snapshots.lock', 'c'); - flock($lock, LOCK_EX); - - try { - $process->run(); - } finally { - flock($lock, LOCK_UN); - fclose($lock); - } + $process->run(); return (string) preg_replace([ '#\x1b[[][^A-Za-z]*[A-Za-z]#', // colors diff --git a/tests/Visual/MutationOutputTest.php b/tests/Visual/MutationOutputTest.php new file mode 100644 index 0000000..a45ab8b --- /dev/null +++ b/tests/Visual/MutationOutputTest.php @@ -0,0 +1,19 @@ +toMatchSnapshot(); +}); + +test('visual snapshot of mutation tests with describe on success', function (): void { + expect(mutationTestOutput('TestedWithDescribe')) + ->toMatchSnapshot(); +}); + +test('visual snapshot of mutation tests when a mutant escaped', function (): void { + expect(mutationTestOutput('Untested')) + ->toMatchSnapshot(); +}); diff --git a/tests/Visual/Tested.php b/tests/Visual/Tested.php deleted file mode 100644 index fa6df07..0000000 --- a/tests/Visual/Tested.php +++ /dev/null @@ -1,8 +0,0 @@ -toMatchSnapshot(); -}); diff --git a/tests/Visual/TestedWithDescribe.php b/tests/Visual/TestedWithDescribe.php deleted file mode 100644 index 59e0ea3..0000000 --- a/tests/Visual/TestedWithDescribe.php +++ /dev/null @@ -1,8 +0,0 @@ -toMatchSnapshot(); -}); diff --git a/tests/Visual/Untested.php b/tests/Visual/Untested.php deleted file mode 100644 index 53d1f32..0000000 --- a/tests/Visual/Untested.php +++ /dev/null @@ -1,8 +0,0 @@ -toMatchSnapshot(); -}); From 6ade939998ff53256bb9f53be74483de3f9e6ff0 Mon Sep 17 00:00:00 2001 From: Punyapal Shah Date: Fri, 30 Oct 2026 19:29:03 +0530 Subject: [PATCH 5/5] fix: use parser argument API without adding mutation behavior --- .../Abstract/AbstractFunctionCallUnwrapMutator.php | 6 +++--- tests/Mutators/String/UnwrapTrimTest.php | 13 ------------- 2 files changed, 3 insertions(+), 16 deletions(-) diff --git a/src/Mutators/Abstract/AbstractFunctionCallUnwrapMutator.php b/src/Mutators/Abstract/AbstractFunctionCallUnwrapMutator.php index 5676448..a12d922 100644 --- a/src/Mutators/Abstract/AbstractFunctionCallUnwrapMutator.php +++ b/src/Mutators/Abstract/AbstractFunctionCallUnwrapMutator.php @@ -5,12 +5,12 @@ namespace Pest\Mutate\Mutators\Abstract; use PhpParser\Node; -use PhpParser\Node\Arg; use PhpParser\Node\Expr\ArrowFunction; use PhpParser\Node\Expr\FuncCall; use PhpParser\Node\Expr\Variable; use PhpParser\Node\Name; use PhpParser\Node\Param; +use PhpParser\Node\VariadicPlaceholder; abstract class AbstractFunctionCallUnwrapMutator extends AbstractMutator { @@ -37,14 +37,14 @@ public static function mutate(Node $node): Node { assert($node instanceof FuncCall); - if (! $node->args[0] instanceof Arg) { + if ($node->args[0] instanceof VariadicPlaceholder) { return new ArrowFunction([ 'params' => [new Param(new Variable('value'))], 'expr' => new Variable('value'), ]); } - return $node->args[0]->value; + return $node->getArgs()[0]->value; } abstract public static function functionName(): string; diff --git a/tests/Mutators/String/UnwrapTrimTest.php b/tests/Mutators/String/UnwrapTrimTest.php index 7782de9..ecb5385 100644 --- a/tests/Mutators/String/UnwrapTrimTest.php +++ b/tests/Mutators/String/UnwrapTrimTest.php @@ -3,7 +3,6 @@ declare(strict_types=1); use Pest\Mutate\Mutators\String\UnwrapTrim; -use PhpParser\Node\ArgPlaceholder; it('unwraps the trim function', function (): void { expect(mutateCode(UnwrapTrim::class, <<<'CODE' @@ -28,15 +27,3 @@ array_map(fn($value) => $value, $array); CODE); }); - -it('replaces a trim argument placeholder with an empty callable', function (): void { - expect(mutateCode(UnwrapTrim::class, <<<'CODE' - toBe(<<<'CODE' - $value; - CODE); -})->skip(! class_exists(ArgPlaceholder::class), 'Argument placeholders require PHP-Parser 5.9.');