From 9d5d1601e291e2458969586766d5bf10809e9318 Mon Sep 17 00:00:00 2001 From: Nuno Maduro Date: Thu, 5 Sep 2024 18:13:05 +0100 Subject: [PATCH] Improves API --- composer.json | 4 +-- rector.php | 33 +++++++------------ src/Boostrappers/BootPhpUnitSubscribers.php | 4 +-- src/Boostrappers/BootSubscribers.php | 4 +-- src/Event/Events/Test/Outcome/Tested.php | 2 +- src/Support/MutationGenerator.php | 8 ++--- src/Tester/MutationTestRunner.php | 2 +- tests/Arch.php | 1 + .../Support/Printers/DefaultPrinterTest.php | 4 +-- 9 files changed, 26 insertions(+), 36 deletions(-) diff --git a/composer.json b/composer.json index 8638675..d1452b5 100644 --- a/composer.json +++ b/composer.json @@ -22,11 +22,11 @@ "require": { "php": "^8.2", "nikic/php-parser": "^5.1.0", - "pestphp/pest-plugin": "^v3.0.0", + "pestphp/pest-plugin": "^3.0.0", "psr/simple-cache": "^3.0.0" }, "require-dev": { - "pestphp/pest": "^v3.0.0", + "pestphp/pest": "^3.0.0", "pestphp/pest-dev-tools": "^3.0.0", "pestphp/pest-plugin-type-coverage": "^3.0.0" }, diff --git a/rector.php b/rector.php index 036ff1d..3189300 100644 --- a/rector.php +++ b/rector.php @@ -2,29 +2,18 @@ declare(strict_types=1); -use Rector\CodeQuality\Rector\Class_\InlineConstructorDefaultToPropertyRector; use Rector\Config\RectorConfig; -use Rector\Set\ValueObject\LevelSetList; -use Rector\Set\ValueObject\SetList; -return static function (RectorConfig $rectorConfig): void { - $rectorConfig->paths([ +return RectorConfig::configure() + ->withPaths([ __DIR__.'/src', __DIR__.'/tests', - ]); - - $rectorConfig->importNames(); - - $rectorConfig->rules([ - InlineConstructorDefaultToPropertyRector::class, - ]); - - $rectorConfig->sets([ - LevelSetList::UP_TO_PHP_81, - SetList::CODE_QUALITY, - SetList::DEAD_CODE, - SetList::EARLY_RETURN, - SetList::TYPE_DECLARATION, - ]); - -}; + ]) + ->withPreparedSets( + deadCode: true, + codeQuality: true, + typeDeclarations: true, + privatization: true, + earlyReturn: true, + ) + ->withPhpSets(); diff --git a/src/Boostrappers/BootPhpUnitSubscribers.php b/src/Boostrappers/BootPhpUnitSubscribers.php index 5f6e449..bac6353 100644 --- a/src/Boostrappers/BootPhpUnitSubscribers.php +++ b/src/Boostrappers/BootPhpUnitSubscribers.php @@ -17,7 +17,7 @@ /** * @internal */ -final class BootPhpUnitSubscribers implements Bootstrapper +final readonly class BootPhpUnitSubscribers implements Bootstrapper { /** * The list of Subscribers. @@ -35,7 +35,7 @@ final class BootPhpUnitSubscribers implements Bootstrapper * Creates a new instance of the Boot Subscribers. */ public function __construct( - private readonly Container $container, + private Container $container, ) {} /** diff --git a/src/Boostrappers/BootSubscribers.php b/src/Boostrappers/BootSubscribers.php index 9bcd1eb..e3d0abf 100644 --- a/src/Boostrappers/BootSubscribers.php +++ b/src/Boostrappers/BootSubscribers.php @@ -16,7 +16,7 @@ /** * @internal */ -final class BootSubscribers implements Bootstrapper +final readonly class BootSubscribers implements Bootstrapper { /** * The list of Subscribers. @@ -34,7 +34,7 @@ final class BootSubscribers implements Bootstrapper * Creates a new instance of the Boot Subscribers. */ public function __construct( - private readonly Container $container, + private Container $container, ) {} /** diff --git a/src/Event/Events/Test/Outcome/Tested.php b/src/Event/Events/Test/Outcome/Tested.php index bfbf0c1..eedb5dd 100644 --- a/src/Event/Events/Test/Outcome/Tested.php +++ b/src/Event/Events/Test/Outcome/Tested.php @@ -10,6 +10,6 @@ class Tested implements Event { public function __construct( - public readonly MutationTest $test, + public MutationTest $test, ) {} } diff --git a/src/Support/MutationGenerator.php b/src/Support/MutationGenerator.php index 6b81d04..8a6f205 100644 --- a/src/Support/MutationGenerator.php +++ b/src/Support/MutationGenerator.php @@ -20,9 +20,9 @@ class MutationGenerator private int $offset; - private Node $originalNode; + private Node $originalNode; // @phpstan-ignore-line - private ?Node $modifiedNode = null; + private ?Node $modifiedNode = null; // @phpstan-ignore-line /** * @param array> $mutators @@ -87,11 +87,11 @@ public function generate( $modifiedAst = $traverser->traverse($stmts); - if (! $this->hasMutated()) { + if (! $this->mutated) { // @phpstan-ignore-line break; } - $newMutations[] = Mutation::create( + $newMutations[] = Mutation::create( // @phpstan-ignore-line file: $file, mutator: $mutator, originalNode: $this->originalNode, diff --git a/src/Tester/MutationTestRunner.php b/src/Tester/MutationTestRunner.php index 97bb197..6d6e332 100644 --- a/src/Tester/MutationTestRunner.php +++ b/src/Tester/MutationTestRunner.php @@ -226,7 +226,7 @@ private function runTestsInParallel(MutationSuite $mutationSuite, array $covered continue; } - usleep(1000); + usleep(1000); // @pest-arch-ignore-line } $processId = (int) array_key_first(array_filter($this->runningTests, fn (?MutationTest $process): bool => ! $process instanceof MutationTest)); diff --git a/tests/Arch.php b/tests/Arch.php index 83a8b48..8009eac 100644 --- a/tests/Arch.php +++ b/tests/Arch.php @@ -1,6 +1,7 @@ printer->compact(); - $this->printer->reportEscapedMutation($this->mutationTest); + $this->printer->reportUntestedMutation($this->mutationTest); expect($this->out->fetch()) ->toBe('x'); }); it('reports a escaped mutation in normal mode', function (): void { - $this->printer->reportEscapedMutation($this->mutationTest); + $this->printer->reportUntestedMutation($this->mutationTest); expect($this->out->fetch()) ->toContain('тип', 'Line 4:', 'EqualToIdentical')