From c5fca90c9de89921f48bc091df5f5d70a26ba6d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20FIDRY?= Date: Tue, 24 Mar 2020 18:55:38 +0100 Subject: [PATCH 01/21] Remove Mutant::isCoveredByTests() and rename Mutation::isCoveredByTests() to hasTests() --- src/Metrics/MetricsCalculator.php | 6 +++--- src/Mutant/Mutant.php | 5 ----- src/Mutant/MutantExecutionResultFactory.php | 2 +- src/Mutation/Mutation.php | 9 ++++----- src/Process/Runner/MutationTestingRunner.php | 7 +++++-- tests/phpunit/Mutant/MutantAssertions.php | 2 -- tests/phpunit/Mutant/MutantFactoryTest.php | 1 - tests/phpunit/Mutant/MutantTest.php | 4 ---- tests/phpunit/Mutation/MutationTest.php | 4 ++-- 9 files changed, 15 insertions(+), 25 deletions(-) diff --git a/src/Metrics/MetricsCalculator.php b/src/Metrics/MetricsCalculator.php index b6e626ab2..5e2427895 100644 --- a/src/Metrics/MetricsCalculator.php +++ b/src/Metrics/MetricsCalculator.php @@ -68,7 +68,7 @@ class MetricsCalculator /** * @var int */ - private $notCoveredByTestsCount = 0; + private $notExecutedByTestsCount = 0; /** * @var int @@ -110,7 +110,7 @@ public function collect(MutantExecutionResult ...$executionResults): void break; case DetectionStatus::NOT_COVERED: - $this->notCoveredByTestsCount++; + $this->notExecutedByTestsCount++; $this->notCoveredExecutionResults->add($executionResult); break; @@ -164,7 +164,7 @@ public function getTimedOutCount(): int public function getNotTestedCount(): int { - return $this->notCoveredByTestsCount; + return $this->notExecutedByTestsCount; } public function getTotalMutantsCount(): int diff --git a/src/Mutant/Mutant.php b/src/Mutant/Mutant.php index ca0562fb5..9474b421a 100644 --- a/src/Mutant/Mutant.php +++ b/src/Mutant/Mutant.php @@ -81,11 +81,6 @@ public function getDiff(): string return $this->diff; } - public function isCoveredByTest(): bool - { - return $this->mutation->isCoveredByTest(); - } - /** * @return TestLocation[] */ diff --git a/src/Mutant/MutantExecutionResultFactory.php b/src/Mutant/MutantExecutionResultFactory.php index 53a9dd7d5..6bc8ef904 100644 --- a/src/Mutant/MutantExecutionResultFactory.php +++ b/src/Mutant/MutantExecutionResultFactory.php @@ -86,7 +86,7 @@ private function retrieveProcessOutput(Process $process): string private function retrieveDetectionStatus(MutantProcess $mutantProcess): string { - if (!$mutantProcess->getMutant()->isCoveredByTest()) { + if (!$mutantProcess->getMutant()->getMutation()->hasTests()) { return DetectionStatus::NOT_COVERED; } diff --git a/src/Mutation/Mutation.php b/src/Mutation/Mutation.php index eecace91c..7fa15b5bf 100644 --- a/src/Mutation/Mutation.php +++ b/src/Mutation/Mutation.php @@ -70,7 +70,7 @@ class Mutation private $attributes; private $originalFileAst; private $tests; - private $coveredByTests; + private $executedByTests; /** * @var string|null @@ -106,7 +106,7 @@ public function __construct( $this->mutatedNode = $mutatedNode; $this->mutationByMutatorIndex = $mutationByMutatorIndex; $this->tests = $tests; - $this->coveredByTests = count($tests) > 0; + $this->executedByTests = count($tests) > 0; } public function getOriginalFilePath(): string @@ -150,10 +150,9 @@ public function getMutatedNode(): MutatedNode return $this->mutatedNode; } - // TODO: hasTest()? - public function isCoveredByTest(): bool + public function hasTests(): bool { - return $this->coveredByTests; + return $this->executedByTests; } /** diff --git a/src/Process/Runner/MutationTestingRunner.php b/src/Process/Runner/MutationTestingRunner.php index f22bd0351..2853c26bf 100644 --- a/src/Process/Runner/MutationTestingRunner.php +++ b/src/Process/Runner/MutationTestingRunner.php @@ -89,8 +89,11 @@ public function run(iterable $mutations, string $testFrameworkExtraOptions): voi return $this->mutantFactory->create($mutation); }) ->filter(function (Mutant $mutant) { - // It's a proxy call to Mutation, can be done one stage up - if ($mutant->isCoveredByTest()) { + // The filtering is done here since with a mutant and not earlier with a mutation + // since: + // - if pass the filtering, the mutant is going to be used + // - if does not pass the filtering, the mutant is used for the reports + if ($mutant->getMutation()->hasTests()) { return true; } diff --git a/tests/phpunit/Mutant/MutantAssertions.php b/tests/phpunit/Mutant/MutantAssertions.php index e850267be..daa590b04 100644 --- a/tests/phpunit/Mutant/MutantAssertions.php +++ b/tests/phpunit/Mutant/MutantAssertions.php @@ -50,14 +50,12 @@ public function assertMutantStateIs( Mutation $expectedMutation, string $expectedMutatedCode, string $expectedDiff, - bool $expectedCoveredByTests, array $expectedTests ): void { $this->assertSame($expectedFilePath, $mutant->getFilePath()); $this->assertSame($expectedMutation, $mutant->getMutation()); $this->assertSame($expectedMutatedCode, $mutant->getMutatedCode()); $this->assertSame($expectedDiff, $mutant->getDiff()); - $this->assertSame($expectedCoveredByTests, $mutant->isCoveredByTest()); $this->assertSame($expectedTests, $mutant->getTests()); } } diff --git a/tests/phpunit/Mutant/MutantFactoryTest.php b/tests/phpunit/Mutant/MutantFactoryTest.php index cd6a11757..ea2b8eb49 100644 --- a/tests/phpunit/Mutant/MutantFactoryTest.php +++ b/tests/phpunit/Mutant/MutantFactoryTest.php @@ -141,7 +141,6 @@ public function test_it_creates_a_mutant_instance_from_the_given_mutation(): voi $mutation, 'mutated code', 'code diff', - true, $tests ); } diff --git a/tests/phpunit/Mutant/MutantTest.php b/tests/phpunit/Mutant/MutantTest.php index a857b9bc0..9da58b04e 100644 --- a/tests/phpunit/Mutant/MutantTest.php +++ b/tests/phpunit/Mutant/MutantTest.php @@ -58,7 +58,6 @@ public function test_it_can_be_instantiated( Mutation $mutation, string $mutatedCode, string $diff, - bool $expectedCoveredByTests, array $expectedTests ): void { $mutant = new Mutant($filePath, $mutation, $mutatedCode, $diff); @@ -69,7 +68,6 @@ public function test_it_can_be_instantiated( $mutation, $mutatedCode, $diff, - $expectedCoveredByTests, $expectedTests ); } @@ -110,7 +108,6 @@ public function valuesProvider(): iterable ), 'mutated code', 'diff value', - true, $tests, ]; @@ -131,7 +128,6 @@ public function valuesProvider(): iterable ), 'mutated code', 'diff value', - false, [], ]; } diff --git a/tests/phpunit/Mutation/MutationTest.php b/tests/phpunit/Mutation/MutationTest.php index 4cb66f5e3..1a43567de 100644 --- a/tests/phpunit/Mutation/MutationTest.php +++ b/tests/phpunit/Mutation/MutationTest.php @@ -66,7 +66,7 @@ public function test_it_can_be_instantiated( array $tests, array $expectedAttributes, int $expectedOriginalStartingLine, - bool $expectedCoveredByTests, + bool $expectedHasTests, string $expectedHash ): void { $mutation = new Mutation( @@ -88,7 +88,7 @@ public function test_it_can_be_instantiated( $this->assertSame($mutatedNodeClass, $mutation->getMutatedNodeClass()); $this->assertSame($mutatedNode, $mutation->getMutatedNode()); $this->assertSame($tests, $mutation->getAllTests()); - $this->assertSame($expectedCoveredByTests, $mutation->isCoveredByTest()); + $this->assertSame($expectedHasTests, $mutation->hasTests()); $this->assertSame($expectedHash, $mutation->getHash()); } From 29801685a92f474187bed98f3918e162b47532af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20FIDRY?= Date: Tue, 24 Mar 2020 19:15:58 +0100 Subject: [PATCH 02/21] Remove redundant method --- src/Mutant/Mutant.php | 2 +- src/Mutation/Mutation.php | 2 +- src/Process/Builder/MutantProcessBuilder.php | 8 +++++--- tests/phpunit/Mutant/MutantAssertions.php | 8 +------- tests/phpunit/Mutant/MutantFactoryTest.php | 11 ++--------- tests/phpunit/Mutant/MutantTest.php | 10 ++-------- tests/phpunit/Mutation/MutationTest.php | 2 +- 7 files changed, 13 insertions(+), 30 deletions(-) diff --git a/src/Mutant/Mutant.php b/src/Mutant/Mutant.php index 9474b421a..119b32077 100644 --- a/src/Mutant/Mutant.php +++ b/src/Mutant/Mutant.php @@ -86,6 +86,6 @@ public function getDiff(): string */ public function getTests(): array { - return $this->mutation->getAllTests(); + return $this->mutation->getTests(); } } diff --git a/src/Mutation/Mutation.php b/src/Mutation/Mutation.php index 7fa15b5bf..77dbece92 100644 --- a/src/Mutation/Mutation.php +++ b/src/Mutation/Mutation.php @@ -158,7 +158,7 @@ public function hasTests(): bool /** * @return TestLocation[] */ - public function getAllTests(): array + public function getTests(): array { return $this->tests; } diff --git a/src/Process/Builder/MutantProcessBuilder.php b/src/Process/Builder/MutantProcessBuilder.php index f898719ba..72263fd91 100644 --- a/src/Process/Builder/MutantProcessBuilder.php +++ b/src/Process/Builder/MutantProcessBuilder.php @@ -70,12 +70,14 @@ public function __construct( public function createProcessForMutant(Mutant $mutant, string $testFrameworkExtraOptions = ''): MutantProcess { + $mutation = $mutant->getMutation(); + $process = new Process( $this->testFrameworkAdapter->getMutantCommandLine( - $mutant->getTests(), + $mutation->getTests(), $mutant->getFilePath(), - $mutant->getMutation()->getHash(), - $mutant->getMutation()->getOriginalFilePath(), + $mutation->getHash(), + $mutation->getOriginalFilePath(), $testFrameworkExtraOptions ) ); diff --git a/tests/phpunit/Mutant/MutantAssertions.php b/tests/phpunit/Mutant/MutantAssertions.php index daa590b04..be80d7eaa 100644 --- a/tests/phpunit/Mutant/MutantAssertions.php +++ b/tests/phpunit/Mutant/MutantAssertions.php @@ -35,27 +35,21 @@ namespace Infection\Tests\Mutant; -use Infection\AbstractTestFramework\Coverage\TestLocation; use Infection\Mutant\Mutant; use Infection\Mutation\Mutation; trait MutantAssertions { - /** - * @param TestLocation[] $expectedTests - */ public function assertMutantStateIs( Mutant $mutant, string $expectedFilePath, Mutation $expectedMutation, string $expectedMutatedCode, - string $expectedDiff, - array $expectedTests + string $expectedDiff ): void { $this->assertSame($expectedFilePath, $mutant->getFilePath()); $this->assertSame($expectedMutation, $mutant->getMutation()); $this->assertSame($expectedMutatedCode, $mutant->getMutatedCode()); $this->assertSame($expectedDiff, $mutant->getDiff()); - $this->assertSame($expectedTests, $mutant->getTests()); } } diff --git a/tests/phpunit/Mutant/MutantFactoryTest.php b/tests/phpunit/Mutant/MutantFactoryTest.php index ea2b8eb49..6288b0b2f 100644 --- a/tests/phpunit/Mutant/MutantFactoryTest.php +++ b/tests/phpunit/Mutant/MutantFactoryTest.php @@ -98,13 +98,7 @@ public function test_it_creates_a_mutant_instance_from_the_given_mutation(): voi new Node\Name('Acme'), [new Node\Scalar\LNumber(0)] )], - $tests = [ - new TestLocation( - 'FooTest::test_it_can_instantiate', - '/path/to/acme/FooTest.php', - 0.01 - ), - ] + [] ); $expectedMutantFilePath = sprintf( @@ -140,8 +134,7 @@ public function test_it_creates_a_mutant_instance_from_the_given_mutation(): voi $expectedMutantFilePath, $mutation, 'mutated code', - 'code diff', - $tests + 'code diff' ); } diff --git a/tests/phpunit/Mutant/MutantTest.php b/tests/phpunit/Mutant/MutantTest.php index 9da58b04e..0d6ecd163 100644 --- a/tests/phpunit/Mutant/MutantTest.php +++ b/tests/phpunit/Mutant/MutantTest.php @@ -50,15 +50,12 @@ final class MutantTest extends TestCase /** * @dataProvider valuesProvider - * - * @param TestLocation[] $expectedTests */ public function test_it_can_be_instantiated( string $filePath, Mutation $mutation, string $mutatedCode, - string $diff, - array $expectedTests + string $diff ): void { $mutant = new Mutant($filePath, $mutation, $mutatedCode, $diff); @@ -67,8 +64,7 @@ public function test_it_can_be_instantiated( $filePath, $mutation, $mutatedCode, - $diff, - $expectedTests + $diff ); } @@ -108,7 +104,6 @@ public function valuesProvider(): iterable ), 'mutated code', 'diff value', - $tests, ]; yield 'nominal without tests' => [ @@ -128,7 +123,6 @@ public function valuesProvider(): iterable ), 'mutated code', 'diff value', - [], ]; } } diff --git a/tests/phpunit/Mutation/MutationTest.php b/tests/phpunit/Mutation/MutationTest.php index 1a43567de..8bf0cd3c6 100644 --- a/tests/phpunit/Mutation/MutationTest.php +++ b/tests/phpunit/Mutation/MutationTest.php @@ -87,7 +87,7 @@ public function test_it_can_be_instantiated( $this->assertSame($expectedOriginalStartingLine, $mutation->getOriginalStartingLine()); $this->assertSame($mutatedNodeClass, $mutation->getMutatedNodeClass()); $this->assertSame($mutatedNode, $mutation->getMutatedNode()); - $this->assertSame($tests, $mutation->getAllTests()); + $this->assertSame($tests, $mutation->getTests()); $this->assertSame($expectedHasTests, $mutation->hasTests()); $this->assertSame($expectedHash, $mutation->getHash()); } From 5d3835b2326b55939b3df71559a1ec0ffd40d112 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20FIDRY?= Date: Tue, 24 Mar 2020 23:39:30 +0100 Subject: [PATCH 03/21] PoC: move mutant into mutation --- src/Container.php | 12 +- src/Mutant/MutantExecutionResult.php | 9 +- src/Mutant/MutantExecutionResultFactory.php | 7 +- .../MutantCodeFactory.php | 22 ++- src/Mutation/Mutation.php | 76 +++-------- .../MutationCalculatedState.php} | 48 +++++-- .../MutationFactory.php} | 125 ++++++++++++++++-- src/PhpParser/Visitor/MutatorVisitor.php | 26 +++- src/Process/Builder/MutantProcessBuilder.php | 10 +- src/Process/MutantProcess.php | 12 +- src/Process/Runner/MutationTestingRunner.php | 19 +-- .../phpunit/Mutant/MutantCodeFactoryTest.php | 3 +- tests/phpunit/Mutant/MutantFactoryTest.php | 8 +- tests/phpunit/Mutation/MutationTest.php | 3 - .../Builder/MutantProcessBuilderTest.php | 2 +- tests/phpunit/Process/MutantProcessTest.php | 2 +- .../Runner/MutationTestingRunnerTest.php | 6 +- 17 files changed, 242 insertions(+), 148 deletions(-) rename src/{Mutant => Mutation}/MutantCodeFactory.php (79%) rename src/{Mutant/Exception/MsiCalculationException.php => Mutation/MutationCalculatedState.php} (66%) rename src/{Mutant/MutantFactory.php => Mutation/MutationFactory.php} (50%) diff --git a/src/Container.php b/src/Container.php index 8ecc2f69f..17a6498c5 100644 --- a/src/Container.php +++ b/src/Container.php @@ -62,11 +62,11 @@ use Infection\Logger\LoggerFactory; use Infection\Metrics\MetricsCalculator; use Infection\Metrics\MinMsiChecker; -use Infection\Mutant\MutantCodeFactory; use Infection\Mutant\MutantExecutionResultFactory; -use Infection\Mutant\MutantFactory; use Infection\Mutation\FileMutationGenerator; +use Infection\Mutation\MutantCodeFactory; use Infection\Mutation\Mutation; +use Infection\Mutation\MutationFactory; use Infection\Mutation\MutationGenerator; use Infection\Mutator\MutatorFactory; use Infection\Mutator\MutatorParser; @@ -225,8 +225,8 @@ public static function create(): self MutantCodeFactory::class => static function (self $container): MutantCodeFactory { return new MutantCodeFactory($container->getPrinter()); }, - MutantFactory::class => static function (self $container): MutantFactory { - return new MutantFactory( + MutationFactory::class => static function (self $container): MutationFactory { + return new MutationFactory( $container->getConfiguration()->getTmpDir(), $container->getDiffer(), $container->getPrinter(), @@ -648,9 +648,9 @@ public function getMutantCodeFactory(): MutantCodeFactory return $this->get(MutantCodeFactory::class); } - public function getMutantFactory(): MutantFactory + public function getMutantFactory(): MutationFactory { - return $this->get(MutantFactory::class); + return $this->get(MutationFactory::class); } public function getDiffer(): Differ diff --git a/src/Mutant/MutantExecutionResult.php b/src/Mutant/MutantExecutionResult.php index 8f36841aa..0fc3f6e12 100644 --- a/src/Mutant/MutantExecutionResult.php +++ b/src/Mutant/MutantExecutionResult.php @@ -36,6 +36,7 @@ namespace Infection\Mutant; use function array_keys; +use Infection\Mutation\Mutation; use Infection\Mutator\ProfileList; use Webmozart\Assert\Assert; @@ -74,16 +75,14 @@ public function __construct( $this->originalStartingLine = $originalStartingLine; } - public static function createFromNonCoveredMutant(Mutant $mutant): self + public static function createFromNonCoveredMutant(Mutation $mutation): self { - $mutation = $mutant->getMutation(); - return new self( '', '', DetectionStatus::NOT_COVERED, - $mutant->getDiff(), - $mutant->getMutation()->getMutatorName(), + $mutation->getDiff(), + $mutation->getMutatorName(), $mutation->getOriginalFilePath(), $mutation->getOriginalStartingLine() ); diff --git a/src/Mutant/MutantExecutionResultFactory.php b/src/Mutant/MutantExecutionResultFactory.php index 6bc8ef904..10b388491 100644 --- a/src/Mutant/MutantExecutionResultFactory.php +++ b/src/Mutant/MutantExecutionResultFactory.php @@ -57,14 +57,13 @@ public function __construct(TestFrameworkAdapter $testFrameworkAdapter) public function createFromProcess(MutantProcess $mutantProcess): MutantExecutionResult { $process = $mutantProcess->getProcess(); - $mutant = $mutantProcess->getMutant(); - $mutation = $mutant->getMutation(); + $mutation = $mutantProcess->getMutation(); return new MutantExecutionResult( $process->getCommandLine(), $this->retrieveProcessOutput($process), $this->retrieveDetectionStatus($mutantProcess), - $mutant->getDiff(), + $mutation->getDiff(), $mutation->getMutatorName(), $mutation->getOriginalFilePath(), $mutation->getOriginalStartingLine() @@ -86,7 +85,7 @@ private function retrieveProcessOutput(Process $process): string private function retrieveDetectionStatus(MutantProcess $mutantProcess): string { - if (!$mutantProcess->getMutant()->getMutation()->hasTests()) { + if (!$mutantProcess->getMutation()->getMutation()->hasTests()) { return DetectionStatus::NOT_COVERED; } diff --git a/src/Mutant/MutantCodeFactory.php b/src/Mutation/MutantCodeFactory.php similarity index 79% rename from src/Mutant/MutantCodeFactory.php rename to src/Mutation/MutantCodeFactory.php index ac0035b66..ceeb281b9 100644 --- a/src/Mutant/MutantCodeFactory.php +++ b/src/Mutation/MutantCodeFactory.php @@ -33,11 +33,12 @@ declare(strict_types=1); -namespace Infection\Mutant; +namespace Infection\Mutation; -use Infection\Mutation\Mutation; +use Infection\PhpParser\MutatedNode; use Infection\PhpParser\Visitor\CloneVisitor; use Infection\PhpParser\Visitor\MutatorVisitor; +use PhpParser\Node; use PhpParser\NodeTraverser; use PhpParser\PrettyPrinterAbstract; @@ -54,14 +55,23 @@ public function __construct(PrettyPrinterAbstract $prettyPrinter) $this->printer = $prettyPrinter; } - public function createCode(Mutation $mutation): string - { + /** + * @param array $attributes + * @param Node[] $originalFileAst + * @param class-string $mutatedNodeClass + */ + public function createCode( + array $attributes, + array $originalFileAst, + string $mutatedNodeClass, + MutatedNode $mutatedNode + ): string { $traverser = new NodeTraverser(); $traverser->addVisitor(new CloneVisitor()); - $traverser->addVisitor(new MutatorVisitor($mutation)); + $traverser->addVisitor(new MutatorVisitor($attributes, $mutatedNodeClass, $mutatedNode)); - $mutatedStatements = $traverser->traverse($mutation->getOriginalFileAst()); + $mutatedStatements = $traverser->traverse($originalFileAst); return $this->printer->prettyPrintFile($mutatedStatements); } diff --git a/src/Mutation/Mutation.php b/src/Mutation/Mutation.php index 77dbece92..d79e4e358 100644 --- a/src/Mutation/Mutation.php +++ b/src/Mutation/Mutation.php @@ -37,13 +37,10 @@ use function array_intersect_key; use function array_keys; +use Closure; use function count; -use function implode; use Infection\AbstractTestFramework\Coverage\TestLocation; use Infection\Mutator\ProfileList; -use Infection\PhpParser\MutatedNode; -use function md5; -use PhpParser\Node; use function Safe\array_flip; use Webmozart\Assert\Assert; @@ -64,33 +61,26 @@ class Mutation private $originalFilePath; private $mutatorName; - private $mutatedNodeClass; - private $mutatedNode; - private $mutationByMutatorIndex; private $attributes; - private $originalFileAst; private $tests; private $executedByTests; + private $calculateState; /** - * @var string|null + * @var MutationCalculatedState|null */ - private $hash; + private $calculatedState; /** - * @param Node[] $originalFileAst - * @param array $attributes * @param TestLocation[] $tests + * @param Closure(): MutationCalculatedState $calculateState */ public function __construct( string $originalFilePath, - array $originalFileAst, string $mutatorName, array $attributes, - string $mutatedNodeClass, - MutatedNode $mutatedNode, - int $mutationByMutatorIndex, - array $tests + array $tests, + Closure $calculateState ) { Assert::oneOf($mutatorName, array_keys(ProfileList::ALL_MUTATORS)); @@ -99,27 +89,21 @@ public function __construct( } $this->originalFilePath = $originalFilePath; - $this->originalFileAst = $originalFileAst; $this->mutatorName = $mutatorName; $this->attributes = array_intersect_key($attributes, array_flip(self::ATTRIBUTE_KEYS)); - $this->mutatedNodeClass = $mutatedNodeClass; - $this->mutatedNode = $mutatedNode; - $this->mutationByMutatorIndex = $mutationByMutatorIndex; $this->tests = $tests; $this->executedByTests = count($tests) > 0; + $this->calculateState = $calculateState; } - public function getOriginalFilePath(): string + public function getFilePath(): string { - return $this->originalFilePath; + return $this->getCalculatedState()->getMutationFilePath(); } - /** - * @return Node[] - */ - public function getOriginalFileAst(): array + public function getOriginalFilePath(): string { - return $this->originalFileAst; + return $this->originalFilePath; } public function getMutatorName(): string @@ -127,32 +111,24 @@ public function getMutatorName(): string return $this->mutatorName; } - /** - * @return (string|int|float)[] - */ - public function getAttributes(): array - { - return $this->attributes; - } - public function getOriginalStartingLine(): int { return (int) $this->attributes['startLine']; } - public function getMutatedNodeClass(): string + public function hasTests(): bool { - return $this->mutatedNodeClass; + return $this->executedByTests; } - public function getMutatedNode(): MutatedNode + public function getMutatedCode(): string { - return $this->mutatedNode; + return $this->getCalculatedState()->getMutatedCode(); } - public function hasTests(): bool + public function getDiff(): string { - return $this->executedByTests; + return $this->getCalculatedState()->getDiff(); } /** @@ -165,21 +141,11 @@ public function getTests(): array public function getHash(): string { - return $this->hash ?? $this->hash = $this->createHash(); + return $this->getCalculatedState()->getMutationHash(); } - private function createHash(): string + private function getCalculatedState(): MutationCalculatedState { - $hashKeys = [ - $this->originalFilePath, - $this->mutatorName, - $this->mutationByMutatorIndex, - ]; - - foreach ($this->attributes as $attribute) { - $hashKeys[] = $attribute; - } - - return md5(implode('_', $hashKeys)); + return $this->calculatedState ?? $this->calculatedState = ($this->calculateState)(); } } diff --git a/src/Mutant/Exception/MsiCalculationException.php b/src/Mutation/MutationCalculatedState.php similarity index 66% rename from src/Mutant/Exception/MsiCalculationException.php rename to src/Mutation/MutationCalculatedState.php index ad479d61b..8679371e5 100644 --- a/src/Mutant/Exception/MsiCalculationException.php +++ b/src/Mutation/MutationCalculatedState.php @@ -33,20 +33,44 @@ declare(strict_types=1); -namespace Infection\Mutant\Exception; +namespace Infection\Mutation; -use LogicException; -use function Safe\sprintf; - -/** - * @internal - */ -final class MsiCalculationException extends LogicException +final class MutationCalculatedState { - public static function create(string $type): self + private $mutantFilePath; + private $mutatedCode; + private $diff; + private $mutationHash; + + public function __construct( + string $mutationHash, + string $mutantFilePath, + string $mutatedCode, + string $diff + ) { + $this->mutationHash = $mutationHash; + $this->mutantFilePath = $mutantFilePath; + $this->mutatedCode = $mutatedCode; + $this->diff = $diff; + } + + public function getMutationHash(): string + { + return $this->mutationHash; + } + + public function getMutationFilePath(): string + { + return $this->mutantFilePath; + } + + public function getMutatedCode(): string + { + return $this->mutatedCode; + } + + public function getDiff(): string { - return new self(sprintf( - 'Seems like something is wrong with calculations and %s options.', $type - )); + return $this->diff; } } diff --git a/src/Mutant/MutantFactory.php b/src/Mutation/MutationFactory.php similarity index 50% rename from src/Mutant/MutantFactory.php rename to src/Mutation/MutationFactory.php index 4614467ff..5df071db9 100644 --- a/src/Mutant/MutantFactory.php +++ b/src/Mutation/MutationFactory.php @@ -33,10 +33,13 @@ declare(strict_types=1); -namespace Infection\Mutant; +namespace Infection\Mutation; +use function implode; +use Infection\AbstractTestFramework\Coverage\TestLocation; use Infection\Differ\Differ; -use Infection\Mutation\Mutation; +use Infection\PhpParser\MutatedNode; +use function md5; use PhpParser\Node; use PhpParser\PrettyPrinterAbstract; use function Safe\sprintf; @@ -45,7 +48,7 @@ * @internal * @final */ -class MutantFactory +class MutationFactory { private $tmpDir; private $differ; @@ -69,29 +72,123 @@ public function __construct( $this->mutantCodeFactory = $mutantCodeFactory; } - public function create(Mutation $mutation): Mutant - { + /** + * @param Node[] $originalFileAst + * @param array $attributes + * @param TestLocation[] $tests + */ + public function create( + string $originalFilePath, + array $originalFileAst, + string $mutatorName, + array $attributes, + string $mutatedNodeClass, + MutatedNode $mutatedNode, + int $mutationByMutatorIndex, + array $tests + ): Mutation { + return new Mutation( + $originalFilePath, + $mutatorName, + $attributes, + $tests, + function () use ( + $originalFilePath, + $originalFileAst, + $mutatorName, + $attributes, + $mutatedNodeClass, + $mutatedNode, + $mutationByMutatorIndex + ): MutationCalculatedState { + return $this->calculateState( + $originalFilePath, + $originalFileAst, + $mutatorName, + $attributes, + $mutatedNodeClass, + $mutatedNode, + $mutationByMutatorIndex + ); + } + ); + } + + /** + * @param Node[] $originalFileAst + * @param array $attributes + */ + private function calculateState( + string $originalFilePath, + array $originalFileAst, + string $mutatorName, + array $attributes, + string $mutatedNodeClass, + MutatedNode $mutatedNode, + int $mutationByMutatorIndex + ): MutationCalculatedState { + $hash = self::createHash( + $originalFilePath, + $mutatorName, + $attributes, + $mutationByMutatorIndex + ); + $mutantFilePath = sprintf( '%s/mutant.%s.infection.php', $this->tmpDir, - $mutation->getHash() + $hash ); - $mutatedCode = $this->mutantCodeFactory->createCode($mutation); + $mutatedCode = $this->mutantCodeFactory->createCode( + $attributes, + $originalFileAst, + $mutatedNodeClass, + $mutatedNode + ); - return new Mutant( + return new MutationCalculatedState( + $hash, $mutantFilePath, - $mutation, $mutatedCode, - $this->createMutantDiff($mutation, $mutatedCode) + $this->createMutantDiff( + $originalFilePath, + $originalFileAst, + $mutatedCode + ) ); } - private function createMutantDiff(Mutation $mutation, string $mutantCode): string - { + private static function createHash( + string $originalFilePath, + string $mutatorName, + array $attributes, + int $mutationByMutatorIndex + ): string { + $hashKeys = [ + $originalFilePath, + $mutatorName, + $mutationByMutatorIndex, + ]; + + foreach ($attributes as $attribute) { + $hashKeys[] = $attribute; + } + + return md5(implode('_', $hashKeys)); + } + + /** + * @param Node[] $originalFileAst + */ + private function createMutantDiff( + string $originalFilePath, + array $originalFileAst, + string $mutantCode + ): string { $originalPrettyPrintedFile = $this->getOriginalPrettyPrintedFile( - $mutation->getOriginalFilePath(), - $mutation->getOriginalFileAst() + $originalFilePath, + $originalFileAst ); return $this->differ->diff($originalPrettyPrintedFile, $mutantCode); diff --git a/src/PhpParser/Visitor/MutatorVisitor.php b/src/PhpParser/Visitor/MutatorVisitor.php index 411225d4d..01732054f 100644 --- a/src/PhpParser/Visitor/MutatorVisitor.php +++ b/src/PhpParser/Visitor/MutatorVisitor.php @@ -38,6 +38,7 @@ use function array_key_exists; use function get_class; use Infection\Mutation\Mutation; +use Infection\PhpParser\MutatedNode; use PhpParser\Node; use PhpParser\NodeVisitorAbstract; @@ -46,11 +47,22 @@ */ final class MutatorVisitor extends NodeVisitorAbstract { - private $mutation; + private $attributes; + private $mutatedNodeClass; + private $mutatedNode; - public function __construct(Mutation $mutation) - { - $this->mutation = $mutation; + /** + * @param array $attributes + * @param class-string $mutatedNodeClass + */ + public function __construct( + array $attributes, + string $mutatedNodeClass, + MutatedNode $mutatedNode + ) { + $this->attributes = $attributes; + $this->mutatedNodeClass = $mutatedNodeClass; + $this->mutatedNode = $mutatedNode; } public function leaveNode(Node $node) @@ -61,13 +73,13 @@ public function leaveNode(Node $node) return null; } - $mutatedAttributes = $this->mutation->getAttributes(); + $mutatedAttributes = $this->attributes; $samePosition = $attributes['startTokenPos'] === $mutatedAttributes['startTokenPos'] && $attributes['endTokenPos'] === $mutatedAttributes['endTokenPos']; - if ($samePosition && $this->mutation->getMutatedNodeClass() === get_class($node)) { - return $this->mutation->getMutatedNode()->unwrap(); + if ($samePosition && $this->mutatedNodeClass === get_class($node)) { + return $this->mutatedNode->unwrap(); // TODO STOP TRAVERSING // TODO check all built-in visitors, in particular FirstFindingVisitor // TODO beforeTraverse - FirstFindingVisitor diff --git a/src/Process/Builder/MutantProcessBuilder.php b/src/Process/Builder/MutantProcessBuilder.php index 72263fd91..d5aecb6e2 100644 --- a/src/Process/Builder/MutantProcessBuilder.php +++ b/src/Process/Builder/MutantProcessBuilder.php @@ -38,8 +38,8 @@ use Infection\AbstractTestFramework\TestFrameworkAdapter; use Infection\Event\EventDispatcher\EventDispatcher; use Infection\Event\MutantProcessWasFinished; -use Infection\Mutant\Mutant; use Infection\Mutant\MutantExecutionResultFactory; +use Infection\Mutation\Mutation; use Infection\Process\MutantProcess; use function method_exists; use Symfony\Component\Process\Process; @@ -68,14 +68,12 @@ public function __construct( $this->resultFactory = $resultFactory; } - public function createProcessForMutant(Mutant $mutant, string $testFrameworkExtraOptions = ''): MutantProcess + public function createProcessForMutant(Mutation $mutation, string $testFrameworkExtraOptions = ''): MutantProcess { - $mutation = $mutant->getMutation(); - $process = new Process( $this->testFrameworkAdapter->getMutantCommandLine( $mutation->getTests(), - $mutant->getFilePath(), + $mutation->getFilePath(), $mutation->getHash(), $mutation->getOriginalFilePath(), $testFrameworkExtraOptions @@ -89,7 +87,7 @@ public function createProcessForMutant(Mutant $mutant, string $testFrameworkExtr $process->inheritEnvironmentVariables(); } - $mutantProcess = new MutantProcess($process, $mutant); + $mutantProcess = new MutantProcess($process, $mutation); $eventDispatcher = $this->eventDispatcher; $resultFactory = $this->resultFactory; diff --git a/src/Process/MutantProcess.php b/src/Process/MutantProcess.php index d6bbde333..a01b2f994 100644 --- a/src/Process/MutantProcess.php +++ b/src/Process/MutantProcess.php @@ -36,7 +36,7 @@ namespace Infection\Process; use Closure; -use Infection\Mutant\Mutant; +use Infection\Mutation\Mutation; use Infection\Process\Runner\ProcessBearer; use Symfony\Component\Process\Process; @@ -47,7 +47,7 @@ class MutantProcess implements ProcessBearer { private $process; - private $mutant; + private $mutation; private $callback; /** @@ -55,10 +55,10 @@ class MutantProcess implements ProcessBearer */ private $timedOut = false; - public function __construct(Process $process, Mutant $mutant) + public function __construct(Process $process, Mutation $mutation) { $this->process = $process; - $this->mutant = $mutant; + $this->mutation = $mutation; $this->callback = static function (): void {}; } @@ -67,9 +67,9 @@ public function getProcess(): Process return $this->process; } - public function getMutant(): Mutant + public function getMutation(): Mutation { - return $this->mutant; + return $this->mutation; } public function markAsTimedOut(): void diff --git a/src/Process/Runner/MutationTestingRunner.php b/src/Process/Runner/MutationTestingRunner.php index 2853c26bf..0d80971cb 100644 --- a/src/Process/Runner/MutationTestingRunner.php +++ b/src/Process/Runner/MutationTestingRunner.php @@ -42,7 +42,6 @@ use Infection\IterableCounter; use Infection\Mutant\Mutant; use Infection\Mutant\MutantExecutionResult; -use Infection\Mutant\MutantFactory; use Infection\Mutation\Mutation; use Infection\Process\Builder\MutantProcessBuilder; use function Pipeline\take; @@ -54,7 +53,6 @@ final class MutationTestingRunner { private $processBuilder; - private $mutantFactory; private $processRunner; private $eventDispatcher; private $fileSystem; @@ -62,14 +60,12 @@ final class MutationTestingRunner public function __construct( MutantProcessBuilder $mutantProcessBuilder, - MutantFactory $mutantFactory, ProcessRunner $processRunner, EventDispatcher $eventDispatcher, Filesystem $fileSystem, bool $runConcurrently ) { $this->processBuilder = $mutantProcessBuilder; - $this->mutantFactory = $mutantFactory; $this->processRunner = $processRunner; $this->eventDispatcher = $eventDispatcher; $this->fileSystem = $fileSystem; @@ -85,28 +81,25 @@ public function run(iterable $mutations, string $testFrameworkExtraOptions): voi $this->eventDispatcher->dispatch(new MutationTestingWasStarted($numberOfMutants)); $processes = take($mutations) - ->map(function (Mutation $mutation): Mutant { - return $this->mutantFactory->create($mutation); - }) - ->filter(function (Mutant $mutant) { + ->filter(function (Mutation $mutation) { // The filtering is done here since with a mutant and not earlier with a mutation // since: // - if pass the filtering, the mutant is going to be used // - if does not pass the filtering, the mutant is used for the reports - if ($mutant->getMutation()->hasTests()) { + if ($mutation->hasTests()) { return true; } $this->eventDispatcher->dispatch(new MutantProcessWasFinished( - MutantExecutionResult::createFromNonCoveredMutant($mutant) + MutantExecutionResult::createFromNonCoveredMutant($mutation) )); return false; }) - ->map(function (Mutant $mutant) use ($testFrameworkExtraOptions): ProcessBearer { - $this->fileSystem->dumpFile($mutant->getFilePath(), $mutant->getMutatedCode()); + ->map(function (Mutation $mutation) use ($testFrameworkExtraOptions): ProcessBearer { + $this->fileSystem->dumpFile($mutation->getFilePath(), $mutation->getMutatedCode()); - $process = $this->processBuilder->createProcessForMutant($mutant, $testFrameworkExtraOptions); + $process = $this->processBuilder->createProcessForMutant($mutation, $testFrameworkExtraOptions); return $process; }) diff --git a/tests/phpunit/Mutant/MutantCodeFactoryTest.php b/tests/phpunit/Mutant/MutantCodeFactoryTest.php index 450443df3..197bf0942 100644 --- a/tests/phpunit/Mutant/MutantCodeFactoryTest.php +++ b/tests/phpunit/Mutant/MutantCodeFactoryTest.php @@ -35,7 +35,6 @@ namespace Infection\Tests\Mutant; -use Infection\Mutant\MutantCodeFactory; use Infection\Mutation\Mutation; use Infection\Mutator\Arithmetic\Plus; use Infection\PhpParser\MutatedNode; @@ -47,7 +46,7 @@ final class MutantCodeFactoryTest extends TestCase { /** - * @var MutantCodeFactory + * @var \Infection\Mutation\MutantCodeFactory */ private $codeFactory; diff --git a/tests/phpunit/Mutant/MutantFactoryTest.php b/tests/phpunit/Mutant/MutantFactoryTest.php index 6288b0b2f..d957e7c96 100644 --- a/tests/phpunit/Mutant/MutantFactoryTest.php +++ b/tests/phpunit/Mutant/MutantFactoryTest.php @@ -37,9 +37,9 @@ use Infection\AbstractTestFramework\Coverage\TestLocation; use Infection\Differ\Differ; -use Infection\Mutant\MutantCodeFactory; -use Infection\Mutant\MutantFactory; +use Infection\Mutation\MutantCodeFactory; use Infection\Mutation\Mutation; +use Infection\Mutation\MutationFactory; use Infection\Mutator\Arithmetic\Plus; use Infection\PhpParser\MutatedNode; use Infection\Tests\Mutator\MutatorName; @@ -69,7 +69,7 @@ final class MutantFactoryTest extends TestCase private $differMock; /** - * @var MutantFactory + * @var \Infection\Mutation\MutationFactory */ private $mutantFactory; @@ -83,7 +83,7 @@ protected function setUp(): void $this->differMock = $this->createMock(Differ::class); - $this->mutantFactory = new MutantFactory( + $this->mutantFactory = new MutationFactory( '/path/to/tmp', $this->differMock, $this->printerMock, diff --git a/tests/phpunit/Mutation/MutationTest.php b/tests/phpunit/Mutation/MutationTest.php index 8bf0cd3c6..1b4f77b52 100644 --- a/tests/phpunit/Mutation/MutationTest.php +++ b/tests/phpunit/Mutation/MutationTest.php @@ -83,10 +83,7 @@ public function test_it_can_be_instantiated( $this->assertSame($originalFilePath, $mutation->getOriginalFilePath()); $this->assertSame($originalFileAst, $mutation->getOriginalFileAst()); $this->assertSame($mutatorName, $mutation->getMutatorName()); - $this->assertSame($expectedAttributes, $mutation->getAttributes()); $this->assertSame($expectedOriginalStartingLine, $mutation->getOriginalStartingLine()); - $this->assertSame($mutatedNodeClass, $mutation->getMutatedNodeClass()); - $this->assertSame($mutatedNode, $mutation->getMutatedNode()); $this->assertSame($tests, $mutation->getTests()); $this->assertSame($expectedHasTests, $mutation->hasTests()); $this->assertSame($expectedHash, $mutation->getHash()); diff --git a/tests/phpunit/Process/Builder/MutantProcessBuilderTest.php b/tests/phpunit/Process/Builder/MutantProcessBuilderTest.php index 095cc3ac2..1dd958077 100644 --- a/tests/phpunit/Process/Builder/MutantProcessBuilderTest.php +++ b/tests/phpunit/Process/Builder/MutantProcessBuilderTest.php @@ -143,7 +143,7 @@ public function test_it_creates_a_process_with_timeout(): void $this->assertSame(100., $process->getTimeout()); $this->assertFalse($process->isStarted()); - $this->assertSame($mutant, $mutantProcess->getMutant()); + $this->assertSame($mutant, $mutantProcess->getMutation()); $this->assertFalse($mutantProcess->isTimedOut()); $this->assertSame([], $eventDispatcher->getEvents()); diff --git a/tests/phpunit/Process/MutantProcessTest.php b/tests/phpunit/Process/MutantProcessTest.php index 454138ac8..3533df9cd 100644 --- a/tests/phpunit/Process/MutantProcessTest.php +++ b/tests/phpunit/Process/MutantProcessTest.php @@ -112,7 +112,7 @@ private function assertMutantProcessStateIs( bool $expectedTimedOut ): void { $this->assertSame($expectedProcess, $mutantProcess->getProcess()); - $this->assertSame($expectedMutant, $mutantProcess->getMutant()); + $this->assertSame($expectedMutant, $mutantProcess->getMutation()); $this->assertSame($expectedTimedOut, $mutantProcess->isTimedOut()); } } diff --git a/tests/phpunit/Process/Runner/MutationTestingRunnerTest.php b/tests/phpunit/Process/Runner/MutationTestingRunnerTest.php index 0704a0567..1a74dc057 100644 --- a/tests/phpunit/Process/Runner/MutationTestingRunnerTest.php +++ b/tests/phpunit/Process/Runner/MutationTestingRunnerTest.php @@ -44,8 +44,8 @@ use Infection\Event\MutationTestingWasFinished; use Infection\Event\MutationTestingWasStarted; use Infection\Mutant\Mutant; -use Infection\Mutant\MutantFactory; use Infection\Mutation\Mutation; +use Infection\Mutation\MutationFactory; use Infection\Mutator\ZeroIteration\For_; use Infection\PhpParser\MutatedNode; use Infection\Process\Builder\MutantProcessBuilder; @@ -73,7 +73,7 @@ final class MutationTestingRunnerTest extends TestCase private $processBuilderMock; /** - * @var MutantFactory|MockObject + * @var \Infection\Mutation\MutationFactory|MockObject */ private $mutantFactoryMock; @@ -100,7 +100,7 @@ final class MutationTestingRunnerTest extends TestCase protected function setUp(): void { $this->processBuilderMock = $this->createMock(MutantProcessBuilder::class); - $this->mutantFactoryMock = $this->createMock(MutantFactory::class); + $this->mutantFactoryMock = $this->createMock(MutationFactory::class); $this->processRunnerMock = $this->createMock(ProcessRunner::class); $this->eventDispatcher = new EventDispatcherCollector(); $this->fileSystemMock = $this->createMock(Filesystem::class); From ed884548c8121abda4cd521d957589e9d407a6dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20FIDRY?= Date: Wed, 25 Mar 2020 00:54:50 +0100 Subject: [PATCH 04/21] Fix most of the direct tests --- src/Container.php | 4 +- src/Mutant/MutantExecutionResultFactory.php | 2 +- src/Mutation/Mutation.php | 1 + .../phpunit/Mutant/MutantCodeFactoryTest.php | 152 +++++---- .../MutantExecutionResultFactoryTest.php | 305 +++++++++--------- .../Mutant/MutantExecutionResultTest.php | 60 ++-- tests/phpunit/Mutant/MutantFactoryTest.php | 145 +++++---- .../phpunit/Mutation/MutationAssertions.php | 78 ++--- .../Mutation/MutationCalculatedStateTest.php | 36 +++ tests/phpunit/Mutation/MutationTest.php | 158 ++++----- .../PhpParser/Visitor/MutatorVisitorTest.php | 126 +++----- .../Builder/MutantProcessBuilderTest.php | 60 ++-- tests/phpunit/Process/MutantProcessTest.php | 15 +- 13 files changed, 574 insertions(+), 568 deletions(-) rename src/Mutant/Mutant.php => tests/phpunit/Mutation/MutationAssertions.php (57%) create mode 100644 tests/phpunit/Mutation/MutationCalculatedStateTest.php diff --git a/src/Container.php b/src/Container.php index 17a6498c5..d4b5599d2 100644 --- a/src/Container.php +++ b/src/Container.php @@ -450,7 +450,7 @@ public static function create(): self MutationTestingRunner::class => static function (self $container): MutationTestingRunner { return new MutationTestingRunner( $container->getMutantProcessBuilder(), - $container->getMutantFactory(), + $container->getMutationFactory(), $container->getProcessRunner(), $container->getEventDispatcher(), $container->getConfiguration()->isDryRun() @@ -648,7 +648,7 @@ public function getMutantCodeFactory(): MutantCodeFactory return $this->get(MutantCodeFactory::class); } - public function getMutantFactory(): MutationFactory + public function getMutationFactory(): MutationFactory { return $this->get(MutationFactory::class); } diff --git a/src/Mutant/MutantExecutionResultFactory.php b/src/Mutant/MutantExecutionResultFactory.php index 10b388491..4149a5520 100644 --- a/src/Mutant/MutantExecutionResultFactory.php +++ b/src/Mutant/MutantExecutionResultFactory.php @@ -85,7 +85,7 @@ private function retrieveProcessOutput(Process $process): string private function retrieveDetectionStatus(MutantProcess $mutantProcess): string { - if (!$mutantProcess->getMutation()->getMutation()->hasTests()) { + if (!$mutantProcess->getMutation()->hasTests()) { return DetectionStatus::NOT_COVERED; } diff --git a/src/Mutation/Mutation.php b/src/Mutation/Mutation.php index d79e4e358..2492161ff 100644 --- a/src/Mutation/Mutation.php +++ b/src/Mutation/Mutation.php @@ -90,6 +90,7 @@ public function __construct( $this->originalFilePath = $originalFilePath; $this->mutatorName = $mutatorName; + // TODO: move this up $this->attributes = array_intersect_key($attributes, array_flip(self::ATTRIBUTE_KEYS)); $this->tests = $tests; $this->executedByTests = count($tests) > 0; diff --git a/tests/phpunit/Mutant/MutantCodeFactoryTest.php b/tests/phpunit/Mutant/MutantCodeFactoryTest.php index 197bf0942..47a66c510 100644 --- a/tests/phpunit/Mutant/MutantCodeFactoryTest.php +++ b/tests/phpunit/Mutant/MutantCodeFactoryTest.php @@ -57,27 +57,51 @@ protected function setUp(): void /** * @dataProvider mutationProvider + * + * @param array $attributes + * @param Node[] $originalFileAst + * @param class-string $mutatedNodeClass */ public function test_it_creates_the_mutant_code_from_the_given_mutation( - Mutation $mutation, + array $attributes, + array $originalFileAst, + string $mutatedNodeClass, + MutatedNode $mutatedNode, string $expectedMutantCode ): void { - $mutantCode = $this->codeFactory->createCode($mutation); + $mutationCode = $this->codeFactory->createCode( + $attributes, + $originalFileAst, + $mutatedNodeClass, + $mutatedNode + ); - $this->assertSame($expectedMutantCode, $mutantCode); + $this->assertSame($expectedMutantCode, $mutationCode); } /** * @dataProvider mutationProvider + * + * @param array $attributes + * @param Node[] $originalFileAst + * @param class-string $mutatedNodeClass */ public function test_it_creates_the_mutant_code_without_altering_the_original_nodes( - Mutation $mutation + array $attributes, + array $originalFileAst, + string $mutatedNodeClass, + MutatedNode $mutatedNode ): void { - $originalNodesDump = SingletonContainer::getNodeDumper()->dump($mutation->getOriginalFileAst()); + $originalNodesDump = SingletonContainer::getNodeDumper()->dump($originalFileAst); - $this->codeFactory->createCode($mutation); + $this->codeFactory->createCode( + $attributes, + $originalFileAst, + $mutatedNodeClass, + $mutatedNode + ); - $originalNodesDumpAfterMutation = SingletonContainer::getNodeDumper()->dump($mutation->getOriginalFileAst()); + $originalNodesDumpAfterMutation = SingletonContainer::getNodeDumper()->dump($originalFileAst); $this->assertSame($originalNodesDump, $originalNodesDumpAfterMutation); } @@ -85,79 +109,73 @@ public function test_it_creates_the_mutant_code_without_altering_the_original_no public function mutationProvider(): iterable { yield [ - new Mutation( - '/path/to/acme/Foo.php', - [new Node\Stmt\Namespace_( - new Node\Name( - 'Acme', - [ - 'startLine' => 3, - 'startTokenPos' => 4, - 'startFilePos' => 17, - 'endLine' => 3, - 'endTokenPos' => 4, - 'endFilePos' => 20, - ] - ), - [new Node\Stmt\Echo_( - [new Node\Scalar\LNumber( - 10, - [ - 'startLine' => 5, - 'startTokenPos' => 9, - 'startFilePos' => 29, - 'endLine' => 5, - 'endTokenPos' => 9, - 'endFilePos' => 30, - 'kind' => 10, - ] - )], + [ + 'startLine' => 5, + 'startTokenPos' => 9, + 'startFilePos' => 29, + 'endLine' => 5, + 'endTokenPos' => 9, + 'endFilePos' => 30, + 'kind' => 10, + ], + [new Node\Stmt\Namespace_( + new Node\Name( + 'Acme', + [ + 'startLine' => 3, + 'startTokenPos' => 4, + 'startFilePos' => 17, + 'endLine' => 3, + 'endTokenPos' => 4, + 'endFilePos' => 20, + ] + ), + [new Node\Stmt\Echo_( + [new Node\Scalar\LNumber( + 10, [ 'startLine' => 5, - 'startTokenPos' => 7, - 'startFilePos' => 24, + 'startTokenPos' => 9, + 'startFilePos' => 29, 'endLine' => 5, - 'endTokenPos' => 10, - 'endFilePos' => 31, + 'endTokenPos' => 9, + 'endFilePos' => 30, + 'kind' => 10, ] )], [ - 'startLine' => 3, - 'startTokenPos' => 2, - 'startFilePos' => 7, + 'startLine' => 5, + 'startTokenPos' => 7, + 'startFilePos' => 24, 'endLine' => 5, 'endTokenPos' => 10, 'endFilePos' => 31, - 'kind' => 1, ] )], - MutatorName::getName(Plus::class), [ - 'startLine' => 5, - 'startTokenPos' => 9, - 'startFilePos' => 29, + 'startLine' => 3, + 'startTokenPos' => 2, + 'startFilePos' => 7, 'endLine' => 5, - 'endTokenPos' => 9, - 'endFilePos' => 30, - 'kind' => 10, - ], - Node\Scalar\LNumber::class, - MutatedNode::wrap( - new Node\Scalar\LNumber( - 15, - [ - 'startLine' => 5, - 'startTokenPos' => 9, - 'startFilePos' => 29, - 'endLine' => 5, - 'endTokenPos' => 9, - 'endFilePos' => 30, - 'kind' => 10, - ] - ) - ), - 0, - [] + 'endTokenPos' => 10, + 'endFilePos' => 31, + 'kind' => 1, + ] + )], + Node\Scalar\LNumber::class, + MutatedNode::wrap( + new Node\Scalar\LNumber( + 15, + [ + 'startLine' => 5, + 'startTokenPos' => 9, + 'startFilePos' => 29, + 'endLine' => 5, + 'endTokenPos' => 9, + 'endFilePos' => 30, + 'kind' => 10, + ] + ) ), <<<'PHP' method($this->anything()) ; - $mutantProcess = new MutantProcess( - $processMock, - new Mutant( - '/path/to/mutant', - new Mutation( - $originalFilePath = 'path/to/Foo.php', - [], - $mutatorName = MutatorName::getName(For_::class), - [ - 'startLine' => $originalStartingLine = 10, - 'endLine' => 15, - 'startTokenPos' => 0, - 'endTokenPos' => 8, - 'startFilePos' => 2, - 'endFilePos' => 4, - ], - 'Unknown', - MutatedNode::wrap(new Nop()), - 0, - [] - ), - 'notCovered#0', - $mutantDiff = <<<'DIFF' + $mutationDiff = <<<'DIFF' --- Original +++ New @@ @@ @@ -124,7 +103,30 @@ public function test_it_can_create_a_result_from_a_non_covered_mutant_process(): - echo 'original'; + echo 'notCovered#0'; -DIFF +DIFF; + + $mutantProcess = new MutantProcess( + $processMock, + new Mutation( + $originalFilePath = 'path/to/Foo.php', + $mutatorName = MutatorName::getName(For_::class), + [ + 'startLine' => $originalStartingLine = 10, + 'endLine' => 15, + 'startTokenPos' => 0, + 'endTokenPos' => 8, + 'startFilePos' => 2, + 'endFilePos' => 4, + ], + [], + static function () use ($mutationDiff): MutationCalculatedState { + return new MutationCalculatedState( + '0800f', + '/path/to/mutation', + 'notCovered#0', + $mutationDiff + ); + } ) ); @@ -133,7 +135,7 @@ public function test_it_can_create_a_result_from_a_non_covered_mutant_process(): $processCommandLine, $processOutput, DetectionStatus::NOT_COVERED, - $mutantDiff, + $mutationDiff, $mutatorName, $originalFilePath, $originalStartingLine @@ -163,35 +165,7 @@ public function test_it_can_create_a_result_from_a_timed_out_mutant_process(): v ->method($this->anything()) ; - $mutantProcess = new MutantProcess( - $processMock, - new Mutant( - '/path/to/mutant', - new Mutation( - $originalFilePath = 'path/to/Foo.php', - [], - $mutatorName = MutatorName::getName(For_::class), - [ - 'startLine' => $originalStartingLine = 10, - 'endLine' => 15, - 'startTokenPos' => 0, - 'endTokenPos' => 8, - 'startFilePos' => 2, - 'endFilePos' => 4, - ], - 'Unknown', - MutatedNode::wrap(new Nop()), - 0, - [ - new TestLocation( - 'FooTest::test_it_can_instantiate', - '/path/to/acme/FooTest.php', - 0.01 - ), - ] - ), - 'timedOut#0', - $mutantDiff = <<<'DIFF' + $mutationDiff = <<<'DIFF' --- Original +++ New @@ @@ @@ -199,9 +173,39 @@ public function test_it_can_create_a_result_from_a_timed_out_mutant_process(): v - echo 'original'; + echo 'timedOut#0'; -DIFF +DIFF; + + $mutantProcess = new MutantProcess( + $processMock, + new Mutation( + $originalFilePath = 'path/to/Foo.php', + $mutatorName = MutatorName::getName(For_::class), + [ + 'startLine' => $originalStartingLine = 10, + 'endLine' => 15, + 'startTokenPos' => 0, + 'endTokenPos' => 8, + 'startFilePos' => 2, + 'endFilePos' => 4, + ], + [ + new TestLocation( + 'FooTest::test_it_can_instantiate', + '/path/to/acme/FooTest.php', + 0.01 + ), + ], + static function () use ($mutationDiff): MutationCalculatedState { + return new MutationCalculatedState( + '0800f', + '/path/to/mutation', + 'timedOut#0', + $mutationDiff + ); + } ) ); + $mutantProcess->markAsTimedOut(); $this->assertResultStateIs( @@ -209,7 +213,7 @@ public function test_it_can_create_a_result_from_a_timed_out_mutant_process(): v $processCommandLine, $processOutput, DetectionStatus::TIMED_OUT, - $mutantDiff, + $mutationDiff, $mutatorName, $originalFilePath, $originalStartingLine @@ -244,35 +248,7 @@ public function test_it_can_create_a_result_from_an_errored_mutant_process(): vo ->method($this->anything()) ; - $mutantProcess = new MutantProcess( - $processMock, - new Mutant( - '/path/to/mutant', - new Mutation( - $originalFilePath = 'path/to/Foo.php', - [], - $mutatorName = MutatorName::getName(For_::class), - [ - 'startLine' => $originalStartingLine = 10, - 'endLine' => 15, - 'startTokenPos' => 0, - 'endTokenPos' => 8, - 'startFilePos' => 2, - 'endFilePos' => 4, - ], - 'Unknown', - MutatedNode::wrap(new Nop()), - 0, - [ - new TestLocation( - 'FooTest::test_it_can_instantiate', - '/path/to/acme/FooTest.php', - 0.01 - ), - ] - ), - 'errored#0', - $mutantDiff = <<<'DIFF' + $mutationDiff = <<<'DIFF' --- Original +++ New @@ @@ @@ -280,7 +256,36 @@ public function test_it_can_create_a_result_from_an_errored_mutant_process(): vo - echo 'original'; + echo 'errored#0'; -DIFF +DIFF; + + $mutantProcess = new MutantProcess( + $processMock, + new Mutation( + $originalFilePath = 'path/to/Foo.php', + $mutatorName = MutatorName::getName(For_::class), + [ + 'startLine' => $originalStartingLine = 10, + 'endLine' => 15, + 'startTokenPos' => 0, + 'endTokenPos' => 8, + 'startFilePos' => 2, + 'endFilePos' => 4, + ], + [ + new TestLocation( + 'FooTest::test_it_can_instantiate', + '/path/to/acme/FooTest.php', + 0.01 + ), + ], + static function () use ($mutationDiff): MutationCalculatedState { + return new MutationCalculatedState( + '0800f', + '/path/to/mutation', + 'errored#0', + $mutationDiff + ); + } ) ); @@ -289,7 +294,7 @@ public function test_it_can_create_a_result_from_an_errored_mutant_process(): vo $processCommandLine, $processOutput, DetectionStatus::ERROR, - $mutantDiff, + $mutationDiff, $mutatorName, $originalFilePath, $originalStartingLine @@ -326,35 +331,7 @@ public function test_it_can_crate_a_result_from_an_escaped_mutant_process(): voi ->willReturn(true) ; - $mutantProcess = new MutantProcess( - $processMock, - new Mutant( - '/path/to/mutant', - new Mutation( - $originalFilePath = 'path/to/Foo.php', - [], - $mutatorName = MutatorName::getName(For_::class), - [ - 'startLine' => $originalStartingLine = 10, - 'endLine' => 15, - 'startTokenPos' => 0, - 'endTokenPos' => 8, - 'startFilePos' => 2, - 'endFilePos' => 4, - ], - 'Unknown', - MutatedNode::wrap(new Nop()), - 0, - [ - new TestLocation( - 'FooTest::test_it_can_instantiate', - '/path/to/acme/FooTest.php', - 0.01 - ), - ] - ), - 'escaped#0', - $mutantDiff = <<<'DIFF' + $mutationDiff = <<<'DIFF' --- Original +++ New @@ @@ @@ -362,7 +339,36 @@ public function test_it_can_crate_a_result_from_an_escaped_mutant_process(): voi - echo 'original'; + echo 'escaped#0'; -DIFF +DIFF; + + $mutantProcess = new MutantProcess( + $processMock, + new Mutation( + $originalFilePath = 'path/to/Foo.php', + $mutatorName = MutatorName::getName(For_::class), + [ + 'startLine' => $originalStartingLine = 10, + 'endLine' => 15, + 'startTokenPos' => 0, + 'endTokenPos' => 8, + 'startFilePos' => 2, + 'endFilePos' => 4, + ], + [ + new TestLocation( + 'FooTest::test_it_can_instantiate', + '/path/to/acme/FooTest.php', + 0.01 + ), + ], + static function () use ($mutationDiff): MutationCalculatedState { + return new MutationCalculatedState( + '0800f', + '/path/to/mutation', + 'escaped#0', + $mutationDiff + ); + } ) ); @@ -371,7 +377,7 @@ public function test_it_can_crate_a_result_from_an_escaped_mutant_process(): voi $processCommandLine, 'Tests passed!', DetectionStatus::ESCAPED, - $mutantDiff, + $mutationDiff, $mutatorName, $originalFilePath, $originalStartingLine @@ -408,35 +414,7 @@ public function test_it_can_crate_a_result_from_a_killed_mutant_process(): void ->willReturn(false) ; - $mutantProcess = new MutantProcess( - $processMock, - new Mutant( - '/path/to/mutant', - new Mutation( - $originalFilePath = 'path/to/Foo.php', - [], - $mutatorName = MutatorName::getName(For_::class), - [ - 'startLine' => $originalStartingLine = 10, - 'endLine' => 15, - 'startTokenPos' => 0, - 'endTokenPos' => 8, - 'startFilePos' => 2, - 'endFilePos' => 4, - ], - 'Unknown', - MutatedNode::wrap(new Nop()), - 0, - [ - new TestLocation( - 'FooTest::test_it_can_instantiate', - '/path/to/acme/FooTest.php', - 0.01 - ), - ] - ), - 'killed#0', - $mutantDiff = <<<'DIFF' + $mutationDiff = <<<'DIFF' --- Original +++ New @@ @@ @@ -444,7 +422,36 @@ public function test_it_can_crate_a_result_from_a_killed_mutant_process(): void - echo 'original'; + echo 'killed#0'; -DIFF +DIFF; + + $mutantProcess = new MutantProcess( + $processMock, + new Mutation( + $originalFilePath = 'path/to/Foo.php', + $mutatorName = MutatorName::getName(For_::class), + [ + 'startLine' => $originalStartingLine = 10, + 'endLine' => 15, + 'startTokenPos' => 0, + 'endTokenPos' => 8, + 'startFilePos' => 2, + 'endFilePos' => 4, + ], + [ + new TestLocation( + 'FooTest::test_it_can_instantiate', + '/path/to/acme/FooTest.php', + 0.01 + ), + ], + static function () use ($mutationDiff): MutationCalculatedState { + return new MutationCalculatedState( + '0800f', + '/path/to/mutation', + 'killed#0', + $mutationDiff + ); + } ) ); @@ -453,7 +460,7 @@ public function test_it_can_crate_a_result_from_a_killed_mutant_process(): void $processCommandLine, 'Tests failed!', DetectionStatus::KILLED, - $mutantDiff, + $mutationDiff, $mutatorName, $originalFilePath, $originalStartingLine diff --git a/tests/phpunit/Mutant/MutantExecutionResultTest.php b/tests/phpunit/Mutant/MutantExecutionResultTest.php index 365219dde..13b081369 100644 --- a/tests/phpunit/Mutant/MutantExecutionResultTest.php +++ b/tests/phpunit/Mutant/MutantExecutionResultTest.php @@ -40,6 +40,7 @@ use Infection\Mutant\Mutant; use Infection\Mutant\MutantExecutionResult; use Infection\Mutation\Mutation; +use Infection\Mutation\MutationCalculatedState; use Infection\Mutator\ZeroIteration\For_; use Infection\PhpParser\MutatedNode; use Infection\Tests\Mutator\MutatorName; @@ -93,33 +94,7 @@ public function test_it_can_be_instantiated(): void public function test_it_can_be_instantiated_from_a_non_covered_mutant(): void { - $mutant = new Mutant( - '/path/to/mutant', - new Mutation( - $originalFilePath = 'path/to/Foo.php', - [], - $mutatorName = MutatorName::getName(For_::class), - [ - 'startLine' => $originalStartingLine = 10, - 'endLine' => 15, - 'startTokenPos' => 0, - 'endTokenPos' => 8, - 'startFilePos' => 2, - 'endFilePos' => 4, - ], - 'Unknown', - MutatedNode::wrap(new Nop()), - 0, - [ - new TestLocation( - 'FooTest::test_it_can_instantiate', - '/path/to/acme/FooTest.php', - 0.01 - ), - ] - ), - 'notCovered#0', - $mutantDiff = <<<'DIFF' + $mutationDiff = <<<'DIFF' --- Original +++ New @@ @@ @@ -127,7 +102,34 @@ public function test_it_can_be_instantiated_from_a_non_covered_mutant(): void - echo 'original'; + echo 'notCovered#0'; -DIFF +DIFF; + + $mutant = new Mutation( + $originalFilePath = 'path/to/Foo.php', + $mutatorName = MutatorName::getName(For_::class), + [ + 'startLine' => $originalStartingLine = 10, + 'endLine' => 15, + 'startTokenPos' => 0, + 'endTokenPos' => 8, + 'startFilePos' => 2, + 'endFilePos' => 4, + ], + [ + new TestLocation( + 'FooTest::test_it_can_instantiate', + '/path/to/acme/FooTest.php', + 0.01 + ), + ], + static function () use ($mutationDiff): MutationCalculatedState { + return new MutationCalculatedState( + '0800f', + '/path/to/mutation', + 'notCovered#0', + $mutationDiff + ); + } ); $this->assertResultStateIs( @@ -135,7 +137,7 @@ public function test_it_can_be_instantiated_from_a_non_covered_mutant(): void '', '', DetectionStatus::NOT_COVERED, - $mutantDiff, + $mutationDiff, $mutatorName, $originalFilePath, $originalStartingLine diff --git a/tests/phpunit/Mutant/MutantFactoryTest.php b/tests/phpunit/Mutant/MutantFactoryTest.php index d957e7c96..ec000c0d4 100644 --- a/tests/phpunit/Mutant/MutantFactoryTest.php +++ b/tests/phpunit/Mutant/MutantFactoryTest.php @@ -42,16 +42,18 @@ use Infection\Mutation\MutationFactory; use Infection\Mutator\Arithmetic\Plus; use Infection\PhpParser\MutatedNode; +use Infection\Tests\Mutation\MutationAssertions; use Infection\Tests\Mutator\MutatorName; use PhpParser\Node; use PhpParser\PrettyPrinterAbstract; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; +use function md5; use function Safe\sprintf; final class MutantFactoryTest extends TestCase { - use MutantAssertions; + use MutationAssertions; /** * @var MutantCodeFactory|MockObject @@ -91,99 +93,114 @@ protected function setUp(): void ); } - public function test_it_creates_a_mutant_instance_from_the_given_mutation(): void + public function test_it_creates_a_mutation(): void { - $mutation = self::createMutation( - $originalNodes = [new Node\Stmt\Namespace_( - new Node\Name('Acme'), - [new Node\Scalar\LNumber(0)] - )], - [] - ); + $originalFilePath = '/path/to/acme/Foo.php'; + $originalFileAst = [new Node\Stmt\Namespace_( + new Node\Name('Acme'), + [new Node\Scalar\LNumber(0)] + )]; + $mutatorName = MutatorName::getName(Plus::class); + $attributes = [ + 'startLine' => $originalStartingLine = 3, + 'endLine' => 5, + 'startTokenPos' => 21, + 'endTokenPos' => 31, + 'startFilePos' => 43, + 'endFilePos' => 53, + ]; + $mutatedNodeClass = Node\Scalar\LNumber::class; + $mutatedNode = MutatedNode::wrap(new Node\Scalar\LNumber(1)); + $mutationByMutatorIndex = 0; + $tests = [ + new TestLocation( + 'FooTest::test_it_can_instantiate', + '/path/to/acme/FooTest.php', + 0.01 + ), + ]; + + $expectedHash = md5('/path/to/acme/Foo.php_Plus_0_3_5_21_31_43_53'); $expectedMutantFilePath = sprintf( '/path/to/tmp/mutant.%s.infection.php', - $mutation->getHash() + $expectedHash ); $this->codeFactoryMock - ->expects($this->once()) + ->expects($this->exactly(2)) ->method('createCode') - ->with($mutation) + ->with( + $attributes, + $originalFileAst, + $mutatedNodeClass, + $mutatedNode + ) ->willReturn('mutated code') ; $this->printerMock ->expects($this->once()) ->method('prettyPrintFile') - ->with($originalNodes) + ->with($originalFileAst) ->willReturn('original code') ; $this->differMock - ->expects($this->once()) + ->expects($this->exactly(2)) ->method('diff') ->with('original code', 'mutated code') ->willReturn('code diff') ; - $mutant = $this->mutantFactory->create($mutation); + $mutation1 = $this->mutantFactory->create( + $originalFilePath, + $originalFileAst, + $mutatorName, + $attributes, + $mutatedNodeClass, + $mutatedNode, + $mutationByMutatorIndex, + $tests + ); - $this->assertMutantStateIs( - $mutant, + $this->assertMutationSateIs( + $mutation1, + $originalFilePath, + $mutatorName, + $tests, + $expectedHash, $expectedMutantFilePath, - $mutation, 'mutated code', - 'code diff' - ); - } - - public function test_it_printing_the_original_file_is_memoized(): void - { - $mutation = self::createMutation( - $originalNodes = [new Node\Stmt\Nop()], - [] + 'code diff', + $originalStartingLine, + true ); - $this->printerMock - ->expects($this->once()) - ->method('prettyPrintFile') - ->with($originalNodes) - ->willReturn('original code') - ; - - $this->differMock - ->expects($this->atLeastOnce()) - ->method('diff') - ->willReturn('code diff') - ; - - $this->mutantFactory->create($mutation); - $this->mutantFactory->create($mutation); - } + // Check memoization - /** - * @param Node[] $originalNodes - * @param TestLocation[] $tests - */ - private static function createMutation(array $originalNodes, array $tests): Mutation - { - return new Mutation( - '/path/to/acme/Foo.php', - $originalNodes, - MutatorName::getName(Plus::class), - [ - 'startLine' => 3, - 'endLine' => 5, - 'startTokenPos' => 21, - 'endTokenPos' => 31, - 'startFilePos' => 43, - 'endFilePos' => 53, - ], - Node\Scalar\LNumber::class, - MutatedNode::wrap(new Node\Scalar\LNumber(1)), - 0, + $mutation2 = $this->mutantFactory->create( + $originalFilePath, + $originalFileAst, + $mutatorName, + $attributes, + $mutatedNodeClass, + $mutatedNode, + $mutationByMutatorIndex, $tests ); + + $this->assertMutationSateIs( + $mutation2, + $originalFilePath, + $mutatorName, + $tests, + $expectedHash, + $expectedMutantFilePath, + 'mutated code', + 'code diff', + $originalStartingLine, + true + ); } } diff --git a/src/Mutant/Mutant.php b/tests/phpunit/Mutation/MutationAssertions.php similarity index 57% rename from src/Mutant/Mutant.php rename to tests/phpunit/Mutation/MutationAssertions.php index 119b32077..eb462e319 100644 --- a/src/Mutant/Mutant.php +++ b/tests/phpunit/Mutation/MutationAssertions.php @@ -33,59 +33,41 @@ declare(strict_types=1); -namespace Infection\Mutant; +namespace Infection\Tests\Mutation; +use Infection\Mutation\MutationCalculatedState; +use function array_merge; use Infection\AbstractTestFramework\Coverage\TestLocation; use Infection\Mutation\Mutation; +use Infection\Mutator\Arithmetic\Plus; +use Infection\PhpParser\MutatedNode; +use Infection\Tests\Mutator\MutatorName; +use function md5; +use PhpParser\Node; +use PHPUnit\Framework\TestCase; -/** - * @internal - * @final - */ -class Mutant +trait MutationAssertions { - private $mutantFilePath; - private $mutation; - private $mutatedCode; - private $diff; - - public function __construct( - string $mutantFilePath, + private function assertMutationSateIs( Mutation $mutation, - string $mutatedCode, - string $diff - ) { - $this->mutantFilePath = $mutantFilePath; - $this->mutation = $mutation; - $this->mutatedCode = $mutatedCode; - $this->diff = $diff; - } - - public function getFilePath(): string - { - return $this->mutantFilePath; - } - - public function getMutation(): Mutation - { - return $this->mutation; - } - - public function getMutatedCode(): string - { - return $this->mutatedCode; - } - - public function getDiff(): string - { - return $this->diff; - } - - /** - * @return TestLocation[] - */ - public function getTests(): array - { - return $this->mutation->getTests(); + string $expectedOriginalFilePath, + string $expectedMutatorName, + array $expectedTests, + string $expectedHash, + string $expectedFilePath, + string $expectedCode, + string $expectedDiff, + int $expectedOriginalStartingLine, + bool $expectedHasTests + ): void { + $this->assertSame($expectedOriginalFilePath, $mutation->getOriginalFilePath()); + $this->assertSame($expectedMutatorName, $mutation->getMutatorName()); + $this->assertSame($expectedOriginalStartingLine, $mutation->getOriginalStartingLine()); + $this->assertSame($expectedTests, $mutation->getTests()); + $this->assertSame($expectedHasTests, $mutation->hasTests()); + $this->assertSame($expectedHash, $mutation->getHash()); + $this->assertSame($expectedFilePath, $mutation->getFilePath()); + $this->assertSame($expectedCode, $mutation->getMutatedCode()); + $this->assertSame($expectedDiff, $mutation->getDiff()); } } diff --git a/tests/phpunit/Mutation/MutationCalculatedStateTest.php b/tests/phpunit/Mutation/MutationCalculatedStateTest.php new file mode 100644 index 000000000..476f91e47 --- /dev/null +++ b/tests/phpunit/Mutation/MutationCalculatedStateTest.php @@ -0,0 +1,36 @@ +assertSame($hash, $state->getMutationHash()); + $this->assertSame($filePath, $state->getMutationFilePath()); + $this->assertSame($code, $state->getMutatedCode()); + $this->assertSame($diff, $state->getDiff()); + } +} diff --git a/tests/phpunit/Mutation/MutationTest.php b/tests/phpunit/Mutation/MutationTest.php index 1b4f77b52..4c2636c71 100644 --- a/tests/phpunit/Mutation/MutationTest.php +++ b/tests/phpunit/Mutation/MutationTest.php @@ -35,6 +35,7 @@ namespace Infection\Tests\Mutation; +use Infection\Mutation\MutationCalculatedState; use function array_merge; use Infection\AbstractTestFramework\Coverage\TestLocation; use Infection\Mutation\Mutation; @@ -57,36 +58,40 @@ final class MutationTest extends TestCase */ public function test_it_can_be_instantiated( string $originalFilePath, - array $originalFileAst, string $mutatorName, array $attributes, - string $mutatedNodeClass, - MutatedNode $mutatedNode, - int $mutationByMutatorIndex, array $tests, - array $expectedAttributes, + string $hash, + string $filePath, + string $code, + string $diff, int $expectedOriginalStartingLine, - bool $expectedHasTests, - string $expectedHash + bool $expectedHasTests ): void { $mutation = new Mutation( $originalFilePath, - $originalFileAst, $mutatorName, $attributes, - $mutatedNodeClass, - $mutatedNode, - $mutationByMutatorIndex, - $tests + $tests, + static function () use ($hash, $filePath, $code, $diff): MutationCalculatedState { + return new MutationCalculatedState( + $hash, + $filePath, + $code, + $diff + ); + } ); $this->assertSame($originalFilePath, $mutation->getOriginalFilePath()); - $this->assertSame($originalFileAst, $mutation->getOriginalFileAst()); $this->assertSame($mutatorName, $mutation->getMutatorName()); $this->assertSame($expectedOriginalStartingLine, $mutation->getOriginalStartingLine()); $this->assertSame($tests, $mutation->getTests()); $this->assertSame($expectedHasTests, $mutation->hasTests()); - $this->assertSame($expectedHash, $mutation->getHash()); + $this->assertSame($hash, $mutation->getHash()); + $this->assertSame($filePath, $mutation->getFilePath()); + $this->assertSame($code, $mutation->getMutatedCode()); + $this->assertSame($diff, $mutation->getDiff()); } public function valuesProvider(): iterable @@ -102,30 +107,21 @@ public function valuesProvider(): iterable yield 'empty' => [ '', - [], MutatorName::getName(Plus::class), $nominalAttributes, - Node\Scalar\LNumber::class, - MutatedNode::wrap(new Node\Scalar\LNumber(1)), - -1, [], - $nominalAttributes, + '', + '', + '', + '', $originalStartingLine, false, - md5('_Plus_-1_3_5_21_31_43_53'), ]; yield 'nominal with a test' => [ '/path/to/acme/Foo.php', - [new Node\Stmt\Namespace_( - new Node\Name('Acme'), - [new Node\Scalar\LNumber(0)] - )], MutatorName::getName(Plus::class), $nominalAttributes, - Node\Scalar\LNumber::class, - MutatedNode::wrap(new Node\Scalar\LNumber(1)), - 0, [ new TestLocation( 'FooTest::test_it_can_instantiate', @@ -133,47 +129,27 @@ public function valuesProvider(): iterable 0.01 ), ], - $nominalAttributes, - $originalStartingLine, - true, - md5('/path/to/acme/Foo.php_Plus_0_3_5_21_31_43_53'), - ]; + '0800f', + '/path/to/mutation', + 'notCovered#0', + <<<'DIFF' +--- Original ++++ New +@@ @@ - yield 'nominal with a test with a different mutator index' => [ - '/path/to/acme/Foo.php', - [new Node\Stmt\Namespace_( - new Node\Name('Acme'), - [new Node\Scalar\LNumber(0)] - )], - MutatorName::getName(Plus::class), - $nominalAttributes, - Node\Scalar\LNumber::class, - MutatedNode::wrap(new Node\Scalar\LNumber(1)), - 99, - [ - new TestLocation( - 'FooTest::test_it_can_instantiate', - '/path/to/acme/FooTest.php', - 0.01 - ), - ], - $nominalAttributes, +- echo 'original'; ++ echo 'notCovered#0'; + +DIFF + , $originalStartingLine, true, - md5('/path/to/acme/Foo.php_Plus_99_3_5_21_31_43_53'), ]; yield 'nominal with a test and additional attributes' => [ '/path/to/acme/Foo.php', - [new Node\Stmt\Namespace_( - new Node\Name('Acme'), - [new Node\Scalar\LNumber(0)] - )], MutatorName::getName(Plus::class), array_merge($nominalAttributes, ['foo' => 100, 'bar' => 1000]), - Node\Scalar\LNumber::class, - MutatedNode::wrap(new Node\Scalar\LNumber(1)), - 0, [ new TestLocation( 'FooTest::test_it_can_instantiate', @@ -181,55 +157,43 @@ public function valuesProvider(): iterable 0.01 ), ], - $nominalAttributes, + '0800f', + '/path/to/mutation', + 'notCovered#0', + <<<'DIFF' +--- Original ++++ New +@@ @@ + +- echo 'original'; ++ echo 'notCovered#0'; + +DIFF + , $originalStartingLine, true, - md5('/path/to/acme/Foo.php_Plus_0_3_5_21_31_43_53'), ]; yield 'nominal without a test' => [ '/path/to/acme/Foo.php', - [new Node\Stmt\Namespace_( - new Node\Name('Acme'), - [new Node\Scalar\LNumber(0)] - )], MutatorName::getName(Plus::class), $nominalAttributes, - Node\Scalar\LNumber::class, - MutatedNode::wrap(new Node\Scalar\LNumber(1)), - 0, [], - $nominalAttributes, - $originalStartingLine, - false, - md5('/path/to/acme/Foo.php_Plus_0_3_5_21_31_43_53'), - ]; + '0800f', + '/path/to/mutation', + 'notCovered#0', + <<<'DIFF' +--- Original ++++ New +@@ @@ - yield 'nominal with a test and multiple mutated nodes' => [ - '/path/to/acme/Foo.php', - [new Node\Stmt\Namespace_( - new Node\Name('Acme'), - [new Node\Scalar\LNumber(0)] - )], - MutatorName::getName(Plus::class), - $nominalAttributes, - Node\Scalar\LNumber::class, - MutatedNode::wrap([ - new Node\Scalar\LNumber(1), - new Node\Scalar\LNumber(-1), - ]), - 0, - [ - new TestLocation( - 'FooTest::test_it_can_instantiate', - '/path/to/acme/FooTest.php', - 0.01 - ), - ], - $nominalAttributes, +- echo 'original'; ++ echo 'notCovered#0'; + +DIFF + , $originalStartingLine, - true, - md5('/path/to/acme/Foo.php_Plus_0_3_5_21_31_43_53'), + false, ]; } } diff --git a/tests/phpunit/PhpParser/Visitor/MutatorVisitorTest.php b/tests/phpunit/PhpParser/Visitor/MutatorVisitorTest.php index 6f310c8ee..55a8fef81 100644 --- a/tests/phpunit/PhpParser/Visitor/MutatorVisitorTest.php +++ b/tests/phpunit/PhpParser/Visitor/MutatorVisitorTest.php @@ -57,15 +57,19 @@ final class MutatorVisitorTest extends BaseVisitorTest * @dataProvider providesMutationCases * * @param Node[] $nodes + * @param array $attributes + * @param class-string $mutatedNodeClass */ public function test_it_mutates_the_correct_node( array $nodes, - string $expectedCodeOutput, - Mutation $mutation + array $attributes, + string $mutatedNodeClass, + MutatedNode $mutatedNode, + string $expectedCodeOutput ): void { $this->traverse( $nodes, - [new MutatorVisitor($mutation)] + [new MutatorVisitor($attributes, $mutatedNodeClass, $mutatedNode)] ); $output = SingletonContainer::getPrinter()->prettyPrintFile($nodes); @@ -77,7 +81,7 @@ public function providesMutationCases(): iterable { yield 'it mutates the correct node' => (function () { return [ - $nodes = $this->parseCode(<<<'PHP' + $this->parseCode(<<<'PHP' 29, + 'endTokenPos' => 48, + 'startLine' => -1, + 'endLine' => -1, + 'startFilePos' => -1, + 'endFilePos' => -1, + ], + ClassMethod::class, + MutatedNode::wrap(new Nop()), <<<'PHP' 29, - 'endTokenPos' => 48, - 'startLine' => -1, - 'endLine' => -1, - 'startFilePos' => -1, - 'endFilePos' => -1, - ], - ClassMethod::class, - MutatedNode::wrap(new Nop()), - 0, - [] - ), ]; })(); yield 'it can mutate the node with multiple-ones' => (function () { return [ - $nodes = $this->parseCode(<<<'PHP' + $this->parseCode(<<<'PHP' 29, + 'endTokenPos' => 48, + 'startLine' => -1, + 'endLine' => -1, + 'startFilePos' => -1, + 'endFilePos' => -1, + ], + ClassMethod::class, + MutatedNode::wrap([new Nop(), new Nop()]), <<<'PHP' 29, - 'endTokenPos' => 48, - 'startLine' => -1, - 'endLine' => -1, - 'startFilePos' => -1, - 'endFilePos' => -1, - ], - ClassMethod::class, - MutatedNode::wrap([new Nop(), new Nop()]), - 0, - [] - ), ]; })(); yield 'it does not mutate if only one of start or end position is correctly set' => (function () { return [ - $nodes = $this->parseCode(<<<'PHP' + $this->parseCode(<<<'PHP' 29, + 'endTokenPos' => 50, + 'startLine' => -1, + 'endLine' => -1, + 'startFilePos' => -1, + 'endFilePos' => -1, + ], + ClassMethod::class, + MutatedNode::wrap(new Nop()), <<<'PHP' 29, - 'endTokenPos' => 50, - 'startLine' => -1, - 'endLine' => -1, - 'startFilePos' => -1, - 'endFilePos' => -1, - ], - ClassMethod::class, - MutatedNode::wrap(new Nop()), - 0, - [] - ), ]; })(); @@ -248,7 +231,7 @@ public function bye() : string $badParser = (new ParserFactory())->create(ParserFactory::PREFER_PHP7, $badLexer); return [ - $nodes = $badParser->parse(<<<'PHP' + $badParser->parse(<<<'PHP' 29, + 'endTokenPos' => 48, + 'startLine' => -1, + 'endLine' => -1, + 'startFilePos' => -1, + 'endFilePos' => -1, + ], + MutatorName::getName(PublicVisibility::class), + MutatedNode::wrap(new Nop()), <<<'PHP' 29, - 'endTokenPos' => 48, - 'startLine' => -1, - 'endLine' => -1, - 'startFilePos' => -1, - 'endFilePos' => -1, - ], - MutatorName::getName(PublicVisibility::class), - MutatedNode::wrap(new Nop()), - 0, - [] - ), ]; })(); } diff --git a/tests/phpunit/Process/Builder/MutantProcessBuilderTest.php b/tests/phpunit/Process/Builder/MutantProcessBuilderTest.php index 1dd958077..33b62f683 100644 --- a/tests/phpunit/Process/Builder/MutantProcessBuilderTest.php +++ b/tests/phpunit/Process/Builder/MutantProcessBuilderTest.php @@ -35,6 +35,7 @@ namespace Infection\Tests\Process\Builder; +use Infection\Mutation\MutationCalculatedState; use function current; use Infection\AbstractTestFramework\Coverage\TestLocation; use Infection\AbstractTestFramework\TestFrameworkAdapter; @@ -56,33 +57,33 @@ final class MutantProcessBuilderTest extends TestCase { public function test_it_creates_a_process_with_timeout(): void { - $mutant = new Mutant( - $mutantFilePath = '/path/to/mutant', - new Mutation( - $originalFilePath = 'path/to/Foo.php', - [], - MutatorName::getName(For_::class), - [ - 'startLine' => $originalStartingLine = 10, - 'endLine' => 15, - 'startTokenPos' => 0, - 'endTokenPos' => 8, - 'startFilePos' => 2, - 'endFilePos' => 4, - ], - 'Unknown', - MutatedNode::wrap(new Nop()), - 0, - $tests = [ - new TestLocation( - 'FooTest::test_it_can_instantiate', - '/path/to/acme/FooTest.php', - 0.01 - ), - ] - ), - 'killed#0', - $mutantDiff = <<<'DIFF' + $hash = '0800f'; + $mutantFilePath = '/path/to/mutation'; + + $mutant = new Mutation( + $originalFilePath = 'path/to/Foo.php', + MutatorName::getName(For_::class), + [ + 'startLine' => $originalStartingLine = 10, + 'endLine' => 15, + 'startTokenPos' => 0, + 'endTokenPos' => 8, + 'startFilePos' => 2, + 'endFilePos' => 4, + ], + $tests = [ + new TestLocation( + 'FooTest::test_it_can_instantiate', + '/path/to/acme/FooTest.php', + 0.01 + ), + ], + static function () use ($hash, $mutantFilePath): MutationCalculatedState { + return new MutationCalculatedState( + $hash, + $mutantFilePath, + 'notCovered#0', + <<<'DIFF' --- Original +++ New @@ @@ @@ -91,9 +92,10 @@ public function test_it_creates_a_process_with_timeout(): void + echo 'killed#0'; DIFF + ); + } ); - $timeout = 100; $testFrameworkExtraOptions = '--verbose'; $testFrameworkAdapterMock = $this->createMock(TestFrameworkAdapter::class); @@ -102,7 +104,7 @@ public function test_it_creates_a_process_with_timeout(): void ->with( $tests, $mutantFilePath, - $this->isType('string'), + $hash, $originalFilePath, $testFrameworkExtraOptions ) diff --git a/tests/phpunit/Process/MutantProcessTest.php b/tests/phpunit/Process/MutantProcessTest.php index 3533df9cd..129e22d0b 100644 --- a/tests/phpunit/Process/MutantProcessTest.php +++ b/tests/phpunit/Process/MutantProcessTest.php @@ -36,6 +36,7 @@ namespace Infection\Tests\Process; use Infection\Mutant\Mutant; +use Infection\Mutation\Mutation; use Infection\Process\MutantProcess; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; @@ -49,9 +50,9 @@ final class MutantProcessTest extends TestCase private $processMock; /** - * @var MockObject|Mutant + * @var MockObject|Mutation */ - private $mutantMock; + private $mutationMock; /** * @var MutantProcess @@ -61,9 +62,9 @@ final class MutantProcessTest extends TestCase protected function setUp(): void { $this->processMock = $this->createMock(Process::class); - $this->mutantMock = $this->createMock(Mutant::class); + $this->mutationMock = $this->createMock(Mutation::class); - $this->mutantProcess = new MutantProcess($this->processMock, $this->mutantMock); + $this->mutantProcess = new MutantProcess($this->processMock, $this->mutationMock); } public function test_it_exposes_its_state(): void @@ -71,7 +72,7 @@ public function test_it_exposes_its_state(): void $this->assertMutantProcessStateIs( $this->mutantProcess, $this->processMock, - $this->mutantMock, + $this->mutationMock, false ); } @@ -83,7 +84,7 @@ public function test_it_can_be_marked_as_timed_out(): void $this->assertMutantProcessStateIs( $this->mutantProcess, $this->processMock, - $this->mutantMock, + $this->mutationMock, true ); } @@ -108,7 +109,7 @@ static function () use (&$called): void { private function assertMutantProcessStateIs( MutantProcess $mutantProcess, Process $expectedProcess, - Mutant $expectedMutant, + Mutation $expectedMutant, bool $expectedTimedOut ): void { $this->assertSame($expectedProcess, $mutantProcess->getProcess()); From 8ea638a53a4f6ece88cd54b08542fb1f2cece205 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20FIDRY?= Date: Wed, 25 Mar 2020 12:18:37 +0100 Subject: [PATCH 05/21] Remove occurrences of mutants --- doc/nomenclature.md | 60 ++++++++++++++++++- .../ValueProvider/ExcludeDirsProvider.php | 2 +- src/Container.php | 20 +++---- src/Engine.php | 15 +++-- ...hed.php => MutationProcessWasFinished.php} | 2 +- ...ationGeneratingConsoleLoggerSubscriber.php | 2 +- ...ationGeneratingConsoleLoggerSubscriber.php | 2 +- ...MutationTestingConsoleLoggerSubscriber.php | 10 ++-- src/Logger/DebugFileLogger.php | 2 +- src/Logger/PerMutatorLogger.php | 2 +- src/Logger/SummaryFileLogger.php | 2 +- src/Logger/TextFileLogger.php | 2 +- src/Metrics/Calculator.php | 2 +- src/Metrics/MetricsCalculator.php | 14 ++--- ...p => SortableMutationExecutionResults.php} | 2 +- src/Mutation/MutationCalculatedState.php | 8 +-- src/Mutation/MutationExecutionResult.php | 12 ++-- .../MutationExecutionResultFactory.php | 18 +++--- src/Mutation/MutationFactory.php | 22 +++---- src/Mutator/MutatorParser.php | 2 +- ...Factory.php => MutationProcessFactory.php} | 20 +++---- ...{MutantProcess.php => MutationProcess.php} | 2 +- src/Process/Runner/MutationTestingRunner.php | 21 +++---- .../AbstractTestFrameworkAdapter.php | 10 ++-- .../Config/MutationConfigBuilder.php | 10 +++- .../Config/Builder/MutationConfigBuilder.php | 8 +-- .../TestFrameworkExtraOptionsFilter.php | 14 +++-- .../OutputFormatter/DotFormatterTest.php | 16 ++--- ...php => MutationProcessWasFinishedTest.php} | 8 +-- ...nitialTestsConsoleLoggerSubscriberTest.php | 2 +- ...nGeneratingConsoleLoggerSubscriberTest.php | 2 +- ...tionTestingConsoleLoggerSubscriberTest.php | 4 +- .../DummyTestFrameworkAdapter.php | 14 ++++- .../phpunit/Metrics/MetricsCalculatorTest.php | 22 +++---- ... SortableMutationExecutionResultsTest.php} | 8 +-- .../Mutation/MutationCodeFactoryTest.php | 10 ++-- ... => MutationExecutionResultAssertions.php} | 6 +- .../MutationExecutionResultFactoryTest.php | 37 ++++++------ .../Mutation/MutationExecutionResultTest.php | 17 +++--- .../phpunit/Mutation/MutationFactoryTest.php | 16 ++--- tests/phpunit/Mutator/BaseMutatorTestCase.php | 16 ++--- ...est.php => MutationProcessFactoryTest.php} | 31 +++++----- ...rocessTest.php => MutationProcessTest.php} | 37 ++++++------ .../Runner/MutationTestingRunnerTest.php | 31 +++++----- .../TestFrameworkExtraOptionsFilterTest.php | 13 ++-- 45 files changed, 322 insertions(+), 254 deletions(-) rename src/Event/{MutantProcessWasFinished.php => MutationProcessWasFinished.php} (98%) rename src/Metrics/{SortableMutantExecutionResults.php => SortableMutationExecutionResults.php} (98%) rename src/Process/Builder/{MutantProcessFactory.php => MutationProcessFactory.php} (85%) rename src/Process/{MutantProcess.php => MutationProcess.php} (98%) rename tests/phpunit/Event/{MutantProcessWasFinishedTest.php => MutationProcessWasFinishedTest.php} (88%) rename tests/phpunit/Metrics/{SortableMutantExecutionResultsTest.php => SortableMutationExecutionResultsTest.php} (96%) rename tests/phpunit/Mutation/{MutantExecutionResultAssertions.php => MutationExecutionResultAssertions.php} (94%) rename tests/phpunit/Process/Builder/{MutantProcessFactoryTest.php => MutationProcessFactoryTest.php} (85%) rename tests/phpunit/Process/{MutantProcessTest.php => MutationProcessTest.php} (75%) diff --git a/doc/nomenclature.md b/doc/nomenclature.md index 752d8720f..1d313d741 100644 --- a/doc/nomenclature.md +++ b/doc/nomenclature.md @@ -2,9 +2,58 @@ ## Table of Contents +- [A](#a) + - [AST][ast] +- [M](#m) + - [Mutagenesis][mutagenesis] + - [Mutant][mutant] + - [Mutation][mutation] + - [Mutator][mutator] +- [S](#s) + - [Subject][subject] - [T](#t) - - [Tracer][tracer] - - [Trace][trace] + - [Tracer][tracer] + - [Trace][trace] + + +## A + +### AST + +Acronym for [Abstract Syntax Tree][ast-definition]. It is a tree representation of the abstract +syntactic structure of code. It is what Infection parses the code into in order to operate on it. + + +## M + +### Mutagenesis + +Process of creating a mutant from the original program. + + +### Mutant + +New program that differs from the original by applying a mutation. + + +### Mutation + +The result of applying a mutator to the AST of a subject and represents a change to be applied. + + +### Mutator + +Define a possible transformation, which applied to the AST of a subject will result in a mutation. + +In the Mutation Testing literature, mutators are also known as "mutant operator", +"mutagenic operator", "mutagen" and "mutation rule". + + +## S + +### Subject + +An addressable piece of code to be targeted for mutation testing. ## T @@ -23,5 +72,12 @@ Artifact produced by a tracer: provides the piece of source code and its associa
+[ast]: #ast +[ast-definition]: https://en.wikipedia.org/wiki/Abstract_syntax_tree +[mutagenesis]: #mutagenesis +[mutant]: #mutant +[mutation]: #mutation +[mutator]: #mutator +[subject]: #subject [tracer]: #tracer [trace]: #trace diff --git a/src/Config/ValueProvider/ExcludeDirsProvider.php b/src/Config/ValueProvider/ExcludeDirsProvider.php index da16e561f..bba913f24 100644 --- a/src/Config/ValueProvider/ExcludeDirsProvider.php +++ b/src/Config/ValueProvider/ExcludeDirsProvider.php @@ -75,7 +75,7 @@ public function get(InputInterface $input, OutputInterface $output, array $dirsI { $output->writeln([ '', - 'There can be situations when you want to exclude some folders from generating mutants.', + 'There can be situations when you want to exclude some folders from generating mutations.', 'You can use glob pattern (*Bundle/**/*/Tests) for them or just regular dir path.', 'It should be relative to the source directory.', 'You should not mutate test suite files.', diff --git a/src/Container.php b/src/Container.php index 44c6971b3..31f790ace 100644 --- a/src/Container.php +++ b/src/Container.php @@ -72,7 +72,7 @@ use Infection\PhpParser\FileParser; use Infection\PhpParser\NodeTraverserFactory; use Infection\Process\Builder\InitialTestRunProcessBuilder; -use Infection\Process\Builder\MutantProcessFactory; +use Infection\Process\Builder\MutationProcessFactory; use Infection\Process\Builder\SubscriberBuilder; use Infection\Process\Runner\DryProcessRunner; use Infection\Process\Runner\InitialTestsRunner; @@ -230,7 +230,7 @@ public static function create(): self $container->getConfiguration()->getTmpDir(), $container->getDiffer(), $container->getPrinter(), - $container->getMutantCodeFactory() + $container->getMutationCodeFactory() ); }, Differ::class => static function (): Differ { @@ -428,12 +428,12 @@ public static function create(): self $container->getEventDispatcher() ); }, - MutantProcessFactory::class => static function (self $container): MutantProcessFactory { - return new MutantProcessFactory( + MutationProcessFactory::class => static function (self $container): MutationProcessFactory { + return new MutationProcessFactory( $container->getTestFrameworkAdapter(), $container->getConfiguration()->getProcessTimeout(), $container->getEventDispatcher(), - $container->getMutantExecutionResultFactory() + $container->getMutationExecutionResultFactory() ); }, MutationGenerator::class => static function (self $container): MutationGenerator { @@ -449,7 +449,7 @@ public static function create(): self }, MutationTestingRunner::class => static function (self $container): MutationTestingRunner { return new MutationTestingRunner( - $container->getMutantProcessFactory(), + $container->getMutationProcessFactory(), $container->getMutationFactory(), $container->getProcessRunner(), $container->getEventDispatcher(), @@ -643,7 +643,7 @@ public function getFactory(): Factory return $this->get(Factory::class); } - public function getMutantCodeFactory(): MutationCodeFactory + public function getMutationCodeFactory(): MutationCodeFactory { return $this->get(MutationCodeFactory::class); } @@ -828,9 +828,9 @@ public function getInitialTestsRunner(): InitialTestsRunner return $this->get(InitialTestsRunner::class); } - public function getMutantProcessFactory(): MutantProcessFactory + public function getMutationProcessFactory(): MutationProcessFactory { - return $this->get(MutantProcessFactory::class); + return $this->get(MutationProcessFactory::class); } public function getMutationGenerator(): MutationGenerator @@ -878,7 +878,7 @@ public function getAdapterInstaller(): AdapterInstaller return $this->get(AdapterInstaller::class); } - public function getMutantExecutionResultFactory(): MutationExecutionResultFactory + public function getMutationExecutionResultFactory(): MutationExecutionResultFactory { return $this->get(MutationExecutionResultFactory::class); } diff --git a/src/Engine.php b/src/Engine.php index 7367e0ecc..897933c48 100644 --- a/src/Engine.php +++ b/src/Engine.php @@ -110,7 +110,7 @@ public function execute(): void $this->runMutationAnalysis(); $this->minMsiChecker->checkMetrics( - $this->metricsCalculator->getTotalMutantsCount(), + $this->metricsCalculator->getTotalMutationsCount(), $this->metricsCalculator->getMutationScoreIndicator(), $this->metricsCalculator->getCoveredCodeMutationScoreIndicator(), $this->consoleOutput @@ -155,12 +155,15 @@ private function runMutationAnalysis(): void : [] ); - $actualExtraOptions = $this->config->getTestFrameworkExtraOptions(); + $extraOptions = $this->config->getTestFrameworkExtraOptions(); - $filteredExtraOptionsForMutant = $this->adapter instanceof ProvidesInitialRunOnlyOptions - ? $this->testFrameworkExtraOptionsFilter->filterForMutantProcess($actualExtraOptions, $this->adapter->getInitialRunOnlyOptions()) - : $actualExtraOptions; + $mutationExtraOptions = $this->adapter instanceof ProvidesInitialRunOnlyOptions + ? $this->testFrameworkExtraOptionsFilter->filterForMutationProcess( + $extraOptions, + $this->adapter->getInitialRunOnlyOptions() + ) + : $extraOptions; - $this->mutationTestingRunner->run($mutations, $filteredExtraOptionsForMutant); + $this->mutationTestingRunner->run($mutations, $mutationExtraOptions); } } diff --git a/src/Event/MutantProcessWasFinished.php b/src/Event/MutationProcessWasFinished.php similarity index 98% rename from src/Event/MutantProcessWasFinished.php rename to src/Event/MutationProcessWasFinished.php index 597c9303e..6b0f8e166 100644 --- a/src/Event/MutantProcessWasFinished.php +++ b/src/Event/MutationProcessWasFinished.php @@ -40,7 +40,7 @@ /** * @internal */ -final class MutantProcessWasFinished +final class MutationProcessWasFinished { private $executionResult; diff --git a/src/Event/Subscriber/CiMutationGeneratingConsoleLoggerSubscriber.php b/src/Event/Subscriber/CiMutationGeneratingConsoleLoggerSubscriber.php index 5a8e4b05c..aa3a993be 100644 --- a/src/Event/Subscriber/CiMutationGeneratingConsoleLoggerSubscriber.php +++ b/src/Event/Subscriber/CiMutationGeneratingConsoleLoggerSubscriber.php @@ -55,7 +55,7 @@ public function onMutationGenerationWasStarted(MutationGenerationWasStarted $eve { $this->output->writeln([ '', - 'Generate mutants...', + 'Generate mutations...', '', sprintf('Processing source code files: %s', $event->getMutableFilesCount()), ]); diff --git a/src/Event/Subscriber/MutationGeneratingConsoleLoggerSubscriber.php b/src/Event/Subscriber/MutationGeneratingConsoleLoggerSubscriber.php index 9e8df10d3..a0ce162c8 100644 --- a/src/Event/Subscriber/MutationGeneratingConsoleLoggerSubscriber.php +++ b/src/Event/Subscriber/MutationGeneratingConsoleLoggerSubscriber.php @@ -59,7 +59,7 @@ public function __construct(OutputInterface $output) public function onMutationGenerationWasStarted(MutationGenerationWasStarted $event): void { - $this->output->writeln(['', '', 'Generate mutants...', '']); + $this->output->writeln(['', '', 'Generate mutations...', '']); $this->progressBar->start($event->getMutableFilesCount()); } diff --git a/src/Event/Subscriber/MutationTestingConsoleLoggerSubscriber.php b/src/Event/Subscriber/MutationTestingConsoleLoggerSubscriber.php index daf88af9c..8c6318258 100644 --- a/src/Event/Subscriber/MutationTestingConsoleLoggerSubscriber.php +++ b/src/Event/Subscriber/MutationTestingConsoleLoggerSubscriber.php @@ -37,7 +37,7 @@ use Infection\Console\OutputFormatter\OutputFormatter; use Infection\Differ\DiffColorizer; -use Infection\Event\MutantProcessWasFinished; +use Infection\Event\MutationProcessWasFinished; use Infection\Event\MutationTestingWasFinished; use Infection\Event\MutationTestingWasStarted; use Infection\Metrics\MetricsCalculator; @@ -88,7 +88,7 @@ public function onMutationTestingWasStarted(MutationTestingWasStarted $event): v $this->outputFormatter->start($this->mutationCount); } - public function onMutantProcessWasFinished(MutantProcessWasFinished $event): void + public function onMutantProcessWasFinished(MutationProcessWasFinished $event): void { $executionResult = $event->getExecutionResult(); @@ -117,7 +117,7 @@ public function onMutationTestingWasFinished(MutationTestingWasFinished $event): */ private function showMutations(array $executionResults, string $headlinePrefix): void { - $headline = sprintf('%s mutants:', $headlinePrefix); + $headline = sprintf('%s mutations:', $headlinePrefix); $this->output->writeln([ '', @@ -138,14 +138,14 @@ private function showMutations(array $executionResults, string $headlinePrefix): ), ]); - $this->output->writeln($this->diffColorizer->colorize($executionResult->getMutantDiff())); + $this->output->writeln($this->diffColorizer->colorize($executionResult->getMutationDiff())); } } private function showMetrics(): void { $this->output->writeln(['', '']); - $this->output->writeln('' . $this->metricsCalculator->getTotalMutantsCount() . ' mutations were generated:'); + $this->output->writeln('' . $this->metricsCalculator->getTotalMutationsCount() . ' mutations were generated:'); $this->output->writeln('' . $this->getPadded($this->metricsCalculator->getKilledCount()) . ' mutants were killed'); $this->output->writeln('' . $this->getPadded($this->metricsCalculator->getNotTestedCount()) . ' mutants were not covered by tests'); $this->output->writeln('' . $this->getPadded($this->metricsCalculator->getEscapedCount()) . ' covered mutants were not detected'); diff --git a/src/Logger/DebugFileLogger.php b/src/Logger/DebugFileLogger.php index 450e77d03..2553bf84f 100644 --- a/src/Logger/DebugFileLogger.php +++ b/src/Logger/DebugFileLogger.php @@ -66,7 +66,7 @@ public function getLogLines(): array $logs = []; - $logs[] = 'Total: ' . $this->metricsCalculator->getTotalMutantsCount(); + $logs[] = 'Total: ' . $this->metricsCalculator->getTotalMutationsCount(); $logs[] = ''; $logs[] = $this->getResultsLine( $this->metricsCalculator->getKilledExecutionResults(), diff --git a/src/Logger/PerMutatorLogger.php b/src/Logger/PerMutatorLogger.php index be8685137..f4596c907 100644 --- a/src/Logger/PerMutatorLogger.php +++ b/src/Logger/PerMutatorLogger.php @@ -76,7 +76,7 @@ public function getLogLines(): array /* @var MetricsCalculator $calculator */ $table[] = [ $mutatorName, - (string) $calculator->getTotalMutantsCount(), + (string) $calculator->getTotalMutationsCount(), (string) $calculator->getKilledCount(), (string) $calculator->getEscapedCount(), (string) $calculator->getErrorCount(), diff --git a/src/Logger/SummaryFileLogger.php b/src/Logger/SummaryFileLogger.php index 8a5dcbc73..a5b01b0cc 100644 --- a/src/Logger/SummaryFileLogger.php +++ b/src/Logger/SummaryFileLogger.php @@ -55,7 +55,7 @@ public function __construct(MetricsCalculator $metricsCalculator) public function getLogLines(): array { return [ - 'Total: ' . $this->metricsCalculator->getTotalMutantsCount(), + 'Total: ' . $this->metricsCalculator->getTotalMutationsCount(), '', 'Killed: ' . $this->metricsCalculator->getKilledCount(), 'Errored: ' . $this->metricsCalculator->getErrorCount(), diff --git a/src/Logger/TextFileLogger.php b/src/Logger/TextFileLogger.php index 7305195d2..3e9530c5a 100644 --- a/src/Logger/TextFileLogger.php +++ b/src/Logger/TextFileLogger.php @@ -138,7 +138,7 @@ private function getResultsLine( $lines[] = self::getMutatorLine($index, $executionResult); $lines[] = ''; - $lines[] = Str::trimLineReturns($executionResult->getMutantDiff()); + $lines[] = Str::trimLineReturns($executionResult->getMutationDiff()); if ($this->debugMode) { $lines[] = ''; diff --git a/src/Metrics/Calculator.php b/src/Metrics/Calculator.php index 32c24c594..9dd188700 100644 --- a/src/Metrics/Calculator.php +++ b/src/Metrics/Calculator.php @@ -82,7 +82,7 @@ public static function fromMetrics(MetricsCalculator $calculator): self $calculator->getErrorCount(), $calculator->getTimedOutCount(), $calculator->getNotTestedCount(), - $calculator->getTotalMutantsCount() + $calculator->getTotalMutationsCount() ); } diff --git a/src/Metrics/MetricsCalculator.php b/src/Metrics/MetricsCalculator.php index 4a322db44..39e65727d 100644 --- a/src/Metrics/MetricsCalculator.php +++ b/src/Metrics/MetricsCalculator.php @@ -88,12 +88,12 @@ class MetricsCalculator public function __construct() { - $this->killedExecutionResults = new SortableMutantExecutionResults(); - $this->errorExecutionResults = new SortableMutantExecutionResults(); - $this->escapedExecutionResults = new SortableMutantExecutionResults(); - $this->timedOutExecutionResults = new SortableMutantExecutionResults(); - $this->notCoveredExecutionResults = new SortableMutantExecutionResults(); - $this->allExecutionResults = new SortableMutantExecutionResults(); + $this->killedExecutionResults = new SortableMutationExecutionResults(); + $this->errorExecutionResults = new SortableMutationExecutionResults(); + $this->escapedExecutionResults = new SortableMutationExecutionResults(); + $this->timedOutExecutionResults = new SortableMutationExecutionResults(); + $this->notCoveredExecutionResults = new SortableMutationExecutionResults(); + $this->allExecutionResults = new SortableMutationExecutionResults(); } public function collect(MutationExecutionResult ...$executionResults): void @@ -167,7 +167,7 @@ public function getNotTestedCount(): int return $this->notExecutedByTestsCount; } - public function getTotalMutantsCount(): int + public function getTotalMutationsCount(): int { return $this->totalMutantsCount; } diff --git a/src/Metrics/SortableMutantExecutionResults.php b/src/Metrics/SortableMutationExecutionResults.php similarity index 98% rename from src/Metrics/SortableMutantExecutionResults.php rename to src/Metrics/SortableMutationExecutionResults.php index 6afcecb78..731e28e96 100644 --- a/src/Metrics/SortableMutantExecutionResults.php +++ b/src/Metrics/SortableMutationExecutionResults.php @@ -41,7 +41,7 @@ /** * @internal */ -final class SortableMutantExecutionResults +final class SortableMutationExecutionResults { /** * @var \Infection\Mutation\MutationExecutionResult[] diff --git a/src/Mutation/MutationCalculatedState.php b/src/Mutation/MutationCalculatedState.php index 8679371e5..94c0d810b 100644 --- a/src/Mutation/MutationCalculatedState.php +++ b/src/Mutation/MutationCalculatedState.php @@ -37,19 +37,19 @@ final class MutationCalculatedState { - private $mutantFilePath; + private $mutationFilePath; private $mutatedCode; private $diff; private $mutationHash; public function __construct( string $mutationHash, - string $mutantFilePath, + string $mutationFilePath, string $mutatedCode, string $diff ) { $this->mutationHash = $mutationHash; - $this->mutantFilePath = $mutantFilePath; + $this->mutationFilePath = $mutationFilePath; $this->mutatedCode = $mutatedCode; $this->diff = $diff; } @@ -61,7 +61,7 @@ public function getMutationHash(): string public function getMutationFilePath(): string { - return $this->mutantFilePath; + return $this->mutationFilePath; } public function getMutatedCode(): string diff --git a/src/Mutation/MutationExecutionResult.php b/src/Mutation/MutationExecutionResult.php index af9040468..f5d2a5353 100644 --- a/src/Mutation/MutationExecutionResult.php +++ b/src/Mutation/MutationExecutionResult.php @@ -48,7 +48,7 @@ class MutationExecutionResult private $processCommandLine; private $processOutput; private $detectionStatus; - private $mutantDiff; + private $mutationDiff; private $mutatorName; private $originalFilePath; private $originalStartingLine; @@ -57,7 +57,7 @@ public function __construct( string $processCommandLine, string $processOutput, string $detectionStatus, - string $mutantDiff, + string $mutationDiff, string $mutatorName, string $originalFilePath, int $originalStartingLine @@ -68,13 +68,13 @@ public function __construct( $this->processCommandLine = $processCommandLine; $this->processOutput = $processOutput; $this->detectionStatus = $detectionStatus; - $this->mutantDiff = $mutantDiff; + $this->mutationDiff = $mutationDiff; $this->mutatorName = $mutatorName; $this->originalFilePath = $originalFilePath; $this->originalStartingLine = $originalStartingLine; } - public static function createFromNonCoveredMutant(Mutation $mutation): self + public static function createFromNonCoveredMutation(Mutation $mutation): self { return new self( '', @@ -102,9 +102,9 @@ public function getDetectionStatus(): string return $this->detectionStatus; } - public function getMutantDiff(): string + public function getMutationDiff(): string { - return $this->mutantDiff; + return $this->mutationDiff; } public function getMutatorName(): string diff --git a/src/Mutation/MutationExecutionResultFactory.php b/src/Mutation/MutationExecutionResultFactory.php index 968be5ff1..facc6c26a 100644 --- a/src/Mutation/MutationExecutionResultFactory.php +++ b/src/Mutation/MutationExecutionResultFactory.php @@ -36,7 +36,7 @@ namespace Infection\Mutation; use Infection\AbstractTestFramework\TestFrameworkAdapter; -use Infection\Process\MutantProcess; +use Infection\Process\MutationProcess; use Symfony\Component\Process\Process; use Webmozart\Assert\Assert; use function Safe\sprintf; @@ -54,15 +54,15 @@ public function __construct(TestFrameworkAdapter $testFrameworkAdapter) $this->testFrameworkAdapter = $testFrameworkAdapter; } - public function createFromProcess(MutantProcess $mutantProcess): MutationExecutionResult + public function createFromProcess(MutationProcess $mutationProcess): MutationExecutionResult { - $process = $mutantProcess->getProcess(); - $mutation = $mutantProcess->getMutation(); + $process = $mutationProcess->getProcess(); + $mutation = $mutationProcess->getMutation(); return new MutationExecutionResult( $process->getCommandLine(), $this->retrieveProcessOutput($process), - $this->retrieveDetectionStatus($mutantProcess), + $this->retrieveDetectionStatus($mutationProcess), $mutation->getDiff(), $mutation->getMutatorName(), $mutation->getOriginalFilePath(), @@ -83,17 +83,17 @@ private function retrieveProcessOutput(Process $process): string return $process->getOutput(); } - private function retrieveDetectionStatus(MutantProcess $mutantProcess): string + private function retrieveDetectionStatus(MutationProcess $mutationProcess): string { - if (!$mutantProcess->getMutation()->hasTests()) { + if (!$mutationProcess->getMutation()->hasTests()) { return DetectionStatus::NOT_COVERED; } - if ($mutantProcess->isTimedOut()) { + if ($mutationProcess->isTimedOut()) { return DetectionStatus::TIMED_OUT; } - $process = $mutantProcess->getProcess(); + $process = $mutationProcess->getProcess(); if ($process->getExitCode() > 100) { // See \Symfony\Component\Process\Process::$exitCodes diff --git a/src/Mutation/MutationFactory.php b/src/Mutation/MutationFactory.php index 056fd6f2c..32379d40a 100644 --- a/src/Mutation/MutationFactory.php +++ b/src/Mutation/MutationFactory.php @@ -58,18 +58,18 @@ class MutationFactory * @var string[] */ private $printedFileCache = []; - private $mutantCodeFactory; + private $mutationCodeFactory; public function __construct( string $tmpDir, Differ $differ, PrettyPrinterAbstract $printer, - MutationCodeFactory $mutantCodeFactory + MutationCodeFactory $mutationCodeFactory ) { $this->tmpDir = $tmpDir; $this->differ = $differ; $this->printer = $printer; - $this->mutantCodeFactory = $mutantCodeFactory; + $this->mutationCodeFactory = $mutationCodeFactory; } /** @@ -134,13 +134,13 @@ private function calculateState( $mutationByMutatorIndex ); - $mutantFilePath = sprintf( - '%s/mutant.%s.infection.php', + $mutationFilePath = sprintf( + '%s/mutation.%s.infection.php', $this->tmpDir, $hash ); - $mutatedCode = $this->mutantCodeFactory->createCode( + $mutatedCode = $this->mutationCodeFactory->createCode( $attributes, $originalFileAst, $mutatedNodeClass, @@ -149,9 +149,9 @@ private function calculateState( return new MutationCalculatedState( $hash, - $mutantFilePath, + $mutationFilePath, $mutatedCode, - $this->createMutantDiff( + $this->createMutationDiff( $originalFilePath, $originalFileAst, $mutatedCode @@ -181,17 +181,17 @@ private static function createHash( /** * @param Node[] $originalFileAst */ - private function createMutantDiff( + private function createMutationDiff( string $originalFilePath, array $originalFileAst, - string $mutantCode + string $mutationCode ): string { $originalPrettyPrintedFile = $this->getOriginalPrettyPrintedFile( $originalFilePath, $originalFileAst ); - return $this->differ->diff($originalPrettyPrintedFile, $mutantCode); + return $this->differ->diff($originalPrettyPrintedFile, $mutationCode); } /** diff --git a/src/Mutator/MutatorParser.php b/src/Mutator/MutatorParser.php index c61e554b0..0924a4946 100644 --- a/src/Mutator/MutatorParser.php +++ b/src/Mutator/MutatorParser.php @@ -89,7 +89,7 @@ public function parse(string $unparsedMutators): array throw new UnexpectedValueException( sprintf( 'Expected "%s" to be a known mutator or profile. See "%s" and "%s" for ' - . 'the list of available mutants and profiles.', + . 'the list of available mutations and profiles.', $profileOrMutator, 'https://infection.github.io/guide/mutators.html', 'https://infection.github.io/guide/profiles.html' diff --git a/src/Process/Builder/MutantProcessFactory.php b/src/Process/Builder/MutationProcessFactory.php similarity index 85% rename from src/Process/Builder/MutantProcessFactory.php rename to src/Process/Builder/MutationProcessFactory.php index f0adefe98..39d908c91 100644 --- a/src/Process/Builder/MutantProcessFactory.php +++ b/src/Process/Builder/MutationProcessFactory.php @@ -37,10 +37,10 @@ use Infection\AbstractTestFramework\TestFrameworkAdapter; use Infection\Event\EventDispatcher\EventDispatcher; -use Infection\Event\MutantProcessWasFinished; +use Infection\Event\MutationProcessWasFinished; use Infection\Mutation\Mutation; use Infection\Mutation\MutationExecutionResultFactory; -use Infection\Process\MutantProcess; +use Infection\Process\MutationProcess; use Symfony\Component\Process\Process; use function method_exists; @@ -48,7 +48,7 @@ * @internal * @final */ -class MutantProcessFactory +class MutationProcessFactory { private $testFrameworkAdapter; private $timeout; @@ -68,7 +68,7 @@ public function __construct( $this->resultFactory = $resultFactory; } - public function createProcessForMutant(Mutation $mutation, string $testFrameworkExtraOptions = ''): MutantProcess + public function createProcessForMutation(Mutation $mutation, string $testFrameworkExtraOptions = ''): MutationProcess { $process = new Process( $this->testFrameworkAdapter->getMutantCommandLine( @@ -87,21 +87,21 @@ public function createProcessForMutant(Mutation $mutation, string $testFramework $process->inheritEnvironmentVariables(); } - $mutantProcess = new MutantProcess($process, $mutation); + $mutationProcess = new MutationProcess($process, $mutation); $eventDispatcher = $this->eventDispatcher; $resultFactory = $this->resultFactory; - $mutantProcess->registerTerminateProcessClosure(static function () use ( - $mutantProcess, + $mutationProcess->registerTerminateProcessClosure(static function () use ( + $mutationProcess, $eventDispatcher, $resultFactory ): void { - $eventDispatcher->dispatch(new MutantProcessWasFinished( - $resultFactory->createFromProcess($mutantProcess)) + $eventDispatcher->dispatch(new MutationProcessWasFinished( + $resultFactory->createFromProcess($mutationProcess)) ); }); - return $mutantProcess; + return $mutationProcess; } } diff --git a/src/Process/MutantProcess.php b/src/Process/MutationProcess.php similarity index 98% rename from src/Process/MutantProcess.php rename to src/Process/MutationProcess.php index a01b2f994..1d0f3dd9e 100644 --- a/src/Process/MutantProcess.php +++ b/src/Process/MutationProcess.php @@ -44,7 +44,7 @@ * @internal * @final */ -class MutantProcess implements ProcessBearer +class MutationProcess implements ProcessBearer { private $process; private $mutation; diff --git a/src/Process/Runner/MutationTestingRunner.php b/src/Process/Runner/MutationTestingRunner.php index 2df0b2017..3dc36990c 100644 --- a/src/Process/Runner/MutationTestingRunner.php +++ b/src/Process/Runner/MutationTestingRunner.php @@ -36,14 +36,13 @@ namespace Infection\Process\Runner; use Infection\Event\EventDispatcher\EventDispatcher; -use Infection\Event\MutantProcessWasFinished; +use Infection\Event\MutationProcessWasFinished; use Infection\Event\MutationTestingWasFinished; use Infection\Event\MutationTestingWasStarted; use Infection\IterableCounter; -use Infection\Mutant\Mutant; use Infection\Mutation\Mutation; use Infection\Mutation\MutationExecutionResult; -use Infection\Process\Builder\MutantProcessFactory; +use Infection\Process\Builder\MutationProcessFactory; use Symfony\Component\Filesystem\Filesystem; use function Pipeline\take; @@ -59,7 +58,7 @@ final class MutationTestingRunner private $runConcurrently; public function __construct( - MutantProcessFactory $processFactory, + MutationProcessFactory $processFactory, ProcessRunner $processRunner, EventDispatcher $eventDispatcher, Filesystem $fileSystem, @@ -77,21 +76,17 @@ public function __construct( */ public function run(iterable $mutations, string $testFrameworkExtraOptions): void { - $numberOfMutants = IterableCounter::bufferAndCountIfNeeded($mutations, $this->runConcurrently); - $this->eventDispatcher->dispatch(new MutationTestingWasStarted($numberOfMutants)); + $numberOfMutations = IterableCounter::bufferAndCountIfNeeded($mutations, $this->runConcurrently); + $this->eventDispatcher->dispatch(new MutationTestingWasStarted($numberOfMutations)); $processes = take($mutations) ->filter(function (Mutation $mutation) { - // The filtering is done here since with a mutant and not earlier with a mutation - // since: - // - if pass the filtering, the mutant is going to be used - // - if does not pass the filtering, the mutant is used for the reports if ($mutation->hasTests()) { return true; } - $this->eventDispatcher->dispatch(new MutantProcessWasFinished( - MutationExecutionResult::createFromNonCoveredMutant($mutation) + $this->eventDispatcher->dispatch(new MutationProcessWasFinished( + MutationExecutionResult::createFromNonCoveredMutation($mutation) )); return false; @@ -99,7 +94,7 @@ public function run(iterable $mutations, string $testFrameworkExtraOptions): voi ->map(function (Mutation $mutation) use ($testFrameworkExtraOptions): ProcessBearer { $this->fileSystem->dumpFile($mutation->getFilePath(), $mutation->getMutatedCode()); - $process = $this->processFactory->createProcessForMutant( + $process = $this->processFactory->createProcessForMutation( $mutation, $testFrameworkExtraOptions ); diff --git a/src/TestFramework/AbstractTestFrameworkAdapter.php b/src/TestFramework/AbstractTestFrameworkAdapter.php index 599196ca9..362f0cfc6 100644 --- a/src/TestFramework/AbstractTestFrameworkAdapter.php +++ b/src/TestFramework/AbstractTestFrameworkAdapter.php @@ -98,7 +98,7 @@ public function getInitialTestRunCommandLine( } /** - * Returns array of arguments to pass them into the Mutant Symfony Process + * Returns array of arguments to pass them into the Mutation Symfony's process * * @param TestLocation[] $tests * @@ -106,7 +106,7 @@ public function getInitialTestRunCommandLine( */ public function getMutantCommandLine( array $tests, - string $mutantFilePath, + string $mutationFilePath, string $mutationHash, string $mutationOriginalFilePath, string $extraOptions @@ -114,7 +114,7 @@ public function getMutantCommandLine( return $this->getCommandLine( $this->buildMutationConfigFile( $tests, - $mutantFilePath, + $mutationFilePath, $mutationHash, $mutationOriginalFilePath ), @@ -166,13 +166,13 @@ protected function buildInitialConfigFile(): string */ protected function buildMutationConfigFile( array $tests, - string $mutantFilePath, + string $mutationFilePath, string $mutationHash, string $mutationOriginalFilePath ): string { return $this->mutationConfigBuilder->build( $tests, - $mutantFilePath, + $mutationFilePath, $mutationHash, $mutationOriginalFilePath ); diff --git a/src/TestFramework/Config/MutationConfigBuilder.php b/src/TestFramework/Config/MutationConfigBuilder.php index 15daf7fc8..027314a62 100644 --- a/src/TestFramework/Config/MutationConfigBuilder.php +++ b/src/TestFramework/Config/MutationConfigBuilder.php @@ -53,12 +53,16 @@ abstract class MutationConfigBuilder */ abstract public function build( array $tests, - string $mutantFilePath, + string $mutationFilePath, string $mutationHash, string $mutationOriginalFilePath ): string; - protected function getInterceptorFileContent(string $interceptorPath, string $originalFilePath, string $mutantFilePath): string + protected function getInterceptorFileContent( + string $interceptorPath, + string $originalFilePath, + string $mutationFilePath + ): string { $infectionPhar = ''; @@ -78,7 +82,7 @@ protected function getInterceptorFileContent(string $interceptorPath, string $or use {$namespacePrefix}Infection\StreamWrapper\IncludeInterceptor; -IncludeInterceptor::intercept('{$originalFilePath}', '{$mutantFilePath}'); +IncludeInterceptor::intercept('{$originalFilePath}', '{$mutationFilePath}'); IncludeInterceptor::enable(); CONTENT; } diff --git a/src/TestFramework/PhpUnit/Config/Builder/MutationConfigBuilder.php b/src/TestFramework/PhpUnit/Config/Builder/MutationConfigBuilder.php index 063a8ba04..b5df447ad 100644 --- a/src/TestFramework/PhpUnit/Config/Builder/MutationConfigBuilder.php +++ b/src/TestFramework/PhpUnit/Config/Builder/MutationConfigBuilder.php @@ -89,7 +89,7 @@ public function __construct( */ public function build( array $tests, - string $mutantFilePath, + string $mutationFilePath, string $mutationHash, string $mutationOriginalFilePath ): string { @@ -125,7 +125,7 @@ public function build( $customAutoloadFilePath, $this->createCustomAutoloadWithInterceptor( $mutationOriginalFilePath, - $mutantFilePath, + $mutationFilePath, $originalBootstrapFile ) ); @@ -155,7 +155,7 @@ private function getDom(): DOMDocument private function createCustomAutoloadWithInterceptor( string $originalFilePath, - string $mutantFilePath, + string $mutationFilePath, string $originalAutoloadFile ): string { $interceptorPath = IncludeInterceptor::LOCATION; @@ -172,7 +172,7 @@ private function createCustomAutoloadWithInterceptor( PHP , - $this->getInterceptorFileContent($interceptorPath, $originalFilePath, $mutantFilePath), + $this->getInterceptorFileContent($interceptorPath, $originalFilePath, $mutationFilePath), $originalAutoloadFile ); } diff --git a/src/TestFramework/TestFrameworkExtraOptionsFilter.php b/src/TestFramework/TestFrameworkExtraOptionsFilter.php index 417d5ff4e..6d286c182 100644 --- a/src/TestFramework/TestFrameworkExtraOptionsFilter.php +++ b/src/TestFramework/TestFrameworkExtraOptionsFilter.php @@ -47,14 +47,18 @@ final class TestFrameworkExtraOptionsFilter { /** * @param string[] $initialRunOnlyOptions - * - * @throws \Safe\Exceptions\PcreException - * @throws \Safe\Exceptions\StringsException */ - public function filterForMutantProcess(string $actualExtraOptions, array $initialRunOnlyOptions): string + public function filterForMutationProcess( + string $actualExtraOptions, + array $initialRunOnlyOptions + ): string { foreach ($initialRunOnlyOptions as $initialRunOnlyOption) { - $actualExtraOptions = preg_replace(sprintf('/%s[\=| ](?:\"[^\"]*\"|\'[^\']*\'|[^\ ]*)/', $initialRunOnlyOption), '', $actualExtraOptions); + $actualExtraOptions = preg_replace( + sprintf('/%s[\=| ](?:\"[^\"]*\"|\'[^\']*\'|[^\ ]*)/', $initialRunOnlyOption), + '', + $actualExtraOptions + ); Assert::notNull($actualExtraOptions); } diff --git a/tests/phpunit/Console/OutputFormatter/DotFormatterTest.php b/tests/phpunit/Console/OutputFormatter/DotFormatterTest.php index d5f22bb69..22477af83 100644 --- a/tests/phpunit/Console/OutputFormatter/DotFormatterTest.php +++ b/tests/phpunit/Console/OutputFormatter/DotFormatterTest.php @@ -77,7 +77,7 @@ public function test_killed_logs_correctly_in_console(): void $dot = new DotFormatter($outputKilled); $dot->start(10); $dot->advance( - $this->createMutantExecutionResultsOfType(DetectionStatus::KILLED)[0], + $this->createMutationExecutionResultsOfType(DetectionStatus::KILLED)[0], 10 ); } @@ -94,7 +94,7 @@ public function test_escaped_logs_correctly_in_console(): void $dot = new DotFormatter($outputEscaped); $dot->start(10); $dot->advance( - $this->createMutantExecutionResultsOfType(DetectionStatus::ESCAPED)[0], + $this->createMutationExecutionResultsOfType(DetectionStatus::ESCAPED)[0], 10 ); } @@ -111,7 +111,7 @@ public function test_errored_logs_correctly_in_console(): void $dot = new DotFormatter($outputErrored); $dot->start(10); $dot->advance( - $this->createMutantExecutionResultsOfType(DetectionStatus::ERROR)[0], + $this->createMutationExecutionResultsOfType(DetectionStatus::ERROR)[0], 10 ); } @@ -128,7 +128,7 @@ public function test_timed_out_logs_correctly_in_console(): void $dot = new DotFormatter($outputTimedOut); $dot->start(10); $dot->advance( - $this->createMutantExecutionResultsOfType(DetectionStatus::TIMED_OUT)[0], + $this->createMutationExecutionResultsOfType(DetectionStatus::TIMED_OUT)[0], 10 ); } @@ -145,7 +145,7 @@ public function test_not_covered_correctly_in_console(): void $dot = new DotFormatter($outputNotCovered); $dot->start(10); $dot->advance( - $this->createMutantExecutionResultsOfType(DetectionStatus::NOT_COVERED)[0], + $this->createMutationExecutionResultsOfType(DetectionStatus::NOT_COVERED)[0], 10 ); } @@ -159,7 +159,7 @@ public function test_it_prints_total_number_of_mutations(): void $dot->start($totalMutations); for ($i = 0; $i < $totalMutations; ++$i) { - $dot->advance($this->createMutantExecutionResultsOfType(DetectionStatus::KILLED)[0], $totalMutations); + $dot->advance($this->createMutationExecutionResultsOfType(DetectionStatus::KILLED)[0], $totalMutations); } $this->assertSame(str_replace("\n", PHP_EOL, @@ -186,7 +186,7 @@ public function test_it_prints_current_number_of_pending_mutations(): void for ($i = 0; $i < $totalMutations; ++$i) { $dot->advance( - $this->createMutantExecutionResultsOfType(DetectionStatus::KILLED)[0], + $this->createMutationExecutionResultsOfType(DetectionStatus::KILLED)[0], 0 ); } @@ -205,7 +205,7 @@ public function test_it_prints_current_number_of_pending_mutations(): void ); } - private function createMutantExecutionResultsOfType( + private function createMutationExecutionResultsOfType( string $detectionStatus, int $count = 1 ): array { diff --git a/tests/phpunit/Event/MutantProcessWasFinishedTest.php b/tests/phpunit/Event/MutationProcessWasFinishedTest.php similarity index 88% rename from tests/phpunit/Event/MutantProcessWasFinishedTest.php rename to tests/phpunit/Event/MutationProcessWasFinishedTest.php index 5194d2f6d..246df59a8 100644 --- a/tests/phpunit/Event/MutantProcessWasFinishedTest.php +++ b/tests/phpunit/Event/MutationProcessWasFinishedTest.php @@ -35,17 +35,17 @@ namespace Infection\Tests\Event; -use Infection\Event\MutantProcessWasFinished; +use Infection\Event\MutationProcessWasFinished; use Infection\Mutation\MutationExecutionResult; use PHPUnit\Framework\TestCase; -final class MutantProcessWasFinishedTest extends TestCase +final class MutationProcessWasFinishedTest extends TestCase { - public function test_it_exposes_its_mutant_process(): void + public function test_it_exposes_its_mutation_process(): void { $executionResultMock = $this->createMock(MutationExecutionResult::class); - $event = new MutantProcessWasFinished($executionResultMock); + $event = new MutationProcessWasFinished($executionResultMock); $this->assertSame($executionResultMock, $event->getExecutionResult()); } diff --git a/tests/phpunit/Event/Subscriber/CiInitialTestsConsoleLoggerSubscriberTest.php b/tests/phpunit/Event/Subscriber/CiInitialTestsConsoleLoggerSubscriberTest.php index 424359f78..38922a95c 100644 --- a/tests/phpunit/Event/Subscriber/CiInitialTestsConsoleLoggerSubscriberTest.php +++ b/tests/phpunit/Event/Subscriber/CiInitialTestsConsoleLoggerSubscriberTest.php @@ -63,7 +63,7 @@ protected function setUp(): void $this->testFramework = $this->createMock(AbstractTestFrameworkAdapter::class); } - public function test_it_reacts_on_mutants_creating_event(): void + public function test_it_reacts_on_mutations_creating_event(): void { $this->output->expects($this->once()) ->method('writeln') diff --git a/tests/phpunit/Event/Subscriber/CiMutationGeneratingConsoleLoggerSubscriberTest.php b/tests/phpunit/Event/Subscriber/CiMutationGeneratingConsoleLoggerSubscriberTest.php index d0ae92855..2d97cc187 100644 --- a/tests/phpunit/Event/Subscriber/CiMutationGeneratingConsoleLoggerSubscriberTest.php +++ b/tests/phpunit/Event/Subscriber/CiMutationGeneratingConsoleLoggerSubscriberTest.php @@ -62,7 +62,7 @@ public function test_it_reacts_on_mutation_generating_started_event(): void ->method('writeln') ->with([ '', - 'Generate mutants...', + 'Generate mutations...', '', 'Processing source code files: 123', ]); diff --git a/tests/phpunit/Event/Subscriber/MutationTestingConsoleLoggerSubscriberTest.php b/tests/phpunit/Event/Subscriber/MutationTestingConsoleLoggerSubscriberTest.php index bc68a61fc..4f17e7888 100644 --- a/tests/phpunit/Event/Subscriber/MutationTestingConsoleLoggerSubscriberTest.php +++ b/tests/phpunit/Event/Subscriber/MutationTestingConsoleLoggerSubscriberTest.php @@ -38,7 +38,7 @@ use Infection\Console\OutputFormatter\OutputFormatter; use Infection\Differ\DiffColorizer; use Infection\Event\EventDispatcher\SyncEventDispatcher; -use Infection\Event\MutantProcessWasFinished; +use Infection\Event\MutationProcessWasFinished; use Infection\Event\MutationTestingWasFinished; use Infection\Event\MutationTestingWasStarted; use Infection\Event\Subscriber\MutationTestingConsoleLoggerSubscriber; @@ -116,7 +116,7 @@ public function test_it_reacts_on_mutation_process_finished(): void )); $dispatcher->dispatch( - new MutantProcessWasFinished( + new MutationProcessWasFinished( $this->createMock(MutationExecutionResult::class) ) ); diff --git a/tests/phpunit/Fixtures/TestFramework/DummyTestFrameworkAdapter.php b/tests/phpunit/Fixtures/TestFramework/DummyTestFrameworkAdapter.php index 7f2d982a7..fcf94fd83 100644 --- a/tests/phpunit/Fixtures/TestFramework/DummyTestFrameworkAdapter.php +++ b/tests/phpunit/Fixtures/TestFramework/DummyTestFrameworkAdapter.php @@ -23,12 +23,22 @@ public function hasJUnitReport(): bool return false; } - public function getInitialTestRunCommandLine(string $extraOptions, array $phpExtraArgs, bool $skipCoverage): array + public function getInitialTestRunCommandLine( + string $extraOptions, + array $phpExtraArgs, + bool $skipCoverage + ): array { return ['/bin/dummy']; } - public function getMutantCommandLine(array $coverageTests, string $mutatedFilePath, string $mutationHash, string $mutationOriginalFilePath, string $extraOptions): array + public function getMutantCommandLine( + array $coverageTests, + string $mutatedFilePath, + string $mutationHash, + string $mutationOriginalFilePath, + string $extraOptions + ): array { return ['/bin/dummy']; } diff --git a/tests/phpunit/Metrics/MetricsCalculatorTest.php b/tests/phpunit/Metrics/MetricsCalculatorTest.php index 4ee6110be..3c661ed65 100644 --- a/tests/phpunit/Metrics/MetricsCalculatorTest.php +++ b/tests/phpunit/Metrics/MetricsCalculatorTest.php @@ -56,7 +56,7 @@ public function test_it_shows_zero_values_by_default(): void $this->assertSame(0, $calculator->getEscapedCount()); $this->assertSame(0, $calculator->getTimedOutCount()); $this->assertSame(0, $calculator->getNotTestedCount()); - $this->assertSame(0, $calculator->getTotalMutantsCount()); + $this->assertSame(0, $calculator->getTotalMutationsCount()); $this->assertSame([], $calculator->getKilledExecutionResults()); $this->assertSame([], $calculator->getErrorExecutionResults()); @@ -74,27 +74,27 @@ public function test_it_collects_all_values(): void { $calculator = new MetricsCalculator(); - $expectedKilledResults = $this->addMutantExecutionResult( + $expectedKilledResults = $this->addMutationExecutionResult( $calculator, DetectionStatus::KILLED, 7 ); - $expectedErrorResults = $this->addMutantExecutionResult( + $expectedErrorResults = $this->addMutationExecutionResult( $calculator, DetectionStatus::ERROR, 2 ); - $expectedEscapedResults = $this->addMutantExecutionResult( + $expectedEscapedResults = $this->addMutationExecutionResult( $calculator, DetectionStatus::ESCAPED, 2 ); - $expectedTimedOutResults = $this->addMutantExecutionResult( + $expectedTimedOutResults = $this->addMutationExecutionResult( $calculator, DetectionStatus::TIMED_OUT, 2 ); - $expectedNotCoveredResults = $this->addMutantExecutionResult( + $expectedNotCoveredResults = $this->addMutationExecutionResult( $calculator, DetectionStatus::NOT_COVERED, 1 @@ -122,7 +122,7 @@ public function test_it_collects_all_values(): void $calculator->getAllExecutionResults() ); - $this->assertSame(14, $calculator->getTotalMutantsCount()); + $this->assertSame(14, $calculator->getTotalMutationsCount()); $this->assertSame(78.57142857142857, $calculator->getMutationScoreIndicator()); $this->assertSame(92.85714285714286, $calculator->getCoverageRate()); $this->assertSame(84.61538461538461, $calculator->getCoveredCodeMutationScoreIndicator()); @@ -139,7 +139,7 @@ public function test_its_metrics_are_properly_updated_when_adding_a_new_process( $this->assertSame(0.0, $calculator->getCoverageRate()); $this->assertSame(0.0, $calculator->getCoveredCodeMutationScoreIndicator()); - $expectedKilledResults = $this->addMutantExecutionResult( + $expectedKilledResults = $this->addMutationExecutionResult( $calculator, DetectionStatus::KILLED, 1 @@ -156,7 +156,7 @@ public function test_its_metrics_are_properly_updated_when_adding_a_new_process( /** * @return \Infection\Mutation\MutationExecutionResult[] */ - private function addMutantExecutionResult( + private function addMutationExecutionResult( MetricsCalculator $calculator, string $detectionStatus, int $count @@ -164,7 +164,7 @@ private function addMutantExecutionResult( $executionResults = []; for ($i = 0; $i < $count; ++$i) { - $executionResults[] = $this->createMutantExecutionResult($detectionStatus); + $executionResults[] = $this->createMutationExecutionResult($detectionStatus); } $calculator->collect(...$executionResults); @@ -172,7 +172,7 @@ private function addMutantExecutionResult( return $executionResults; } - private function createMutantExecutionResult(string $detectionStatus): MutationExecutionResult + private function createMutationExecutionResult(string $detectionStatus): MutationExecutionResult { $id = $this->id; ++$this->id; diff --git a/tests/phpunit/Metrics/SortableMutantExecutionResultsTest.php b/tests/phpunit/Metrics/SortableMutationExecutionResultsTest.php similarity index 96% rename from tests/phpunit/Metrics/SortableMutantExecutionResultsTest.php rename to tests/phpunit/Metrics/SortableMutationExecutionResultsTest.php index 23e3221cd..216a50c51 100644 --- a/tests/phpunit/Metrics/SortableMutantExecutionResultsTest.php +++ b/tests/phpunit/Metrics/SortableMutationExecutionResultsTest.php @@ -35,14 +35,14 @@ namespace Infection\Tests\Metrics; -use Infection\Metrics\SortableMutantExecutionResults; +use Infection\Metrics\SortableMutationExecutionResults; use Infection\Mutation\DetectionStatus; use Infection\Mutation\MutationExecutionResult; use Infection\Mutator\ZeroIteration\For_; use Infection\Tests\Mutator\MutatorName; use PHPUnit\Framework\TestCase; -final class SortableMutantExecutionResultsTest extends TestCase +final class SortableMutationExecutionResultsTest extends TestCase { /** * @dataProvider resultsProvider @@ -52,7 +52,7 @@ final class SortableMutantExecutionResultsTest extends TestCase */ public function test_it_can_sort_results(array $executionResults, array $expectedResults): void { - $sortableResults = new SortableMutantExecutionResults(); + $sortableResults = new SortableMutationExecutionResults(); foreach ($executionResults as $executionResult) { $sortableResults->add($executionResult); @@ -63,7 +63,7 @@ public function test_it_can_sort_results(array $executionResults, array $expecte public function test_it_keeps_results_sorted_as_they_are_added(): void { - $sortableResults = new SortableMutantExecutionResults(); + $sortableResults = new SortableMutationExecutionResults(); $result0 = $this->createExecutionResult( 0, diff --git a/tests/phpunit/Mutation/MutationCodeFactoryTest.php b/tests/phpunit/Mutation/MutationCodeFactoryTest.php index 791af2b70..e2da0fc86 100644 --- a/tests/phpunit/Mutation/MutationCodeFactoryTest.php +++ b/tests/phpunit/Mutation/MutationCodeFactoryTest.php @@ -49,7 +49,7 @@ final class MutationCodeFactoryTest extends TestCase protected function setUp(): void { - $this->codeFactory = SingletonContainer::getContainer()->getMutantCodeFactory(); + $this->codeFactory = SingletonContainer::getContainer()->getMutationCodeFactory(); } /** @@ -59,12 +59,12 @@ protected function setUp(): void * @param Node[] $originalFileAst * @param class-string $mutatedNodeClass */ - public function test_it_creates_the_mutant_code_from_the_given_mutation( + public function test_it_creates_the_mutation_code_from_the_given_mutation( array $attributes, array $originalFileAst, string $mutatedNodeClass, MutatedNode $mutatedNode, - string $expectedMutantCode + string $expectedMutationCode ): void { $mutationCode = $this->codeFactory->createCode( $attributes, @@ -73,7 +73,7 @@ public function test_it_creates_the_mutant_code_from_the_given_mutation( $mutatedNode ); - $this->assertSame($expectedMutantCode, $mutationCode); + $this->assertSame($expectedMutationCode, $mutationCode); } /** @@ -83,7 +83,7 @@ public function test_it_creates_the_mutant_code_from_the_given_mutation( * @param Node[] $originalFileAst * @param class-string $mutatedNodeClass */ - public function test_it_creates_the_mutant_code_without_altering_the_original_nodes( + public function test_it_creates_the_mutation_code_without_altering_the_original_nodes( array $attributes, array $originalFileAst, string $mutatedNodeClass, diff --git a/tests/phpunit/Mutation/MutantExecutionResultAssertions.php b/tests/phpunit/Mutation/MutationExecutionResultAssertions.php similarity index 94% rename from tests/phpunit/Mutation/MutantExecutionResultAssertions.php rename to tests/phpunit/Mutation/MutationExecutionResultAssertions.php index b8cc05f94..48d04cfd0 100644 --- a/tests/phpunit/Mutation/MutantExecutionResultAssertions.php +++ b/tests/phpunit/Mutation/MutationExecutionResultAssertions.php @@ -35,14 +35,14 @@ namespace Infection\Tests\Mutation; -trait MutantExecutionResultAssertions +trait MutationExecutionResultAssertions { private function assertResultStateIs( \Infection\Mutation\MutationExecutionResult $result, string $expectedProcessCommandLine, string $expectedProcessOutput, string $expectedDetectionStatus, - string $expectedMutantDiff, + string $expectedMutationDiff, string $expectedMutatorName, string $expectedOriginalFilePath, int $expectedOriginalStartingLine @@ -50,7 +50,7 @@ private function assertResultStateIs( $this->assertSame($expectedProcessCommandLine, $result->getProcessCommandLine()); $this->assertSame($expectedProcessOutput, $result->getProcessOutput()); $this->assertSame($expectedDetectionStatus, $result->getDetectionStatus()); - $this->assertSame($expectedMutantDiff, $result->getMutantDiff()); + $this->assertSame($expectedMutationDiff, $result->getMutationDiff()); $this->assertSame($expectedMutatorName, $result->getMutatorName()); $this->assertSame($expectedOriginalFilePath, $result->getOriginalFilePath()); $this->assertSame($expectedOriginalStartingLine, $result->getOriginalStartingLine()); diff --git a/tests/phpunit/Mutation/MutationExecutionResultFactoryTest.php b/tests/phpunit/Mutation/MutationExecutionResultFactoryTest.php index 3802d1a45..bad99c03d 100644 --- a/tests/phpunit/Mutation/MutationExecutionResultFactoryTest.php +++ b/tests/phpunit/Mutation/MutationExecutionResultFactoryTest.php @@ -37,13 +37,12 @@ use Infection\AbstractTestFramework\Coverage\TestLocation; use Infection\AbstractTestFramework\TestFrameworkAdapter; -use Infection\Mutant\Mutant; use Infection\Mutation\DetectionStatus; use Infection\Mutation\Mutation; use Infection\Mutation\MutationCalculatedState; use Infection\Mutation\MutationExecutionResultFactory; use Infection\Mutator\ZeroIteration\For_; -use Infection\Process\MutantProcess; +use Infection\Process\MutationProcess; use Infection\Tests\Mutator\MutatorName; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; @@ -51,7 +50,7 @@ final class MutationExecutionResultFactoryTest extends TestCase { - use MutantExecutionResultAssertions; + use MutationExecutionResultAssertions; /** * @var TestFrameworkAdapter|MockObject @@ -70,7 +69,7 @@ protected function setUp(): void $this->resultFactory = new MutationExecutionResultFactory($this->testFrameworkAdapterMock); } - public function test_it_can_create_a_result_from_a_non_covered_mutant_process(): void + public function test_it_can_create_a_result_from_a_non_covered_mutation_process(): void { $processMock = $this->createMock(Process::class); $processMock @@ -103,7 +102,7 @@ public function test_it_can_create_a_result_from_a_non_covered_mutant_process(): DIFF; - $mutantProcess = new MutantProcess( + $mutationProcess = new MutationProcess( $processMock, new Mutation( $originalFilePath = 'path/to/Foo.php', @@ -129,7 +128,7 @@ static function () use ($mutationDiff): MutationCalculatedState { ); $this->assertResultStateIs( - $this->resultFactory->createFromProcess($mutantProcess), + $this->resultFactory->createFromProcess($mutationProcess), $processCommandLine, $processOutput, \Infection\Mutation\DetectionStatus::NOT_COVERED, @@ -140,7 +139,7 @@ static function () use ($mutationDiff): MutationCalculatedState { ); } - public function test_it_can_create_a_result_from_a_timed_out_mutant_process(): void + public function test_it_can_create_a_result_from_a_timed_out_mutation_process(): void { $processMock = $this->createMock(Process::class); $processMock @@ -173,7 +172,7 @@ public function test_it_can_create_a_result_from_a_timed_out_mutant_process(): v DIFF; - $mutantProcess = new MutantProcess( + $mutationProcess = new MutationProcess( $processMock, new Mutation( $originalFilePath = 'path/to/Foo.php', @@ -204,10 +203,10 @@ static function () use ($mutationDiff): MutationCalculatedState { ) ); - $mutantProcess->markAsTimedOut(); + $mutationProcess->markAsTimedOut(); $this->assertResultStateIs( - $this->resultFactory->createFromProcess($mutantProcess), + $this->resultFactory->createFromProcess($mutationProcess), $processCommandLine, $processOutput, \Infection\Mutation\DetectionStatus::TIMED_OUT, @@ -218,7 +217,7 @@ static function () use ($mutationDiff): MutationCalculatedState { ); } - public function test_it_can_create_a_result_from_an_errored_mutant_process(): void + public function test_it_can_create_a_result_from_an_errored_mutation_process(): void { $processMock = $this->createMock(Process::class); $processMock @@ -256,7 +255,7 @@ public function test_it_can_create_a_result_from_an_errored_mutant_process(): vo DIFF; - $mutantProcess = new MutantProcess( + $mutationProcess = new MutationProcess( $processMock, new Mutation( $originalFilePath = 'path/to/Foo.php', @@ -288,7 +287,7 @@ static function () use ($mutationDiff): MutationCalculatedState { ); $this->assertResultStateIs( - $this->resultFactory->createFromProcess($mutantProcess), + $this->resultFactory->createFromProcess($mutationProcess), $processCommandLine, $processOutput, DetectionStatus::ERROR, @@ -299,7 +298,7 @@ static function () use ($mutationDiff): MutationCalculatedState { ); } - public function test_it_can_crate_a_result_from_an_escaped_mutant_process(): void + public function test_it_can_crate_a_result_from_an_escaped_mutation_process(): void { $processMock = $this->createMock(Process::class); $processMock @@ -339,7 +338,7 @@ public function test_it_can_crate_a_result_from_an_escaped_mutant_process(): voi DIFF; - $mutantProcess = new MutantProcess( + $mutationProcess = new MutationProcess( $processMock, new Mutation( $originalFilePath = 'path/to/Foo.php', @@ -371,7 +370,7 @@ static function () use ($mutationDiff): MutationCalculatedState { ); $this->assertResultStateIs( - $this->resultFactory->createFromProcess($mutantProcess), + $this->resultFactory->createFromProcess($mutationProcess), $processCommandLine, 'Tests passed!', DetectionStatus::ESCAPED, @@ -382,7 +381,7 @@ static function () use ($mutationDiff): MutationCalculatedState { ); } - public function test_it_can_crate_a_result_from_a_killed_mutant_process(): void + public function test_it_can_crate_a_result_from_a_killed_mutation_process(): void { $processMock = $this->createMock(Process::class); $processMock @@ -422,7 +421,7 @@ public function test_it_can_crate_a_result_from_a_killed_mutant_process(): void DIFF; - $mutantProcess = new MutantProcess( + $mutationProcess = new MutationProcess( $processMock, new Mutation( $originalFilePath = 'path/to/Foo.php', @@ -454,7 +453,7 @@ static function () use ($mutationDiff): MutationCalculatedState { ); $this->assertResultStateIs( - $this->resultFactory->createFromProcess($mutantProcess), + $this->resultFactory->createFromProcess($mutationProcess), $processCommandLine, 'Tests failed!', DetectionStatus::KILLED, diff --git a/tests/phpunit/Mutation/MutationExecutionResultTest.php b/tests/phpunit/Mutation/MutationExecutionResultTest.php index 4de0a6fbf..8cdcb7793 100644 --- a/tests/phpunit/Mutation/MutationExecutionResultTest.php +++ b/tests/phpunit/Mutation/MutationExecutionResultTest.php @@ -36,7 +36,6 @@ namespace Infection\Tests\Mutation; use Infection\AbstractTestFramework\Coverage\TestLocation; -use Infection\Mutant\Mutant; use Infection\Mutation\Mutation; use Infection\Mutation\MutationCalculatedState; use Infection\Mutation\MutationExecutionResult; @@ -51,7 +50,7 @@ public function test_it_can_be_instantiated(): void $processCommandLine = 'bin/phpunit --configuration infection-tmp-phpunit.xml --filter "tests/Acme/FooTest.php"'; $processOutput = 'Passed!'; $processResultCode = \Infection\Mutation\DetectionStatus::ESCAPED; - $mutantDiff = <<<'DIFF' + $mutationDiff = <<<'DIFF' --- Original +++ New @@ @@ @@ -69,7 +68,7 @@ public function test_it_can_be_instantiated(): void $processCommandLine, $processOutput, $processResultCode, - $mutantDiff, + $mutationDiff, $mutatorName, $originalFilePath, $originalStartingLine @@ -80,14 +79,14 @@ public function test_it_can_be_instantiated(): void $processCommandLine, $processOutput, $processResultCode, - $mutantDiff, + $mutationDiff, $mutatorName, $originalFilePath, $originalStartingLine ); } - public function test_it_can_be_instantiated_from_a_non_covered_mutant(): void + public function test_it_can_be_instantiated_from_a_non_covered_mutation(): void { $mutationDiff = <<<'DIFF' --- Original @@ -99,7 +98,7 @@ public function test_it_can_be_instantiated_from_a_non_covered_mutant(): void DIFF; - $mutant = new Mutation( + $mutation = new Mutation( $originalFilePath = 'path/to/Foo.php', $mutatorName = MutatorName::getName(For_::class), [ @@ -128,7 +127,7 @@ static function () use ($mutationDiff): MutationCalculatedState { ); $this->assertResultStateIs( - MutationExecutionResult::createFromNonCoveredMutant($mutant), + MutationExecutionResult::createFromNonCoveredMutation($mutation), '', '', \Infection\Mutation\DetectionStatus::NOT_COVERED, @@ -144,7 +143,7 @@ private function assertResultStateIs( string $expectedProcessCommandLine, string $expectedProcessOutput, string $expectedDetectionStatus, - string $expectedMutantDiff, + string $expectedMutationDiff, string $expectedMutatorName, string $expectedOriginalFilePath, int $expectedOriginalStartingLine @@ -152,7 +151,7 @@ private function assertResultStateIs( $this->assertSame($expectedProcessCommandLine, $result->getProcessCommandLine()); $this->assertSame($expectedProcessOutput, $result->getProcessOutput()); $this->assertSame($expectedDetectionStatus, $result->getDetectionStatus()); - $this->assertSame($expectedMutantDiff, $result->getMutantDiff()); + $this->assertSame($expectedMutationDiff, $result->getMutationDiff()); $this->assertSame($expectedMutatorName, $result->getMutatorName()); $this->assertSame($expectedOriginalFilePath, $result->getOriginalFilePath()); $this->assertSame($expectedOriginalStartingLine, $result->getOriginalStartingLine()); diff --git a/tests/phpunit/Mutation/MutationFactoryTest.php b/tests/phpunit/Mutation/MutationFactoryTest.php index 3e08900a7..a245d1b48 100644 --- a/tests/phpunit/Mutation/MutationFactoryTest.php +++ b/tests/phpunit/Mutation/MutationFactoryTest.php @@ -71,7 +71,7 @@ final class MutationFactoryTest extends TestCase /** * @var \Infection\Mutation\MutationFactory */ - private $mutantFactory; + private $mutationFactory; protected function setUp(): void { @@ -83,7 +83,7 @@ protected function setUp(): void $this->differMock = $this->createMock(Differ::class); - $this->mutantFactory = new MutationFactory( + $this->mutationFactory = new MutationFactory( '/path/to/tmp', $this->differMock, $this->printerMock, @@ -120,8 +120,8 @@ public function test_it_creates_a_mutation(): void $expectedHash = md5('/path/to/acme/Foo.php_Plus_0_3_5_21_31_43_53'); - $expectedMutantFilePath = sprintf( - '/path/to/tmp/mutant.%s.infection.php', + $expectedMutationFilePath = sprintf( + '/path/to/tmp/mutation.%s.infection.php', $expectedHash ); @@ -151,7 +151,7 @@ public function test_it_creates_a_mutation(): void ->willReturn('code diff') ; - $mutation1 = $this->mutantFactory->create( + $mutation1 = $this->mutationFactory->create( $originalFilePath, $originalFileAst, $mutatorName, @@ -168,7 +168,7 @@ public function test_it_creates_a_mutation(): void $mutatorName, $tests, $expectedHash, - $expectedMutantFilePath, + $expectedMutationFilePath, 'mutated code', 'code diff', $originalStartingLine, @@ -177,7 +177,7 @@ public function test_it_creates_a_mutation(): void // Check memoization - $mutation2 = $this->mutantFactory->create( + $mutation2 = $this->mutationFactory->create( $originalFilePath, $originalFileAst, $mutatorName, @@ -194,7 +194,7 @@ public function test_it_creates_a_mutation(): void $mutatorName, $tests, $expectedHash, - $expectedMutantFilePath, + $expectedMutationFilePath, 'mutated code', 'code diff', $originalStartingLine, diff --git a/tests/phpunit/Mutator/BaseMutatorTestCase.php b/tests/phpunit/Mutator/BaseMutatorTestCase.php index 33a082aa1..a2debcf37 100644 --- a/tests/phpunit/Mutator/BaseMutatorTestCase.php +++ b/tests/phpunit/Mutator/BaseMutatorTestCase.php @@ -81,19 +81,19 @@ final public function doTest(string $inputCode, $expectedCode = [], array $setti $this->fail('Input code cant be the same as mutated code'); } - $mutants = $this->mutate($inputCode, $settings); + $mutations = $this->mutate($inputCode, $settings); $this->assertCount( - count($mutants), + count($mutations), $expectedCodeSamples, sprintf( - 'Failed asserting that the number of code samples (%d) equals the number of mutants (%d) created by the mutator.', + 'Failed asserting that the number of code samples (%d) equals the number of mutations (%d) created by the mutator.', count($expectedCodeSamples), - count($mutants) + count($mutations) ) ); - foreach ($mutants as $realMutatedCode) { + foreach ($mutations as $realMutatedCode) { /** @var string|null $expectedCodeSample */ $expectedCodeSample = array_shift($expectedCodeSamples); @@ -134,7 +134,7 @@ final protected function mutate(string $code, array $settings = []): array $traverser = new NodeTraverser(); $traverser->addVisitor(new CloneVisitor()); - $mutants = []; + $mutations = []; foreach ($mutations as $mutation) { $mutatorVisitor = new MutatorVisitor($mutation); @@ -143,12 +143,12 @@ final protected function mutate(string $code, array $settings = []): array $mutatedStatements = $traverser->traverse($mutation->getOriginalFileAst()); - $mutants[] = SingletonContainer::getPrinter()->prettyPrintFile($mutatedStatements); + $mutations[] = SingletonContainer::getPrinter()->prettyPrintFile($mutatedStatements); $traverser->removeVisitor($mutatorVisitor); } - return $mutants; + return $mutations; } /** diff --git a/tests/phpunit/Process/Builder/MutantProcessFactoryTest.php b/tests/phpunit/Process/Builder/MutationProcessFactoryTest.php similarity index 85% rename from tests/phpunit/Process/Builder/MutantProcessFactoryTest.php rename to tests/phpunit/Process/Builder/MutationProcessFactoryTest.php index f9e36dfcd..d2b7856f2 100644 --- a/tests/phpunit/Process/Builder/MutantProcessFactoryTest.php +++ b/tests/phpunit/Process/Builder/MutationProcessFactoryTest.php @@ -37,28 +37,27 @@ use Infection\AbstractTestFramework\Coverage\TestLocation; use Infection\AbstractTestFramework\TestFrameworkAdapter; -use Infection\Event\MutantProcessWasFinished; -use Infection\Mutant\Mutant; +use Infection\Event\MutationProcessWasFinished; use Infection\Mutation\Mutation; use Infection\Mutation\MutationCalculatedState; use Infection\Mutation\MutationExecutionResult; use Infection\Mutation\MutationExecutionResultFactory; use Infection\Mutator\ZeroIteration\For_; -use Infection\Process\Builder\MutantProcessFactory; +use Infection\Process\Builder\MutationProcessFactory; use Infection\Tests\Fixtures\Event\EventDispatcherCollector; use Infection\Tests\Mutator\MutatorName; use PHPUnit\Framework\TestCase; use function current; use const PHP_OS_FAMILY; -final class MutantProcessFactoryTest extends TestCase +final class MutationProcessFactoryTest extends TestCase { public function test_it_creates_a_process_with_timeout(): void { $hash = '0800f'; - $mutantFilePath = '/path/to/mutation'; + $mutationFilePath = '/path/to/mutation'; - $mutant = new Mutation( + $mutation = new Mutation( $originalFilePath = 'path/to/Foo.php', MutatorName::getName(For_::class), [ @@ -76,10 +75,10 @@ public function test_it_creates_a_process_with_timeout(): void 0.01 ), ], - static function () use ($hash, $mutantFilePath): MutationCalculatedState { + static function () use ($hash, $mutationFilePath): MutationCalculatedState { return new MutationCalculatedState( $hash, - $mutantFilePath, + $mutationFilePath, 'notCovered#0', <<<'DIFF' --- Original @@ -101,7 +100,7 @@ static function () use ($hash, $mutantFilePath): MutationCalculatedState { ->method('getMutantCommandLine') ->with( $tests, - $mutantFilePath, + $mutationFilePath, $hash, $originalFilePath, $testFrameworkExtraOptions @@ -123,16 +122,16 @@ static function () use ($hash, $mutantFilePath): MutationCalculatedState { ->willReturn($executionResultMock) ; - $factory = new MutantProcessFactory( + $factory = new MutationProcessFactory( $testFrameworkAdapterMock, 100, $eventDispatcher, $resultFactoryMock ); - $mutantProcess = $factory->createProcessForMutant($mutant, $testFrameworkExtraOptions); + $mutationProcess = $factory->createProcessForMutation($mutation, $testFrameworkExtraOptions); - $process = $mutantProcess->getProcess(); + $process = $mutationProcess->getProcess(); $this->assertSame( PHP_OS_FAMILY === 'Windows' @@ -143,12 +142,12 @@ static function () use ($hash, $mutantFilePath): MutationCalculatedState { $this->assertSame(100., $process->getTimeout()); $this->assertFalse($process->isStarted()); - $this->assertSame($mutant, $mutantProcess->getMutation()); - $this->assertFalse($mutantProcess->isTimedOut()); + $this->assertSame($mutation, $mutationProcess->getMutation()); + $this->assertFalse($mutationProcess->isTimedOut()); $this->assertSame([], $eventDispatcher->getEvents()); - $mutantProcess->terminateProcess(); + $mutationProcess->terminateProcess(); $eventsAfterCallbackCall = $eventDispatcher->getEvents(); @@ -156,7 +155,7 @@ static function () use ($hash, $mutantFilePath): MutationCalculatedState { $event = current($eventsAfterCallbackCall); - $this->assertInstanceOf(MutantProcessWasFinished::class, $event); + $this->assertInstanceOf(MutationProcessWasFinished::class, $event); $this->assertSame($executionResultMock, $event->getExecutionResult()); } } diff --git a/tests/phpunit/Process/MutantProcessTest.php b/tests/phpunit/Process/MutationProcessTest.php similarity index 75% rename from tests/phpunit/Process/MutantProcessTest.php rename to tests/phpunit/Process/MutationProcessTest.php index 129e22d0b..30f089376 100644 --- a/tests/phpunit/Process/MutantProcessTest.php +++ b/tests/phpunit/Process/MutationProcessTest.php @@ -35,14 +35,13 @@ namespace Infection\Tests\Process; -use Infection\Mutant\Mutant; use Infection\Mutation\Mutation; -use Infection\Process\MutantProcess; +use Infection\Process\MutationProcess; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Symfony\Component\Process\Process; -final class MutantProcessTest extends TestCase +final class MutationProcessTest extends TestCase { /** * @var MockObject|Process @@ -55,22 +54,22 @@ final class MutantProcessTest extends TestCase private $mutationMock; /** - * @var MutantProcess + * @var MutationProcess */ - private $mutantProcess; + private $mutationProcess; protected function setUp(): void { $this->processMock = $this->createMock(Process::class); $this->mutationMock = $this->createMock(Mutation::class); - $this->mutantProcess = new MutantProcess($this->processMock, $this->mutationMock); + $this->mutationProcess = new MutationProcess($this->processMock, $this->mutationMock); } public function test_it_exposes_its_state(): void { - $this->assertMutantProcessStateIs( - $this->mutantProcess, + $this->assertMutationProcessStateIs( + $this->mutationProcess, $this->processMock, $this->mutationMock, false @@ -79,10 +78,10 @@ public function test_it_exposes_its_state(): void public function test_it_can_be_marked_as_timed_out(): void { - $this->mutantProcess->markAsTimedOut(); + $this->mutationProcess->markAsTimedOut(); - $this->assertMutantProcessStateIs( - $this->mutantProcess, + $this->assertMutationProcessStateIs( + $this->mutationProcess, $this->processMock, $this->mutationMock, true @@ -93,7 +92,7 @@ public function test_it_can_have_a_callback_registered_and_executed(): void { $called = false; - $this->mutantProcess->registerTerminateProcessClosure( + $this->mutationProcess->registerTerminateProcessClosure( static function () use (&$called): void { $called = true; } @@ -101,19 +100,19 @@ static function () use (&$called): void { $this->assertFalse($called); - $this->mutantProcess->terminateProcess(); + $this->mutationProcess->terminateProcess(); $this->assertTrue($called); } - private function assertMutantProcessStateIs( - MutantProcess $mutantProcess, + private function assertMutationProcessStateIs( + MutationProcess $mutationProcess, Process $expectedProcess, - Mutation $expectedMutant, + Mutation $expectedMutation, bool $expectedTimedOut ): void { - $this->assertSame($expectedProcess, $mutantProcess->getProcess()); - $this->assertSame($expectedMutant, $mutantProcess->getMutation()); - $this->assertSame($expectedTimedOut, $mutantProcess->isTimedOut()); + $this->assertSame($expectedProcess, $mutationProcess->getProcess()); + $this->assertSame($expectedMutation, $mutationProcess->getMutation()); + $this->assertSame($expectedTimedOut, $mutationProcess->isTimedOut()); } } diff --git a/tests/phpunit/Process/Runner/MutationTestingRunnerTest.php b/tests/phpunit/Process/Runner/MutationTestingRunnerTest.php index a03a3dc57..1db99df08 100644 --- a/tests/phpunit/Process/Runner/MutationTestingRunnerTest.php +++ b/tests/phpunit/Process/Runner/MutationTestingRunnerTest.php @@ -43,13 +43,12 @@ use Infection\AbstractTestFramework\Coverage\TestLocation; use Infection\Event\MutationTestingWasFinished; use Infection\Event\MutationTestingWasStarted; -use Infection\Mutant\Mutant; use Infection\Mutation\Mutation; use Infection\Mutation\MutationFactory; use Infection\Mutator\ZeroIteration\For_; use Infection\PhpParser\MutatedNode; -use Infection\Process\Builder\MutantProcessFactory; -use Infection\Process\MutantProcess; +use Infection\Process\Builder\MutationProcessFactory; +use Infection\Process\MutationProcess; use Infection\Process\Runner\MutationTestingRunner; use Infection\Process\Runner\ProcessRunner; use Infection\Tests\Fixtures\Event\EventDispatcherCollector; @@ -68,14 +67,14 @@ final class MutationTestingRunnerTest extends TestCase { /** - * @var MutantProcessFactory|MockObject + * @var MutationProcessFactory|MockObject */ private $processFactoryMock; /** * @var \Infection\Mutation\MutationFactory|MockObject */ - private $mutantFactoryMock; + private $mutationFactoryMock; /** * @var ProcessRunner|MockObject @@ -99,15 +98,15 @@ final class MutationTestingRunnerTest extends TestCase protected function setUp(): void { - $this->processFactoryMock = $this->createMock(MutantProcessFactory::class); - $this->mutantFactoryMock = $this->createMock(MutationFactory::class); + $this->processFactoryMock = $this->createMock(MutationProcessFactory::class); + $this->mutationFactoryMock = $this->createMock(MutationFactory::class); $this->processRunnerMock = $this->createMock(ProcessRunner::class); $this->eventDispatcher = new EventDispatcherCollector(); $this->fileSystemMock = $this->createMock(Filesystem::class); $this->runner = new MutationTestingRunner( $this->processFactoryMock, - $this->mutantFactoryMock, + $this->mutationFactoryMock, $this->processRunnerMock, $this->eventDispatcher, $this->fileSystemMock, @@ -145,7 +144,7 @@ public function test_it_applies_and_run_the_mutations(): void ]; $testFrameworkExtraOptions = '--filter=acme/FooTest.php'; - $this->mutantFactoryMock + $this->mutationFactoryMock ->method('create') ->withConsecutive( [$mutation0], @@ -214,7 +213,7 @@ public function test_it_applies_and_run_the_mutations_when_concurrent_execution_ $testFrameworkExtraOptions = '--filter=acme/FooTest.php'; - $this->mutantFactoryMock + $this->mutationFactoryMock ->method('create') ->withConsecutive( [$mutation0], @@ -265,7 +264,7 @@ public function test_it_applies_and_run_the_mutations_when_concurrent_execution_ $this->runner = new MutationTestingRunner( $this->processFactoryMock, - $this->mutantFactoryMock, + $this->mutationFactoryMock, $this->processRunnerMock, $this->eventDispatcher, $this->fileSystemMock, @@ -291,7 +290,7 @@ public function test_it_passes_through_iterables_when_concurrent_execution_reque ->method($this->anything()) ; - $this->mutantFactoryMock + $this->mutationFactoryMock ->expects($this->never()) ->method($this->anything()) ; @@ -309,7 +308,7 @@ public function test_it_passes_through_iterables_when_concurrent_execution_reque $this->runner = new MutationTestingRunner( $this->processFactoryMock, - $this->mutantFactoryMock, + $this->mutationFactoryMock, $this->processRunnerMock, $this->eventDispatcher, $this->fileSystemMock, @@ -329,7 +328,7 @@ public function test_it_dispatches_events_even_when_no_mutations_is_given(): voi ->method($this->anything()) ; - $this->mutantFactoryMock + $this->mutationFactoryMock ->expects($this->never()) ->method($this->anything()) ; @@ -429,9 +428,9 @@ private function formatExpectedEvents(array $events): string ); } - private function buildCoveredMutantProcess(): MutantProcess + private function buildCoveredMutantProcess(): MutationProcess { - $mutantProcess = $this->createMock(MutantProcess::class); + $mutantProcess = $this->createMock(MutationProcess::class); $mutantProcess ->expects($this->never()) ->method('getMutant') diff --git a/tests/phpunit/TestFramework/TestFrameworkExtraOptionsFilterTest.php b/tests/phpunit/TestFramework/TestFrameworkExtraOptionsFilterTest.php index deb4e8822..c8bef4cbb 100644 --- a/tests/phpunit/TestFramework/TestFrameworkExtraOptionsFilterTest.php +++ b/tests/phpunit/TestFramework/TestFrameworkExtraOptionsFilterTest.php @@ -41,18 +41,19 @@ final class TestFrameworkExtraOptionsFilterTest extends TestCase { /** - * @dataProvider mutantProcessProvider + * @dataProvider mutationProcessProvider */ - public function test_it_skips_filter_for_mutant_process(string $actualExtraOptions, string $expectedExtraOptions): void + public function test_it_skips_filter_for_mutation_process(string $actualExtraOptions, string $expectedExtraOptions): void { - $filter = new TestFrameworkExtraOptionsFilter(); - - $filteredOptions = $filter->filterForMutantProcess($actualExtraOptions, ['--configuration', '--filter', '--testsuite']); + $filteredOptions = (new TestFrameworkExtraOptionsFilter())->filterForMutationProcess( + $actualExtraOptions, + ['--configuration', '--filter', '--testsuite'] + ); $this->assertSame($expectedExtraOptions, $filteredOptions); } - public function mutantProcessProvider(): iterable + public function mutationProcessProvider(): iterable { yield ['--filter=someTest#2 --a --b=value', '--a --b=value']; From 581b6a226816b509d77a43ec8ebf3758240b92be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20FIDRY?= Date: Wed, 25 Mar 2020 12:18:56 +0100 Subject: [PATCH 06/21] Fix CS --- src/Console/OutputFormatter/DotFormatter.php | 2 +- src/Container.php | 12 +++---- ...MutationTestingConsoleLoggerSubscriber.php | 5 ++- src/Logger/DebugFileLogger.php | 4 +-- src/Logger/TextFileLogger.php | 8 ++--- src/Mutation/MutationExecutionResult.php | 2 +- .../MutationExecutionResultFactory.php | 2 +- .../Builder/MutationProcessFactory.php | 2 +- src/Process/Runner/MutationTestingRunner.php | 2 +- .../Config/MutationConfigBuilder.php | 3 +- .../TestFrameworkExtraOptionsFilter.php | 3 +- .../ProjectCode/ProjectCodeProvider.php | 10 +++--- .../OutputFormatter/DotFormatterTest.php | 4 +-- .../Logger/CreateMetricsCalculator.php | 2 +- .../phpunit/Metrics/MetricsCalculatorTest.php | 2 +- tests/phpunit/Mutation/MutationAssertions.php | 9 ------ .../Mutation/MutationCalculatedStateTest.php | 31 +++++++++++++++++++ .../phpunit/Mutation/MutationFactoryTest.php | 2 +- tests/phpunit/Mutation/MutationTest.php | 7 +---- .../PhpParser/Visitor/MutatorVisitorTest.php | 1 - .../Builder/MutationProcessFactoryTest.php | 4 +-- 21 files changed, 65 insertions(+), 52 deletions(-) diff --git a/src/Console/OutputFormatter/DotFormatter.php b/src/Console/OutputFormatter/DotFormatter.php index 36aaf63a0..2e87f670f 100644 --- a/src/Console/OutputFormatter/DotFormatter.php +++ b/src/Console/OutputFormatter/DotFormatter.php @@ -37,10 +37,10 @@ use Infection\Mutation\DetectionStatus; use Infection\Mutation\MutationExecutionResult; -use Symfony\Component\Console\Output\OutputInterface; use function Safe\sprintf; use function str_repeat; use function strlen; +use Symfony\Component\Console\Output\OutputInterface; /** * @internal diff --git a/src/Container.php b/src/Container.php index 31f790ace..13fe11938 100644 --- a/src/Container.php +++ b/src/Container.php @@ -35,6 +35,8 @@ namespace Infection; +use function array_filter; +use function array_key_exists; use Closure; use Infection\AbstractTestFramework\TestFrameworkAdapter; use Infection\Configuration\Configuration; @@ -61,8 +63,8 @@ use Infection\Metrics\MetricsCalculator; use Infection\Metrics\MinMsiChecker; use Infection\Mutation\FileMutationGenerator; -use Infection\Mutation\MutationCodeFactory; use Infection\Mutation\Mutation; +use Infection\Mutation\MutationCodeFactory; use Infection\Mutation\MutationExecutionResultFactory; use Infection\Mutation\MutationFactory; use Infection\Mutation\MutationGenerator; @@ -102,21 +104,19 @@ use Infection\TestFramework\Factory; use Infection\TestFramework\TestFrameworkExtraOptionsFilter; use InvalidArgumentException; +use function php_ini_loaded_file; use PhpParser\Lexer; use PhpParser\Parser; use PhpParser\ParserFactory; use PhpParser\PrettyPrinter\Standard; use PhpParser\PrettyPrinterAbstract; +use function Safe\getcwd; +use function Safe\sprintf; use SebastianBergmann\Diff\Differ as BaseDiffer; use Symfony\Component\Console\Helper\QuestionHelper; use Symfony\Component\Filesystem\Filesystem; use Webmozart\Assert\Assert; use Webmozart\PathUtil\Path; -use function array_filter; -use function array_key_exists; -use function php_ini_loaded_file; -use function Safe\getcwd; -use function Safe\sprintf; /** * @internal diff --git a/src/Event/Subscriber/MutationTestingConsoleLoggerSubscriber.php b/src/Event/Subscriber/MutationTestingConsoleLoggerSubscriber.php index 8c6318258..51067b1cd 100644 --- a/src/Event/Subscriber/MutationTestingConsoleLoggerSubscriber.php +++ b/src/Event/Subscriber/MutationTestingConsoleLoggerSubscriber.php @@ -35,19 +35,18 @@ namespace Infection\Event\Subscriber; +use function floor; use Infection\Console\OutputFormatter\OutputFormatter; use Infection\Differ\DiffColorizer; use Infection\Event\MutationProcessWasFinished; use Infection\Event\MutationTestingWasFinished; use Infection\Event\MutationTestingWasStarted; use Infection\Metrics\MetricsCalculator; -use Infection\Mutation\MutationExecutionResult; -use Symfony\Component\Console\Output\OutputInterface; -use function floor; use function Safe\sprintf; use function str_pad; use function str_repeat; use function strlen; +use Symfony\Component\Console\Output\OutputInterface; /** * @internal diff --git a/src/Logger/DebugFileLogger.php b/src/Logger/DebugFileLogger.php index 2553bf84f..15aec3e97 100644 --- a/src/Logger/DebugFileLogger.php +++ b/src/Logger/DebugFileLogger.php @@ -35,13 +35,13 @@ namespace Infection\Logger; +use function implode; use Infection\Metrics\MetricsCalculator; use Infection\Mutation\MutationExecutionResult; -use function implode; +use const PHP_EOL; use function Safe\sprintf; use function str_repeat; use function strlen; -use const PHP_EOL; /** * Simple loggers recording the mutation names and original first line. This is mostly intended for diff --git a/src/Logger/TextFileLogger.php b/src/Logger/TextFileLogger.php index 3e9530c5a..7c2f2d347 100644 --- a/src/Logger/TextFileLogger.php +++ b/src/Logger/TextFileLogger.php @@ -35,16 +35,16 @@ namespace Infection\Logger; -use Infection\Metrics\MetricsCalculator; -use Infection\Mutation\MutationExecutionResult; -use Infection\Str; use function array_map; use function explode; use function implode; +use Infection\Metrics\MetricsCalculator; +use Infection\Mutation\MutationExecutionResult; +use Infection\Str; +use const PHP_EOL; use function Safe\sprintf; use function str_repeat; use function strlen; -use const PHP_EOL; /** * @internal diff --git a/src/Mutation/MutationExecutionResult.php b/src/Mutation/MutationExecutionResult.php index f5d2a5353..3a4caafd7 100644 --- a/src/Mutation/MutationExecutionResult.php +++ b/src/Mutation/MutationExecutionResult.php @@ -35,9 +35,9 @@ namespace Infection\Mutation; +use function array_keys; use Infection\Mutator\ProfileList; use Webmozart\Assert\Assert; -use function array_keys; /** * @internal diff --git a/src/Mutation/MutationExecutionResultFactory.php b/src/Mutation/MutationExecutionResultFactory.php index facc6c26a..b81112650 100644 --- a/src/Mutation/MutationExecutionResultFactory.php +++ b/src/Mutation/MutationExecutionResultFactory.php @@ -37,9 +37,9 @@ use Infection\AbstractTestFramework\TestFrameworkAdapter; use Infection\Process\MutationProcess; +use function Safe\sprintf; use Symfony\Component\Process\Process; use Webmozart\Assert\Assert; -use function Safe\sprintf; /** * @internal diff --git a/src/Process/Builder/MutationProcessFactory.php b/src/Process/Builder/MutationProcessFactory.php index 39d908c91..975fc4942 100644 --- a/src/Process/Builder/MutationProcessFactory.php +++ b/src/Process/Builder/MutationProcessFactory.php @@ -41,8 +41,8 @@ use Infection\Mutation\Mutation; use Infection\Mutation\MutationExecutionResultFactory; use Infection\Process\MutationProcess; -use Symfony\Component\Process\Process; use function method_exists; +use Symfony\Component\Process\Process; /** * @internal diff --git a/src/Process/Runner/MutationTestingRunner.php b/src/Process/Runner/MutationTestingRunner.php index 3dc36990c..7765b0ba3 100644 --- a/src/Process/Runner/MutationTestingRunner.php +++ b/src/Process/Runner/MutationTestingRunner.php @@ -43,8 +43,8 @@ use Infection\Mutation\Mutation; use Infection\Mutation\MutationExecutionResult; use Infection\Process\Builder\MutationProcessFactory; -use Symfony\Component\Filesystem\Filesystem; use function Pipeline\take; +use Symfony\Component\Filesystem\Filesystem; /** * @internal diff --git a/src/TestFramework/Config/MutationConfigBuilder.php b/src/TestFramework/Config/MutationConfigBuilder.php index 027314a62..1cb9cffe4 100644 --- a/src/TestFramework/Config/MutationConfigBuilder.php +++ b/src/TestFramework/Config/MutationConfigBuilder.php @@ -62,8 +62,7 @@ protected function getInterceptorFileContent( string $interceptorPath, string $originalFilePath, string $mutationFilePath - ): string - { + ): string { $infectionPhar = ''; if (strpos(__FILE__, 'phar:') === 0) { diff --git a/src/TestFramework/TestFrameworkExtraOptionsFilter.php b/src/TestFramework/TestFrameworkExtraOptionsFilter.php index 6d286c182..79b6b6088 100644 --- a/src/TestFramework/TestFrameworkExtraOptionsFilter.php +++ b/src/TestFramework/TestFrameworkExtraOptionsFilter.php @@ -51,8 +51,7 @@ final class TestFrameworkExtraOptionsFilter public function filterForMutationProcess( string $actualExtraOptions, array $initialRunOnlyOptions - ): string - { + ): string { foreach ($initialRunOnlyOptions as $initialRunOnlyOption) { $actualExtraOptions = preg_replace( sprintf('/%s[\=| ](?:\"[^\"]*\"|\'[^\']*\'|[^\ ]*)/', $initialRunOnlyOption), diff --git a/tests/phpunit/AutoReview/ProjectCode/ProjectCodeProvider.php b/tests/phpunit/AutoReview/ProjectCode/ProjectCodeProvider.php index 690884ecc..7027d713b 100644 --- a/tests/phpunit/AutoReview/ProjectCode/ProjectCodeProvider.php +++ b/tests/phpunit/AutoReview/ProjectCode/ProjectCodeProvider.php @@ -35,6 +35,8 @@ namespace Infection\Tests\AutoReview\ProjectCode; +use const DIRECTORY_SEPARATOR; +use function in_array; use Infection\CannotBeInstantiated; use Infection\Command\ConfigureCommand; use Infection\Command\RunCommand; @@ -69,16 +71,14 @@ use Infection\TestFramework\PhpUnit\Config\Builder\MutationConfigBuilder as PhpUnitMutationConfigBuilder; use Infection\TestFramework\TestFrameworkTypes; use Infection\Tests\AutoReview\ConcreteClassReflector; -use ReflectionClass; -use Symfony\Component\Finder\Finder; -use Symfony\Component\Finder\SplFileInfo; -use function in_array; use function Infection\Tests\generator_to_phpunit_data_provider; use function iterator_to_array; +use ReflectionClass; use function Safe\sort; use function Safe\sprintf; -use const DIRECTORY_SEPARATOR; use const SORT_STRING; +use Symfony\Component\Finder\Finder; +use Symfony\Component\Finder\SplFileInfo; final class ProjectCodeProvider { diff --git a/tests/phpunit/Console/OutputFormatter/DotFormatterTest.php b/tests/phpunit/Console/OutputFormatter/DotFormatterTest.php index 22477af83..0eeb18186 100644 --- a/tests/phpunit/Console/OutputFormatter/DotFormatterTest.php +++ b/tests/phpunit/Console/OutputFormatter/DotFormatterTest.php @@ -38,11 +38,11 @@ use Infection\Console\OutputFormatter\DotFormatter; use Infection\Mutation\DetectionStatus; use Infection\Mutation\MutationExecutionResult; +use const PHP_EOL; use PHPUnit\Framework\TestCase; +use function strip_tags; use Symfony\Component\Console\Output\BufferedOutput; use Symfony\Component\Console\Output\OutputInterface; -use function strip_tags; -use const PHP_EOL; final class DotFormatterTest extends TestCase { diff --git a/tests/phpunit/Logger/CreateMetricsCalculator.php b/tests/phpunit/Logger/CreateMetricsCalculator.php index 00bb2c815..b3be8c615 100644 --- a/tests/phpunit/Logger/CreateMetricsCalculator.php +++ b/tests/phpunit/Logger/CreateMetricsCalculator.php @@ -41,8 +41,8 @@ use Infection\Mutator\Regex\PregQuote; use Infection\Mutator\ZeroIteration\For_; use Infection\Tests\Mutator\MutatorName; -use function str_replace; use const PHP_EOL; +use function str_replace; trait CreateMetricsCalculator { diff --git a/tests/phpunit/Metrics/MetricsCalculatorTest.php b/tests/phpunit/Metrics/MetricsCalculatorTest.php index 3c661ed65..5c528ee33 100644 --- a/tests/phpunit/Metrics/MetricsCalculatorTest.php +++ b/tests/phpunit/Metrics/MetricsCalculatorTest.php @@ -35,13 +35,13 @@ namespace Infection\Tests\Metrics; +use function array_merge; use Infection\Metrics\MetricsCalculator; use Infection\Mutation\DetectionStatus; use Infection\Mutation\MutationExecutionResult; use Infection\Mutator\ZeroIteration\For_; use Infection\Tests\Mutator\MutatorName; use PHPUnit\Framework\TestCase; -use function array_merge; final class MetricsCalculatorTest extends TestCase { diff --git a/tests/phpunit/Mutation/MutationAssertions.php b/tests/phpunit/Mutation/MutationAssertions.php index eb462e319..a2d1473b3 100644 --- a/tests/phpunit/Mutation/MutationAssertions.php +++ b/tests/phpunit/Mutation/MutationAssertions.php @@ -35,16 +35,7 @@ namespace Infection\Tests\Mutation; -use Infection\Mutation\MutationCalculatedState; -use function array_merge; -use Infection\AbstractTestFramework\Coverage\TestLocation; use Infection\Mutation\Mutation; -use Infection\Mutator\Arithmetic\Plus; -use Infection\PhpParser\MutatedNode; -use Infection\Tests\Mutator\MutatorName; -use function md5; -use PhpParser\Node; -use PHPUnit\Framework\TestCase; trait MutationAssertions { diff --git a/tests/phpunit/Mutation/MutationCalculatedStateTest.php b/tests/phpunit/Mutation/MutationCalculatedStateTest.php index 476f91e47..fd8a95b5f 100644 --- a/tests/phpunit/Mutation/MutationCalculatedStateTest.php +++ b/tests/phpunit/Mutation/MutationCalculatedStateTest.php @@ -1,4 +1,35 @@ $attributes - * @param array $expectedAttributes * @param TestLocation[] $tests */ public function test_it_can_be_instantiated( diff --git a/tests/phpunit/PhpParser/Visitor/MutatorVisitorTest.php b/tests/phpunit/PhpParser/Visitor/MutatorVisitorTest.php index 55a8fef81..fe81f781e 100644 --- a/tests/phpunit/PhpParser/Visitor/MutatorVisitorTest.php +++ b/tests/phpunit/PhpParser/Visitor/MutatorVisitorTest.php @@ -35,7 +35,6 @@ namespace Infection\Tests\PhpParser\Visitor; -use Infection\Mutation\Mutation; use Infection\Mutator\FunctionSignature\PublicVisibility; use Infection\PhpParser\MutatedNode; use Infection\PhpParser\Visitor\MutatorVisitor; diff --git a/tests/phpunit/Process/Builder/MutationProcessFactoryTest.php b/tests/phpunit/Process/Builder/MutationProcessFactoryTest.php index d2b7856f2..4eda4d1fc 100644 --- a/tests/phpunit/Process/Builder/MutationProcessFactoryTest.php +++ b/tests/phpunit/Process/Builder/MutationProcessFactoryTest.php @@ -35,6 +35,7 @@ namespace Infection\Tests\Process\Builder; +use function current; use Infection\AbstractTestFramework\Coverage\TestLocation; use Infection\AbstractTestFramework\TestFrameworkAdapter; use Infection\Event\MutationProcessWasFinished; @@ -46,9 +47,8 @@ use Infection\Process\Builder\MutationProcessFactory; use Infection\Tests\Fixtures\Event\EventDispatcherCollector; use Infection\Tests\Mutator\MutatorName; -use PHPUnit\Framework\TestCase; -use function current; use const PHP_OS_FAMILY; +use PHPUnit\Framework\TestCase; final class MutationProcessFactoryTest extends TestCase { From c163e116c5762d74a15ccb1b6f6a568104b81541 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20FIDRY?= Date: Wed, 25 Mar 2020 12:25:45 +0100 Subject: [PATCH 07/21] Simplify FQCN --- .../Subscriber/MutationTestingConsoleLoggerSubscriber.php | 5 +++-- src/Logger/TextFileLogger.php | 2 +- src/Metrics/SortableMutationExecutionResults.php | 6 +++--- tests/phpunit/Metrics/MetricsCalculatorTest.php | 2 +- tests/phpunit/Mutation/MutationCodeFactoryTest.php | 3 ++- .../phpunit/Mutation/MutationExecutionResultAssertions.php | 4 +++- .../Mutation/MutationExecutionResultFactoryTest.php | 6 +++--- tests/phpunit/Mutation/MutationExecutionResultTest.php | 7 ++++--- tests/phpunit/Mutation/MutationFactoryTest.php | 2 +- tests/phpunit/Process/Runner/MutationTestingRunnerTest.php | 2 +- 10 files changed, 22 insertions(+), 17 deletions(-) diff --git a/src/Event/Subscriber/MutationTestingConsoleLoggerSubscriber.php b/src/Event/Subscriber/MutationTestingConsoleLoggerSubscriber.php index 51067b1cd..532dce38d 100644 --- a/src/Event/Subscriber/MutationTestingConsoleLoggerSubscriber.php +++ b/src/Event/Subscriber/MutationTestingConsoleLoggerSubscriber.php @@ -35,6 +35,7 @@ namespace Infection\Event\Subscriber; +use Infection\Mutation\MutationExecutionResult; use function floor; use Infection\Console\OutputFormatter\OutputFormatter; use Infection\Differ\DiffColorizer; @@ -87,7 +88,7 @@ public function onMutationTestingWasStarted(MutationTestingWasStarted $event): v $this->outputFormatter->start($this->mutationCount); } - public function onMutantProcessWasFinished(MutationProcessWasFinished $event): void + public function onMutationProcessWasFinished(MutationProcessWasFinished $event): void { $executionResult = $event->getExecutionResult(); @@ -112,7 +113,7 @@ public function onMutationTestingWasFinished(MutationTestingWasFinished $event): } /** - * @param \Infection\Mutation\MutationExecutionResult[] $executionResults + * @param MutationExecutionResult[] $executionResults */ private function showMutations(array $executionResults, string $headlinePrefix): void { diff --git a/src/Logger/TextFileLogger.php b/src/Logger/TextFileLogger.php index 7c2f2d347..e12c29712 100644 --- a/src/Logger/TextFileLogger.php +++ b/src/Logger/TextFileLogger.php @@ -112,7 +112,7 @@ public function getLogLines(): array } /** - * @param \Infection\Mutation\MutationExecutionResult[] $executionResults + * @param MutationExecutionResult[] $executionResults */ private function getResultsLine( array $executionResults, diff --git a/src/Metrics/SortableMutationExecutionResults.php b/src/Metrics/SortableMutationExecutionResults.php index 731e28e96..1db92ff6c 100644 --- a/src/Metrics/SortableMutationExecutionResults.php +++ b/src/Metrics/SortableMutationExecutionResults.php @@ -44,7 +44,7 @@ final class SortableMutationExecutionResults { /** - * @var \Infection\Mutation\MutationExecutionResult[] + * @var MutationExecutionResult[] */ private $executionResults = []; @@ -60,7 +60,7 @@ public function add(MutationExecutionResult $executionResult): void } /** - * @return \Infection\Mutation\MutationExecutionResult[] + * @return MutationExecutionResult[] */ public function getSortedExecutionResults(): array { @@ -73,7 +73,7 @@ public function getSortedExecutionResults(): array } /** - * @param \Infection\Mutation\MutationExecutionResult[] $executionResults + * @param MutationExecutionResult[] $executionResults */ private static function sortResults(array &$executionResults): void { diff --git a/tests/phpunit/Metrics/MetricsCalculatorTest.php b/tests/phpunit/Metrics/MetricsCalculatorTest.php index 5c528ee33..89067e61d 100644 --- a/tests/phpunit/Metrics/MetricsCalculatorTest.php +++ b/tests/phpunit/Metrics/MetricsCalculatorTest.php @@ -154,7 +154,7 @@ public function test_its_metrics_are_properly_updated_when_adding_a_new_process( } /** - * @return \Infection\Mutation\MutationExecutionResult[] + * @return MutationExecutionResult[] */ private function addMutationExecutionResult( MetricsCalculator $calculator, diff --git a/tests/phpunit/Mutation/MutationCodeFactoryTest.php b/tests/phpunit/Mutation/MutationCodeFactoryTest.php index e2da0fc86..b5a658d92 100644 --- a/tests/phpunit/Mutation/MutationCodeFactoryTest.php +++ b/tests/phpunit/Mutation/MutationCodeFactoryTest.php @@ -35,6 +35,7 @@ namespace Infection\Tests\Mutation; +use Infection\Mutation\MutationCodeFactory; use Infection\PhpParser\MutatedNode; use Infection\Tests\SingletonContainer; use PhpParser\Node; @@ -43,7 +44,7 @@ final class MutationCodeFactoryTest extends TestCase { /** - * @var \Infection\Mutation\MutationCodeFactory + * @var MutationCodeFactory */ private $codeFactory; diff --git a/tests/phpunit/Mutation/MutationExecutionResultAssertions.php b/tests/phpunit/Mutation/MutationExecutionResultAssertions.php index 48d04cfd0..3f67d41b0 100644 --- a/tests/phpunit/Mutation/MutationExecutionResultAssertions.php +++ b/tests/phpunit/Mutation/MutationExecutionResultAssertions.php @@ -35,10 +35,12 @@ namespace Infection\Tests\Mutation; +use Infection\Mutation\MutationExecutionResult; + trait MutationExecutionResultAssertions { private function assertResultStateIs( - \Infection\Mutation\MutationExecutionResult $result, + MutationExecutionResult $result, string $expectedProcessCommandLine, string $expectedProcessOutput, string $expectedDetectionStatus, diff --git a/tests/phpunit/Mutation/MutationExecutionResultFactoryTest.php b/tests/phpunit/Mutation/MutationExecutionResultFactoryTest.php index bad99c03d..c0f82a338 100644 --- a/tests/phpunit/Mutation/MutationExecutionResultFactoryTest.php +++ b/tests/phpunit/Mutation/MutationExecutionResultFactoryTest.php @@ -58,7 +58,7 @@ final class MutationExecutionResultFactoryTest extends TestCase private $testFrameworkAdapterMock; /** - * @var \Infection\Mutation\MutationExecutionResultFactory + * @var MutationExecutionResultFactory */ private $resultFactory; @@ -131,7 +131,7 @@ static function () use ($mutationDiff): MutationCalculatedState { $this->resultFactory->createFromProcess($mutationProcess), $processCommandLine, $processOutput, - \Infection\Mutation\DetectionStatus::NOT_COVERED, + DetectionStatus::NOT_COVERED, $mutationDiff, $mutatorName, $originalFilePath, @@ -209,7 +209,7 @@ static function () use ($mutationDiff): MutationCalculatedState { $this->resultFactory->createFromProcess($mutationProcess), $processCommandLine, $processOutput, - \Infection\Mutation\DetectionStatus::TIMED_OUT, + DetectionStatus::TIMED_OUT, $mutationDiff, $mutatorName, $originalFilePath, diff --git a/tests/phpunit/Mutation/MutationExecutionResultTest.php b/tests/phpunit/Mutation/MutationExecutionResultTest.php index 8cdcb7793..b6f625ca2 100644 --- a/tests/phpunit/Mutation/MutationExecutionResultTest.php +++ b/tests/phpunit/Mutation/MutationExecutionResultTest.php @@ -36,6 +36,7 @@ namespace Infection\Tests\Mutation; use Infection\AbstractTestFramework\Coverage\TestLocation; +use Infection\Mutation\DetectionStatus; use Infection\Mutation\Mutation; use Infection\Mutation\MutationCalculatedState; use Infection\Mutation\MutationExecutionResult; @@ -49,7 +50,7 @@ public function test_it_can_be_instantiated(): void { $processCommandLine = 'bin/phpunit --configuration infection-tmp-phpunit.xml --filter "tests/Acme/FooTest.php"'; $processOutput = 'Passed!'; - $processResultCode = \Infection\Mutation\DetectionStatus::ESCAPED; + $processResultCode = DetectionStatus::ESCAPED; $mutationDiff = <<<'DIFF' --- Original +++ New @@ -64,7 +65,7 @@ public function test_it_can_be_instantiated(): void $originalFilePath = 'path/to/Foo.php'; $originalStartingLine = 10; - $result = new \Infection\Mutation\MutationExecutionResult( + $result = new MutationExecutionResult( $processCommandLine, $processOutput, $processResultCode, @@ -130,7 +131,7 @@ static function () use ($mutationDiff): MutationCalculatedState { MutationExecutionResult::createFromNonCoveredMutation($mutation), '', '', - \Infection\Mutation\DetectionStatus::NOT_COVERED, + DetectionStatus::NOT_COVERED, $mutationDiff, $mutatorName, $originalFilePath, diff --git a/tests/phpunit/Mutation/MutationFactoryTest.php b/tests/phpunit/Mutation/MutationFactoryTest.php index 7359b5ffb..862b243cb 100644 --- a/tests/phpunit/Mutation/MutationFactoryTest.php +++ b/tests/phpunit/Mutation/MutationFactoryTest.php @@ -69,7 +69,7 @@ final class MutationFactoryTest extends TestCase private $differMock; /** - * @var \Infection\Mutation\MutationFactory + * @var MutationFactory */ private $mutationFactory; diff --git a/tests/phpunit/Process/Runner/MutationTestingRunnerTest.php b/tests/phpunit/Process/Runner/MutationTestingRunnerTest.php index 1db99df08..b7e10e5aa 100644 --- a/tests/phpunit/Process/Runner/MutationTestingRunnerTest.php +++ b/tests/phpunit/Process/Runner/MutationTestingRunnerTest.php @@ -72,7 +72,7 @@ final class MutationTestingRunnerTest extends TestCase private $processFactoryMock; /** - * @var \Infection\Mutation\MutationFactory|MockObject + * @var MutationFactory|MockObject */ private $mutationFactoryMock; From c8f4c86ac4f1fea1ef27e0f19ac1336aacdefa3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20FIDRY?= Date: Wed, 25 Mar 2020 12:53:45 +0100 Subject: [PATCH 08/21] Fix some tests --- src/Container.php | 1 - src/Mutation/MutationExecutionResult.php | 2 +- src/Process/Runner/MutationTestingRunner.php | 2 +- .../TestFramework/FakeAwareAdapter.php | 5 +- .../Mutation/MutationExecutionResultTest.php | 4 +- .../phpunit/Mutation/MutationFactoryTest.php | 2 - tests/phpunit/Mutator/MutatorParserTest.php | 9 ++ .../Runner/MutationTestingRunnerTest.php | 122 +++++------------- 8 files changed, 47 insertions(+), 100 deletions(-) diff --git a/src/Container.php b/src/Container.php index 9588b217b..83613c6c2 100644 --- a/src/Container.php +++ b/src/Container.php @@ -450,7 +450,6 @@ public static function create(): self MutationTestingRunner::class => static function (self $container): MutationTestingRunner { return new MutationTestingRunner( $container->getMutationProcessFactory(), - $container->getMutationFactory(), $container->getProcessRunner(), $container->getEventDispatcher(), $container->getConfiguration()->isDryRun() diff --git a/src/Mutation/MutationExecutionResult.php b/src/Mutation/MutationExecutionResult.php index 3a4caafd7..252645a36 100644 --- a/src/Mutation/MutationExecutionResult.php +++ b/src/Mutation/MutationExecutionResult.php @@ -74,7 +74,7 @@ public function __construct( $this->originalStartingLine = $originalStartingLine; } - public static function createFromNonCoveredMutation(Mutation $mutation): self + public static function createFromNonExecutedByTestsMutation(Mutation $mutation): self { return new self( '', diff --git a/src/Process/Runner/MutationTestingRunner.php b/src/Process/Runner/MutationTestingRunner.php index 7765b0ba3..90c6f75de 100644 --- a/src/Process/Runner/MutationTestingRunner.php +++ b/src/Process/Runner/MutationTestingRunner.php @@ -86,7 +86,7 @@ public function run(iterable $mutations, string $testFrameworkExtraOptions): voi } $this->eventDispatcher->dispatch(new MutationProcessWasFinished( - MutationExecutionResult::createFromNonCoveredMutation($mutation) + MutationExecutionResult::createFromNonExecutedByTestsMutation($mutation) )); return false; diff --git a/tests/phpunit/Fixtures/TestFramework/FakeAwareAdapter.php b/tests/phpunit/Fixtures/TestFramework/FakeAwareAdapter.php index 00f2ef2f2..9f3beb58b 100644 --- a/tests/phpunit/Fixtures/TestFramework/FakeAwareAdapter.php +++ b/tests/phpunit/Fixtures/TestFramework/FakeAwareAdapter.php @@ -5,6 +5,7 @@ use ErrorException; use Infection\AbstractTestFramework\MemoryUsageAware; use Infection\TestFramework\AbstractTestFrameworkAdapter; +use Infection\Tests\UnsupportedMethod; class FakeAwareAdapter extends AbstractTestFrameworkAdapter implements MemoryUsageAware { @@ -22,12 +23,12 @@ public function hasJUnitReport(): bool public function testsPass(string $output): bool { - throw new ErrorException('this should never be called'); + throw UnsupportedMethod::method(__CLASS__, __FUNCTION__); } public function getName(): string { - throw new ErrorException('this should never be called'); + throw UnsupportedMethod::method(__CLASS__, __FUNCTION__); } /** diff --git a/tests/phpunit/Mutation/MutationExecutionResultTest.php b/tests/phpunit/Mutation/MutationExecutionResultTest.php index b6f625ca2..d5e5386a9 100644 --- a/tests/phpunit/Mutation/MutationExecutionResultTest.php +++ b/tests/phpunit/Mutation/MutationExecutionResultTest.php @@ -87,7 +87,7 @@ public function test_it_can_be_instantiated(): void ); } - public function test_it_can_be_instantiated_from_a_non_covered_mutation(): void + public function test_it_can_be_instantiated_from_a_mutation_non_executed_by_tests(): void { $mutationDiff = <<<'DIFF' --- Original @@ -128,7 +128,7 @@ static function () use ($mutationDiff): MutationCalculatedState { ); $this->assertResultStateIs( - MutationExecutionResult::createFromNonCoveredMutation($mutation), + MutationExecutionResult::createFromNonExecutedByTestsMutation($mutation), '', '', DetectionStatus::NOT_COVERED, diff --git a/tests/phpunit/Mutation/MutationFactoryTest.php b/tests/phpunit/Mutation/MutationFactoryTest.php index 862b243cb..9b7fc058f 100644 --- a/tests/phpunit/Mutation/MutationFactoryTest.php +++ b/tests/phpunit/Mutation/MutationFactoryTest.php @@ -78,9 +78,7 @@ protected function setUp(): void parent::setUp(); $this->codeFactoryMock = $this->createMock(MutationCodeFactory::class); - $this->printerMock = $this->createMock(PrettyPrinterAbstract::class); - $this->differMock = $this->createMock(Differ::class); $this->mutationFactory = new MutationFactory( diff --git a/tests/phpunit/Mutator/MutatorParserTest.php b/tests/phpunit/Mutator/MutatorParserTest.php index ef7175ff4..b64ecc038 100644 --- a/tests/phpunit/Mutator/MutatorParserTest.php +++ b/tests/phpunit/Mutator/MutatorParserTest.php @@ -37,6 +37,7 @@ use Infection\Mutator\MutatorParser; use PHPUnit\Framework\TestCase; +use UnexpectedValueException; final class MutatorParserTest extends TestCase { @@ -64,6 +65,14 @@ public function test_it_can_parse_the_provided_input( $this->assertSame($expectedMutators, $parsedMutators); } + public function test_it_cannot_parse_unknown_mutator(): void + { + $this->expectException(UnexpectedValueException::class); + $this->expectExceptionMessage('Expected "Unknown" to be a known mutator or profile. See "https://infection.github.io/guide/mutators.html" and "https://infection.github.io/guide/profiles.html" for the list of available mutations and profiles.'); + + $this->mutatorParser->parse('Unknown'); + } + public function mutatorInputProvider(): iterable { yield 'empty string' => ['', []]; diff --git a/tests/phpunit/Process/Runner/MutationTestingRunnerTest.php b/tests/phpunit/Process/Runner/MutationTestingRunnerTest.php index b7e10e5aa..1c50fc247 100644 --- a/tests/phpunit/Process/Runner/MutationTestingRunnerTest.php +++ b/tests/phpunit/Process/Runner/MutationTestingRunnerTest.php @@ -44,9 +44,8 @@ use Infection\Event\MutationTestingWasFinished; use Infection\Event\MutationTestingWasStarted; use Infection\Mutation\Mutation; -use Infection\Mutation\MutationFactory; +use Infection\Mutation\MutationCalculatedState; use Infection\Mutator\ZeroIteration\For_; -use Infection\PhpParser\MutatedNode; use Infection\Process\Builder\MutationProcessFactory; use Infection\Process\MutationProcess; use Infection\Process\Runner\MutationTestingRunner; @@ -54,12 +53,12 @@ use Infection\Tests\Fixtures\Event\EventDispatcherCollector; use Infection\Tests\Mutator\MutatorName; use Iterator; -use PhpParser\Node\Stmt\Nop; use PHPUnit\Framework\Constraint\Callback; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use function Safe\sprintf; use Symfony\Component\Filesystem\Filesystem; +use Symfony\Component\Process\Process; /** * @group integration @@ -71,11 +70,6 @@ final class MutationTestingRunnerTest extends TestCase */ private $processFactoryMock; - /** - * @var MutationFactory|MockObject - */ - private $mutationFactoryMock; - /** * @var ProcessRunner|MockObject */ @@ -99,14 +93,12 @@ final class MutationTestingRunnerTest extends TestCase protected function setUp(): void { $this->processFactoryMock = $this->createMock(MutationProcessFactory::class); - $this->mutationFactoryMock = $this->createMock(MutationFactory::class); $this->processRunnerMock = $this->createMock(ProcessRunner::class); $this->eventDispatcher = new EventDispatcherCollector(); $this->fileSystemMock = $this->createMock(Filesystem::class); $this->runner = new MutationTestingRunner( $this->processFactoryMock, - $this->mutationFactoryMock, $this->processRunnerMock, $this->eventDispatcher, $this->fileSystemMock, @@ -144,46 +136,24 @@ public function test_it_applies_and_run_the_mutations(): void ]; $testFrameworkExtraOptions = '--filter=acme/FooTest.php'; - $this->mutationFactoryMock - ->method('create') - ->withConsecutive( - [$mutation0], - [$mutation1] - ) - ->willReturnOnConsecutiveCalls( - $mutant0 = new Mutant( - '/path/to/mutant0', - $mutation0, - 'mutated code 0', - 'diff0' - ), - $mutant1 = new Mutant( - '/path/to/mutant1', - $mutation1, - 'mutated code 1', - 'diff1' - ) - ) - ; - $this->fileSystemMock ->expects($this->exactly(2)) ->method('dumpFile') ->withConsecutive( - ['/path/to/mutant0', 'mutated code 0'], - ['/path/to/mutant1', 'mutated code 1'] + ['/path/to/mutation0.php', 'mutated code 0'], + ['/path/to/mutation1.php', 'mutated code 1'] ) ; $this->processFactoryMock - ->method('createProcessForMutant') + ->method('createProcessForMutation') ->withConsecutive( - [$mutant0, $testFrameworkExtraOptions], - [$mutant1, $testFrameworkExtraOptions] + [$mutation0, $testFrameworkExtraOptions], + [$mutation1, $testFrameworkExtraOptions] ) ->willReturnOnConsecutiveCalls( - $process0 = $this->buildCoveredMutantProcess(), - $process1 = $this->buildCoveredMutantProcess() + $process0 = $this->buildCoveredMutationProcess($mutation0), + $process1 = $this->buildCoveredMutationProcess($mutation1) ) ; @@ -213,58 +183,35 @@ public function test_it_applies_and_run_the_mutations_when_concurrent_execution_ $testFrameworkExtraOptions = '--filter=acme/FooTest.php'; - $this->mutationFactoryMock - ->method('create') - ->withConsecutive( - [$mutation0], - [$mutation1] - ) - ->willReturnOnConsecutiveCalls( - $mutant0 = new Mutant( - '/path/to/mutant0', - $mutation0, - 'mutated code 0', - 'diff0' - ), - $mutant1 = new Mutant( - '/path/to/mutant1', - $mutation1, - 'mutated code 1', - 'diff1' - ) - ) - ; - $this->fileSystemMock ->expects($this->exactly(2)) ->method('dumpFile') ->withConsecutive( - ['/path/to/mutant0', 'mutated code 0'], - ['/path/to/mutant1', 'mutated code 1'] + ['/path/to/mutation0.php', 'mutated code 0'], + ['/path/to/mutation1.php', 'mutated code 1'] ) ; $this->processFactoryMock - ->method('createProcessForMutant') + ->method('createProcessForMutation') ->withConsecutive( - [$mutant0, $testFrameworkExtraOptions], - [$mutant1, $testFrameworkExtraOptions] + [$mutation0, $testFrameworkExtraOptions], + [$mutation1, $testFrameworkExtraOptions] ) ->willReturnOnConsecutiveCalls( - $process0 = $this->buildCoveredMutantProcess(), - $process1 = $this->buildCoveredMutantProcess() + $process0 = $this->buildCoveredMutationProcess($mutation0), + $process1 = $this->buildCoveredMutationProcess($mutation1) ) ; $this->processRunnerMock ->expects($this->once()) ->method('run') - ->with($this->iterableContaining([$process0, $process1]), ) + ->with($this->iterableContaining([$process0, $process1])) ; $this->runner = new MutationTestingRunner( $this->processFactoryMock, - $this->mutationFactoryMock, $this->processRunnerMock, $this->eventDispatcher, $this->fileSystemMock, @@ -290,11 +237,6 @@ public function test_it_passes_through_iterables_when_concurrent_execution_reque ->method($this->anything()) ; - $this->mutationFactoryMock - ->expects($this->never()) - ->method($this->anything()) - ; - $this->processFactoryMock ->expects($this->never()) ->method($this->anything()) @@ -308,7 +250,6 @@ public function test_it_passes_through_iterables_when_concurrent_execution_reque $this->runner = new MutationTestingRunner( $this->processFactoryMock, - $this->mutationFactoryMock, $this->processRunnerMock, $this->eventDispatcher, $this->fileSystemMock, @@ -328,11 +269,6 @@ public function test_it_dispatches_events_even_when_no_mutations_is_given(): voi ->method($this->anything()) ; - $this->mutationFactoryMock - ->expects($this->never()) - ->method($this->anything()) - ; - $this->processRunnerMock ->expects($this->once()) ->method('run') @@ -428,15 +364,15 @@ private function formatExpectedEvents(array $events): string ); } - private function buildCoveredMutantProcess(): MutationProcess + private function buildCoveredMutationProcess(Mutation $mutation): MutationProcess { - $mutantProcess = $this->createMock(MutationProcess::class); - $mutantProcess + $processMock = $this->createMock(Process::class); + $processMock ->expects($this->never()) - ->method('getMutant') + ->method($this->anything()) ; - return $mutantProcess; + return new MutationProcess($processMock, $mutation); } private function someIterable(?callable $callback = null): Callback @@ -478,7 +414,6 @@ private function createMutation(int $i): Mutation { return new Mutation( 'path/to/Foo' . $i . '.php', - [], MutatorName::getName(For_::class), [ 'startLine' => $i, @@ -488,16 +423,21 @@ private function createMutation(int $i): Mutation 'startFilePos' => 2, 'endFilePos' => 4, ], - 'Unknown', - MutatedNode::wrap(new Nop()), - 0, [ new TestLocation( 'FooTest::test_it_can_instantiate', '/path/to/acme/FooTest.php', 0.01 ), - ] + ], + static function () use ($i): MutationCalculatedState { + return new MutationCalculatedState( + 'mutationHash#' . $i, + '/path/to/mutation' . $i . '.php', + 'mutated code ' . $i, + 'diff' + ); + } ); } } From a6993c50cc02f01beb0186a1d17bdcbb97d0d58c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20FIDRY?= Date: Wed, 25 Mar 2020 13:52:31 +0100 Subject: [PATCH 09/21] Fix more tests --- src/Container.php | 3 +- src/Mutation/FileMutationGenerator.php | 8 ++- src/Mutation/Mutation.php | 1 + src/Mutation/MutationCalculatedState.php | 3 ++ src/Mutation/MutationFactory.php | 5 ++ src/Mutator/NodeMutationGenerator.php | 8 ++- tests/phpunit/AutoReview/ContainerTest.php | 1 + .../Mutation/FileMutationGeneratorTest.php | 51 ++++++++++++++++--- .../Mutation/MutationCalculatedStateTest.php | 2 - tests/phpunit/Mutator/BaseMutatorTestCase.php | 20 +++++--- 10 files changed, 79 insertions(+), 23 deletions(-) diff --git a/src/Container.php b/src/Container.php index 83613c6c2..b568b8770 100644 --- a/src/Container.php +++ b/src/Container.php @@ -395,7 +395,8 @@ public static function create(): self return new FileMutationGenerator( $container->getFileParser(), $container->getNodeTraverserFactory(), - $container->getLineRangeCalculator() + $container->getLineRangeCalculator(), + $container->getMutationFactory() ); }, LoggerFactory::class => static function (self $container): LoggerFactory { diff --git a/src/Mutation/FileMutationGenerator.php b/src/Mutation/FileMutationGenerator.php index 077066319..ee6f89843 100644 --- a/src/Mutation/FileMutationGenerator.php +++ b/src/Mutation/FileMutationGenerator.php @@ -55,15 +55,18 @@ class FileMutationGenerator private $parser; private $traverserFactory; private $lineRangeCalculator; + private $mutationFactory; public function __construct( FileParser $parser, NodeTraverserFactory $traverserFactory, - LineRangeCalculator $lineRangeCalculator + LineRangeCalculator $lineRangeCalculator, + MutationFactory $mutationFactory ) { $this->parser = $parser; $this->traverserFactory = $traverserFactory; $this->lineRangeCalculator = $lineRangeCalculator; + $this->mutationFactory = $mutationFactory; } /** @@ -98,7 +101,8 @@ public function generate( $initialStatements, $trace, $onlyCovered, - $this->lineRangeCalculator + $this->lineRangeCalculator, + $this->mutationFactory ) ); diff --git a/src/Mutation/Mutation.php b/src/Mutation/Mutation.php index 2492161ff..b304d6fc6 100644 --- a/src/Mutation/Mutation.php +++ b/src/Mutation/Mutation.php @@ -72,6 +72,7 @@ class Mutation private $calculatedState; /** + * @param array $attributes * @param TestLocation[] $tests * @param Closure(): MutationCalculatedState $calculateState */ diff --git a/src/Mutation/MutationCalculatedState.php b/src/Mutation/MutationCalculatedState.php index 94c0d810b..f0ed51ed8 100644 --- a/src/Mutation/MutationCalculatedState.php +++ b/src/Mutation/MutationCalculatedState.php @@ -35,6 +35,9 @@ namespace Infection\Mutation; +/** + * @internal + */ final class MutationCalculatedState { private $mutationFilePath; diff --git a/src/Mutation/MutationFactory.php b/src/Mutation/MutationFactory.php index 32379d40a..d7c061fc3 100644 --- a/src/Mutation/MutationFactory.php +++ b/src/Mutation/MutationFactory.php @@ -75,6 +75,7 @@ public function __construct( /** * @param Node[] $originalFileAst * @param array $attributes + * @param class-string $mutatedNodeClass * @param TestLocation[] $tests */ public function create( @@ -117,6 +118,7 @@ function () use ( /** * @param Node[] $originalFileAst * @param array $attributes + * @param class-string $mutatedNodeClass */ private function calculateState( string $originalFilePath, @@ -159,6 +161,9 @@ private function calculateState( ); } + /** + * @param array $attributes + */ private static function createHash( string $originalFilePath, string $mutatorName, diff --git a/src/Mutator/NodeMutationGenerator.php b/src/Mutator/NodeMutationGenerator.php index d624425bd..8ecd51d6e 100644 --- a/src/Mutator/NodeMutationGenerator.php +++ b/src/Mutator/NodeMutationGenerator.php @@ -38,6 +38,7 @@ use function count; use function get_class; use Infection\Mutation\Mutation; +use Infection\Mutation\MutationFactory; use Infection\PhpParser\MutatedNode; use Infection\PhpParser\Visitor\ReflectionVisitor; use Infection\TestFramework\Coverage\LineRangeCalculator; @@ -61,6 +62,7 @@ class NodeMutationGenerator private $trace; private $onlyCovered; private $lineRangeCalculator; + private $mutationFactory; /** * @param Mutator[] $mutators @@ -72,7 +74,8 @@ public function __construct( array $fileNodes, Trace $trace, bool $onlyCovered, - LineRangeCalculator $lineRangeCalculator + LineRangeCalculator $lineRangeCalculator, + MutationFactory $mutationFactory ) { Assert::allIsInstanceOf($mutators, Mutator::class); @@ -82,6 +85,7 @@ public function __construct( $this->trace = $trace; $this->onlyCovered = $onlyCovered; $this->lineRangeCalculator = $lineRangeCalculator; + $this->mutationFactory = $mutationFactory; } /** @@ -135,7 +139,7 @@ private function generateForMutator(Node $node, Mutator $mutator): iterable $mutationByMutatorIndex = 0; foreach ($mutator->mutate($node) as $mutatedNode) { - yield new Mutation( + yield $this->mutationFactory->create( $this->filePath, $this->fileNodes, $mutator->getName(), diff --git a/tests/phpunit/AutoReview/ContainerTest.php b/tests/phpunit/AutoReview/ContainerTest.php index fbf1569fb..949aa0c2c 100644 --- a/tests/phpunit/AutoReview/ContainerTest.php +++ b/tests/phpunit/AutoReview/ContainerTest.php @@ -98,6 +98,7 @@ static function (string $path): string { __DIR__ . '/ContainerTest.php', __DIR__ . '/../ContainerTest.php', __DIR__ . '/../SingletonContainer.php', + __DIR__ . '/../Mutation/FileMutationGeneratorTest.php', ] ); diff --git a/tests/phpunit/Mutation/FileMutationGeneratorTest.php b/tests/phpunit/Mutation/FileMutationGeneratorTest.php index 0831d1ce0..4558cd2a9 100644 --- a/tests/phpunit/Mutation/FileMutationGeneratorTest.php +++ b/tests/phpunit/Mutation/FileMutationGeneratorTest.php @@ -36,8 +36,10 @@ namespace Infection\Tests\Mutation; use function current; +use Infection\Container; use Infection\Mutation\FileMutationGenerator; use Infection\Mutation\Mutation; +use Infection\Mutation\MutationFactory; use Infection\Mutator\Arithmetic\Plus; use Infection\Mutator\IgnoreConfig; use Infection\Mutator\IgnoreMutator; @@ -49,7 +51,6 @@ use Infection\Tests\Fixtures\PhpParser\FakeIgnorer; use Infection\Tests\Fixtures\PhpParser\FakeNode; use Infection\Tests\Mutator\MutatorName; -use Infection\Tests\SingletonContainer; use PhpParser\NodeTraverserInterface; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; @@ -70,6 +71,11 @@ final class FileMutationGeneratorTest extends TestCase */ private $traverserFactoryMock; + /** + * @var MutationFactory|MockObject + */ + private $mutationFactoryMock; + /** * @var FileMutationGenerator */ @@ -79,16 +85,41 @@ protected function setUp(): void { $this->fileParserMock = $this->createMock(FileParser::class); $this->traverserFactoryMock = $this->createMock(NodeTraverserFactory::class); + $this->mutationFactoryMock = $this->createMock(MutationFactory::class); $this->mutationGenerator = new FileMutationGenerator( $this->fileParserMock, $this->traverserFactoryMock, - new LineRangeCalculator() + new LineRangeCalculator(), + $this->mutationFactoryMock ); } public function test_it_generates_mutations_for_a_given_file(): void { + $container = Container::create()->withDynamicParameters( + null, + '', + false, + 'default', + false, + false, + 'dot', + false, + '/path/to/coverage', + '', + false, + false, + .0, + .0, + 2, + 'phpunit', + '', + '', + 0, + true + ); + $traceMock = $this->createTraceMock( self::FIXTURES_DIR . '/Mutation/OneFile/OneFile.php', '', @@ -104,9 +135,7 @@ public function test_it_generates_mutations_for_a_given_file(): void ->willReturn([]) ; - $mutationGenerator = SingletonContainer::getContainer()->getFileMutationGenerator(); - - $mutations = $mutationGenerator->generate( + $mutations = $container->getFileMutationGenerator()->generate( $traceMock, false, [new IgnoreMutator(new IgnoreConfig([]), new Plus())], @@ -185,18 +214,24 @@ public function test_it_skips_the_mutation_generation_if_checks_only_covered_cod ): void { $this->fileParserMock ->expects($this->never()) - ->method('parse') + ->method($this->anything()) ; $this->traverserFactoryMock ->expects($this->never()) - ->method('create') + ->method($this->anything()) + ; + + $this->mutationFactoryMock + ->expects($this->never()) + ->method($this->anything()) ; $mutationGenerator = new FileMutationGenerator( $this->fileParserMock, $this->traverserFactoryMock, - new LineRangeCalculator() + new LineRangeCalculator(), + $this->mutationFactoryMock ); $mutations = $mutationGenerator->generate( diff --git a/tests/phpunit/Mutation/MutationCalculatedStateTest.php b/tests/phpunit/Mutation/MutationCalculatedStateTest.php index fd8a95b5f..60e2baf7b 100644 --- a/tests/phpunit/Mutation/MutationCalculatedStateTest.php +++ b/tests/phpunit/Mutation/MutationCalculatedStateTest.php @@ -40,8 +40,6 @@ final class MutationCalculatedStateTest extends TestCase { - use MutationCalculatedStateAssertions; - public function test_it_can_be_instantiated(): void { $state = new MutationCalculatedState( diff --git a/tests/phpunit/Mutator/BaseMutatorTestCase.php b/tests/phpunit/Mutator/BaseMutatorTestCase.php index a2debcf37..947af1ce4 100644 --- a/tests/phpunit/Mutator/BaseMutatorTestCase.php +++ b/tests/phpunit/Mutator/BaseMutatorTestCase.php @@ -81,19 +81,19 @@ final public function doTest(string $inputCode, $expectedCode = [], array $setti $this->fail('Input code cant be the same as mutated code'); } - $mutations = $this->mutate($inputCode, $settings); + $mutatedCodes = $this->mutate($inputCode, $settings); $this->assertCount( - count($mutations), + count($mutatedCodes), $expectedCodeSamples, sprintf( 'Failed asserting that the number of code samples (%d) equals the number of mutations (%d) created by the mutator.', count($expectedCodeSamples), - count($mutations) + count($mutatedCodes) ) ); - foreach ($mutations as $realMutatedCode) { + foreach ($mutatedCodes as $realMutatedCode) { /** @var string|null $expectedCodeSample */ $expectedCodeSample = array_shift($expectedCodeSamples); @@ -134,21 +134,25 @@ final protected function mutate(string $code, array $settings = []): array $traverser = new NodeTraverser(); $traverser->addVisitor(new CloneVisitor()); - $mutations = []; + $mutatedCodes = []; foreach ($mutations as $mutation) { - $mutatorVisitor = new MutatorVisitor($mutation); + $mutatorVisitor = new MutatorVisitor( + $mutation->getAttributes(), + $mutation->getMutatedNodeClass(), + $mutation->getMutatedNode() + ); $traverser->addVisitor($mutatorVisitor); $mutatedStatements = $traverser->traverse($mutation->getOriginalFileAst()); - $mutations[] = SingletonContainer::getPrinter()->prettyPrintFile($mutatedStatements); + $mutatedCodes[] = SingletonContainer::getPrinter()->prettyPrintFile($mutatedStatements); $traverser->removeVisitor($mutatorVisitor); } - return $mutations; + return $mutatedCodes; } /** From 56e8026f4da9f2b51efb69246afe55e8743e763a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20FIDRY?= Date: Wed, 25 Mar 2020 14:55:45 +0100 Subject: [PATCH 10/21] Fix more tests --- src/Console/LogVerbosity.php | 3 + src/Container.php | 4 +- src/Metrics/MinMsiChecker.php | 1 - src/Mutation/DetectionStatus.php | 4 + src/Mutation/Mutation.php | 25 +-- src/Mutation/MutationAttributeKeys.php | 59 +++++++ src/Mutation/MutationFactory.php | 11 +- tests/phpunit/Fixtures/SimpleMutation.php | 8 +- .../MutationExecutionResultFactoryTest.php | 45 +----- .../Mutation/MutationExecutionResultTest.php | 9 +- .../phpunit/Mutation/MutationFactoryTest.php | 148 +++++++++++++----- tests/phpunit/Mutation/MutationTest.php | 55 +------ tests/phpunit/Mutator/BaseMutatorTestCase.php | 2 +- .../Builder/MutationProcessFactoryTest.php | 9 +- .../Runner/MutationTestingRunnerTest.php | 9 +- 15 files changed, 212 insertions(+), 180 deletions(-) create mode 100644 src/Mutation/MutationAttributeKeys.php diff --git a/src/Console/LogVerbosity.php b/src/Console/LogVerbosity.php index 69a15dd80..b5ccb915b 100644 --- a/src/Console/LogVerbosity.php +++ b/src/Console/LogVerbosity.php @@ -37,6 +37,7 @@ use function array_key_exists; use function in_array; +use Infection\CannotBeInstantiated; use Symfony\Component\Console\Input\InputInterface; /** @@ -44,6 +45,8 @@ */ final class LogVerbosity { + use CannotBeInstantiated; + public const DEBUG = 'all'; public const NORMAL = 'default'; public const NONE = 'none'; diff --git a/src/Container.php b/src/Container.php index b568b8770..bb0f51fbb 100644 --- a/src/Container.php +++ b/src/Container.php @@ -63,7 +63,7 @@ use Infection\Metrics\MetricsCalculator; use Infection\Metrics\MinMsiChecker; use Infection\Mutation\FileMutationGenerator; -use Infection\Mutation\Mutation; +use Infection\Mutation\MutationAttributeKeys; use Infection\Mutation\MutationCodeFactory; use Infection\Mutation\MutationExecutionResultFactory; use Infection\Mutation\MutationFactory; @@ -259,7 +259,7 @@ public static function create(): self ); }, Lexer::class => static function (): Lexer { - $attributes = Mutation::ATTRIBUTE_KEYS; + $attributes = MutationAttributeKeys::ALL; $attributes[] = 'comments'; return new Lexer\Emulative(['usedAttributes' => $attributes]); diff --git a/src/Metrics/MinMsiChecker.php b/src/Metrics/MinMsiChecker.php index b74efd05a..b1fe3356e 100644 --- a/src/Metrics/MinMsiChecker.php +++ b/src/Metrics/MinMsiChecker.php @@ -42,7 +42,6 @@ */ final class MinMsiChecker { - public const MSI_FAILURE = 'min-msi'; private const VALUE_OVER_REQUIRED_TOLERANCE = 2; private $ignoreMsiWithNoMutations; diff --git a/src/Mutation/DetectionStatus.php b/src/Mutation/DetectionStatus.php index d47288f29..4f7a78f2c 100644 --- a/src/Mutation/DetectionStatus.php +++ b/src/Mutation/DetectionStatus.php @@ -35,11 +35,15 @@ namespace Infection\Mutation; +use Infection\CannotBeInstantiated; + /** * @internal */ final class DetectionStatus { + use CannotBeInstantiated; + public const KILLED = 'killed'; public const ESCAPED = 'escaped'; public const ERROR = 'error'; diff --git a/src/Mutation/Mutation.php b/src/Mutation/Mutation.php index b304d6fc6..0afe791ae 100644 --- a/src/Mutation/Mutation.php +++ b/src/Mutation/Mutation.php @@ -35,13 +35,11 @@ namespace Infection\Mutation; -use function array_intersect_key; use function array_keys; use Closure; use function count; use Infection\AbstractTestFramework\Coverage\TestLocation; use Infection\Mutator\ProfileList; -use function Safe\array_flip; use Webmozart\Assert\Assert; /** @@ -50,18 +48,9 @@ */ class Mutation { - public const ATTRIBUTE_KEYS = [ - 'startLine', - 'endLine', - 'startTokenPos', - 'endTokenPos', - 'startFilePos', - 'endFilePos', - ]; - private $originalFilePath; private $mutatorName; - private $attributes; + private $originalStartingLine; private $tests; private $executedByTests; private $calculateState; @@ -72,27 +61,21 @@ class Mutation private $calculatedState; /** - * @param array $attributes * @param TestLocation[] $tests * @param Closure(): MutationCalculatedState $calculateState */ public function __construct( string $originalFilePath, string $mutatorName, - array $attributes, + int $originalStartingLine, array $tests, Closure $calculateState ) { Assert::oneOf($mutatorName, array_keys(ProfileList::ALL_MUTATORS)); - foreach (self::ATTRIBUTE_KEYS as $key) { - Assert::keyExists($attributes, $key); - } - $this->originalFilePath = $originalFilePath; $this->mutatorName = $mutatorName; - // TODO: move this up - $this->attributes = array_intersect_key($attributes, array_flip(self::ATTRIBUTE_KEYS)); + $this->originalStartingLine = $originalStartingLine; $this->tests = $tests; $this->executedByTests = count($tests) > 0; $this->calculateState = $calculateState; @@ -115,7 +98,7 @@ public function getMutatorName(): string public function getOriginalStartingLine(): int { - return (int) $this->attributes['startLine']; + return $this->originalStartingLine; } public function hasTests(): bool diff --git a/src/Mutation/MutationAttributeKeys.php b/src/Mutation/MutationAttributeKeys.php new file mode 100644 index 000000000..2946d3b72 --- /dev/null +++ b/src/Mutation/MutationAttributeKeys.php @@ -0,0 +1,59 @@ +originalFileAst = $originalFileAst; $this->mutator = $mutator; $this->mutatedNode = $mutatedNode; - $this->attributes = $attributes; + $this->originalStartingLine = $attributes; $this->mutatedNodeClass = $mutatedNodeClass; } @@ -63,9 +63,9 @@ public function getMutatedNode(): MutatedNode return $this->mutatedNode; } - public function getAttributes(): array + public function getOriginalStartingLine(): array { - return $this->attributes; + return $this->originalStartingLine; } public function getMutatedNodeClass(): string diff --git a/tests/phpunit/Mutation/MutationExecutionResultFactoryTest.php b/tests/phpunit/Mutation/MutationExecutionResultFactoryTest.php index c0f82a338..1cfac0fd2 100644 --- a/tests/phpunit/Mutation/MutationExecutionResultFactoryTest.php +++ b/tests/phpunit/Mutation/MutationExecutionResultFactoryTest.php @@ -107,14 +107,7 @@ public function test_it_can_create_a_result_from_a_non_covered_mutation_process( new Mutation( $originalFilePath = 'path/to/Foo.php', $mutatorName = MutatorName::getName(For_::class), - [ - 'startLine' => $originalStartingLine = 10, - 'endLine' => 15, - 'startTokenPos' => 0, - 'endTokenPos' => 8, - 'startFilePos' => 2, - 'endFilePos' => 4, - ], + $originalStartingLine = 10, [], static function () use ($mutationDiff): MutationCalculatedState { return new MutationCalculatedState( @@ -177,14 +170,7 @@ public function test_it_can_create_a_result_from_a_timed_out_mutation_process(): new Mutation( $originalFilePath = 'path/to/Foo.php', $mutatorName = MutatorName::getName(For_::class), - [ - 'startLine' => $originalStartingLine = 10, - 'endLine' => 15, - 'startTokenPos' => 0, - 'endTokenPos' => 8, - 'startFilePos' => 2, - 'endFilePos' => 4, - ], + $originalStartingLine = 10, [ new TestLocation( 'FooTest::test_it_can_instantiate', @@ -260,14 +246,7 @@ public function test_it_can_create_a_result_from_an_errored_mutation_process(): new Mutation( $originalFilePath = 'path/to/Foo.php', $mutatorName = MutatorName::getName(For_::class), - [ - 'startLine' => $originalStartingLine = 10, - 'endLine' => 15, - 'startTokenPos' => 0, - 'endTokenPos' => 8, - 'startFilePos' => 2, - 'endFilePos' => 4, - ], + $originalStartingLine = 10, [ new TestLocation( 'FooTest::test_it_can_instantiate', @@ -343,14 +322,7 @@ public function test_it_can_crate_a_result_from_an_escaped_mutation_process(): v new Mutation( $originalFilePath = 'path/to/Foo.php', $mutatorName = MutatorName::getName(For_::class), - [ - 'startLine' => $originalStartingLine = 10, - 'endLine' => 15, - 'startTokenPos' => 0, - 'endTokenPos' => 8, - 'startFilePos' => 2, - 'endFilePos' => 4, - ], + $originalStartingLine = 10, [ new TestLocation( 'FooTest::test_it_can_instantiate', @@ -426,14 +398,7 @@ public function test_it_can_crate_a_result_from_a_killed_mutation_process(): voi new Mutation( $originalFilePath = 'path/to/Foo.php', $mutatorName = MutatorName::getName(For_::class), - [ - 'startLine' => $originalStartingLine = 10, - 'endLine' => 15, - 'startTokenPos' => 0, - 'endTokenPos' => 8, - 'startFilePos' => 2, - 'endFilePos' => 4, - ], + $originalStartingLine = 10, [ new TestLocation( 'FooTest::test_it_can_instantiate', diff --git a/tests/phpunit/Mutation/MutationExecutionResultTest.php b/tests/phpunit/Mutation/MutationExecutionResultTest.php index d5e5386a9..968c31451 100644 --- a/tests/phpunit/Mutation/MutationExecutionResultTest.php +++ b/tests/phpunit/Mutation/MutationExecutionResultTest.php @@ -102,14 +102,7 @@ public function test_it_can_be_instantiated_from_a_mutation_non_executed_by_test $mutation = new Mutation( $originalFilePath = 'path/to/Foo.php', $mutatorName = MutatorName::getName(For_::class), - [ - 'startLine' => $originalStartingLine = 10, - 'endLine' => 15, - 'startTokenPos' => 0, - 'endTokenPos' => 8, - 'startFilePos' => 2, - 'endFilePos' => 4, - ], + $originalStartingLine = 10, [ new TestLocation( 'FooTest::test_it_can_instantiate', diff --git a/tests/phpunit/Mutation/MutationFactoryTest.php b/tests/phpunit/Mutation/MutationFactoryTest.php index 9b7fc058f..8a493ba4d 100644 --- a/tests/phpunit/Mutation/MutationFactoryTest.php +++ b/tests/phpunit/Mutation/MutationFactoryTest.php @@ -35,6 +35,7 @@ namespace Infection\Tests\Mutation; +use function array_merge; use Infection\AbstractTestFramework\Coverage\TestLocation; use Infection\Differ\Differ; use Infection\Mutation\MutationCodeFactory; @@ -89,45 +90,34 @@ protected function setUp(): void ); } - public function test_it_creates_a_mutation(): void - { - $originalFilePath = '/path/to/acme/Foo.php'; - $originalFileAst = [new Node\Stmt\Namespace_( - new Node\Name('Acme'), - [new Node\Scalar\LNumber(0)] - )]; - $mutatorName = MutatorName::getName(Plus::class); - $attributes = [ - 'startLine' => $originalStartingLine = 3, - 'endLine' => 5, - 'startTokenPos' => 21, - 'endTokenPos' => 31, - 'startFilePos' => 43, - 'endFilePos' => 53, - ]; - $mutatedNodeClass = Node\Scalar\LNumber::class; - $mutatedNode = MutatedNode::wrap(new Node\Scalar\LNumber(1)); - $mutationByMutatorIndex = 0; - $tests = [ - new TestLocation( - 'FooTest::test_it_can_instantiate', - '/path/to/acme/FooTest.php', - 0.01 - ), - ]; - - $expectedHash = md5('/path/to/acme/Foo.php_Plus_0_3_5_21_31_43_53'); - - $expectedMutationFilePath = sprintf( - '/path/to/tmp/mutation.%s.infection.php', - $expectedHash - ); - + /** + * @dataProvider valuesProvider + * + * @param Node[] $originalFileAst + * @param array $attributes + * @param class-string $mutatedNodeClass + * @param TestLocation[] $tests + * @param array $expectedFilteredAttributes + */ + public function test_it_creates_a_mutation( + string $originalFilePath, + array $originalFileAst, + string $mutatorName, + array $attributes, + string $mutatedNodeClass, + MutatedNode $mutatedNode, + int $mutationByMutatorIndex, + array $tests, + array $expectedFilteredAttributes, + string $expectedHash, + string $expectedMutationFilePath, + int $expectedOriginalStartingLine + ): void { $this->codeFactoryMock ->expects($this->exactly(2)) ->method('createCode') ->with( - $attributes, + $expectedFilteredAttributes, $originalFileAst, $mutatedNodeClass, $mutatedNode @@ -169,7 +159,7 @@ public function test_it_creates_a_mutation(): void $expectedMutationFilePath, 'mutated code', 'code diff', - $originalStartingLine, + $expectedOriginalStartingLine, true ); @@ -195,8 +185,92 @@ public function test_it_creates_a_mutation(): void $expectedMutationFilePath, 'mutated code', 'code diff', - $originalStartingLine, + $expectedOriginalStartingLine, true ); } + + public static function valuesProvider(): iterable + { + $nominalAttributes = [ + 'startLine' => $originalStartingLine = 3, + 'endLine' => 5, + 'startTokenPos' => 21, + 'endTokenPos' => 31, + 'startFilePos' => 43, + 'endFilePos' => 53, + ]; + + yield 'nominal' => (static function () use ( + $nominalAttributes, + $originalStartingLine + ): array { + $expectedHash = md5('/path/to/acme/Foo.php_Plus_0_3_5_21_31_43_53'); + + return [ + '/path/to/acme/Foo.php', + [ + new Node\Stmt\Namespace_( + new Node\Name('Acme'), + [new Node\Scalar\LNumber(0)] + ), + ], + MutatorName::getName(Plus::class), + $nominalAttributes, + Node\Scalar\LNumber::class, + MutatedNode::wrap(new Node\Scalar\LNumber(1)), + 0, + [ + new TestLocation( + 'FooTest::test_it_can_instantiate', + '/path/to/acme/FooTest.php', + 0.01 + ), + ], + $nominalAttributes, + $expectedHash, + sprintf( + '/path/to/tmp/mutation.%s.infection.php', + $expectedHash + ), + $originalStartingLine, + ]; + })(); + + yield 'with additional attributes' => (static function () use ( + $nominalAttributes, + $originalStartingLine + ): array { + $expectedHash = md5('/path/to/acme/Foo.php_Plus_0_3_5_21_31_43_53'); + + return [ + '/path/to/acme/Foo.php', + [ + new Node\Stmt\Namespace_( + new Node\Name('Acme'), + [new Node\Scalar\LNumber(0)] + ), + ], + MutatorName::getName(Plus::class), + array_merge($nominalAttributes, ['foo' => 100, 'bar' => 1000]), + Node\Scalar\LNumber::class, + MutatedNode::wrap(new Node\Scalar\LNumber(1)), + 0, + [ + new TestLocation( + 'FooTest::test_it_can_instantiate', + '/path/to/acme/FooTest.php', + 0.01 + ), + ], + $nominalAttributes, + $expectedHash, + sprintf( + '/path/to/tmp/mutation.%s.infection.php', + $expectedHash + ), + $originalStartingLine, + ]; + })(); + } } diff --git a/tests/phpunit/Mutation/MutationTest.php b/tests/phpunit/Mutation/MutationTest.php index 03d4c2e78..d918f3a93 100644 --- a/tests/phpunit/Mutation/MutationTest.php +++ b/tests/phpunit/Mutation/MutationTest.php @@ -35,7 +35,6 @@ namespace Infection\Tests\Mutation; -use function array_merge; use Infection\AbstractTestFramework\Coverage\TestLocation; use Infection\Mutation\Mutation; use Infection\Mutation\MutationCalculatedState; @@ -48,25 +47,23 @@ final class MutationTest extends TestCase /** * @dataProvider valuesProvider * - * @param array $attributes * @param TestLocation[] $tests */ public function test_it_can_be_instantiated( string $originalFilePath, string $mutatorName, - array $attributes, + int $originalStartingLine, array $tests, string $hash, string $filePath, string $code, string $diff, - int $expectedOriginalStartingLine, bool $expectedHasTests ): void { $mutation = new Mutation( $originalFilePath, $mutatorName, - $attributes, + $originalStartingLine, $tests, static function () use ($hash, $filePath, $code, $diff): MutationCalculatedState { return new MutationCalculatedState( @@ -80,7 +77,7 @@ static function () use ($hash, $filePath, $code, $diff): MutationCalculatedState $this->assertSame($originalFilePath, $mutation->getOriginalFilePath()); $this->assertSame($mutatorName, $mutation->getMutatorName()); - $this->assertSame($expectedOriginalStartingLine, $mutation->getOriginalStartingLine()); + $this->assertSame($originalStartingLine, $mutation->getOriginalStartingLine()); $this->assertSame($tests, $mutation->getTests()); $this->assertSame($expectedHasTests, $mutation->hasTests()); $this->assertSame($hash, $mutation->getHash()); @@ -91,60 +88,22 @@ static function () use ($hash, $filePath, $code, $diff): MutationCalculatedState public function valuesProvider(): iterable { - $nominalAttributes = [ - 'startLine' => $originalStartingLine = 3, - 'endLine' => 5, - 'startTokenPos' => 21, - 'endTokenPos' => 31, - 'startFilePos' => 43, - 'endFilePos' => 53, - ]; - yield 'empty' => [ '', MutatorName::getName(Plus::class), - $nominalAttributes, + 3, [], '', '', '', '', - $originalStartingLine, false, ]; yield 'nominal with a test' => [ '/path/to/acme/Foo.php', MutatorName::getName(Plus::class), - $nominalAttributes, - [ - new TestLocation( - 'FooTest::test_it_can_instantiate', - '/path/to/acme/FooTest.php', - 0.01 - ), - ], - '0800f', - '/path/to/mutation', - 'notCovered#0', - <<<'DIFF' ---- Original -+++ New -@@ @@ - -- echo 'original'; -+ echo 'notCovered#0'; - -DIFF - , - $originalStartingLine, - true, - ]; - - yield 'nominal with a test and additional attributes' => [ - '/path/to/acme/Foo.php', - MutatorName::getName(Plus::class), - array_merge($nominalAttributes, ['foo' => 100, 'bar' => 1000]), + 3, [ new TestLocation( 'FooTest::test_it_can_instantiate', @@ -165,14 +124,13 @@ public function valuesProvider(): iterable DIFF , - $originalStartingLine, true, ]; yield 'nominal without a test' => [ '/path/to/acme/Foo.php', MutatorName::getName(Plus::class), - $nominalAttributes, + 3, [], '0800f', '/path/to/mutation', @@ -187,7 +145,6 @@ public function valuesProvider(): iterable DIFF , - $originalStartingLine, false, ]; } diff --git a/tests/phpunit/Mutator/BaseMutatorTestCase.php b/tests/phpunit/Mutator/BaseMutatorTestCase.php index 947af1ce4..3ab260ebd 100644 --- a/tests/phpunit/Mutator/BaseMutatorTestCase.php +++ b/tests/phpunit/Mutator/BaseMutatorTestCase.php @@ -138,7 +138,7 @@ final protected function mutate(string $code, array $settings = []): array foreach ($mutations as $mutation) { $mutatorVisitor = new MutatorVisitor( - $mutation->getAttributes(), + $mutation->getOriginalStartingLine(), $mutation->getMutatedNodeClass(), $mutation->getMutatedNode() ); diff --git a/tests/phpunit/Process/Builder/MutationProcessFactoryTest.php b/tests/phpunit/Process/Builder/MutationProcessFactoryTest.php index 4eda4d1fc..dc742ca89 100644 --- a/tests/phpunit/Process/Builder/MutationProcessFactoryTest.php +++ b/tests/phpunit/Process/Builder/MutationProcessFactoryTest.php @@ -60,14 +60,7 @@ public function test_it_creates_a_process_with_timeout(): void $mutation = new Mutation( $originalFilePath = 'path/to/Foo.php', MutatorName::getName(For_::class), - [ - 'startLine' => $originalStartingLine = 10, - 'endLine' => 15, - 'startTokenPos' => 0, - 'endTokenPos' => 8, - 'startFilePos' => 2, - 'endFilePos' => 4, - ], + 10, $tests = [ new TestLocation( 'FooTest::test_it_can_instantiate', diff --git a/tests/phpunit/Process/Runner/MutationTestingRunnerTest.php b/tests/phpunit/Process/Runner/MutationTestingRunnerTest.php index 1c50fc247..afb7f0943 100644 --- a/tests/phpunit/Process/Runner/MutationTestingRunnerTest.php +++ b/tests/phpunit/Process/Runner/MutationTestingRunnerTest.php @@ -415,14 +415,7 @@ private function createMutation(int $i): Mutation return new Mutation( 'path/to/Foo' . $i . '.php', MutatorName::getName(For_::class), - [ - 'startLine' => $i, - 'endLine' => 15, - 'startTokenPos' => 0, - 'endTokenPos' => 8, - 'startFilePos' => 2, - 'endFilePos' => 4, - ], + 10, [ new TestLocation( 'FooTest::test_it_can_instantiate', From 9e3bb0e746e7b7586ebf02f733a1d8cf310e98d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20FIDRY?= Date: Wed, 25 Mar 2020 15:05:58 +0100 Subject: [PATCH 11/21] Fix SimpleMutation --- tests/phpunit/Fixtures/SimpleMutation.php | 62 ++++++++++--------- .../SimpleMutationsCollectorVisitor.php | 11 ++-- tests/phpunit/Mutator/BaseMutatorTestCase.php | 6 +- 3 files changed, 39 insertions(+), 40 deletions(-) diff --git a/tests/phpunit/Fixtures/SimpleMutation.php b/tests/phpunit/Fixtures/SimpleMutation.php index c87a63fbe..3339ea1bb 100644 --- a/tests/phpunit/Fixtures/SimpleMutation.php +++ b/tests/phpunit/Fixtures/SimpleMutation.php @@ -5,54 +5,53 @@ namespace Infection\Tests\Fixtures; use Infection\Mutation\Mutation; +use Infection\Mutation\MutationAttributeKeys; +use Infection\Mutation\MutationCalculatedState; use Infection\Mutator\Mutator; use Infection\PhpParser\MutatedNode; +use Infection\Tests\UnsupportedMethod; use PhpParser\Node; class SimpleMutation extends Mutation { - /** - * @var Mutator - */ - private $mutator; - - /** - * @var Node[] - */ private $originalFileAst; - - /** - * @var MutatedNode - */ + private $mutator; private $mutatedNode; - /** - * @var array - */ - private $originalStartingLine; - /** - * @var string - */ + private $attributes; private $mutatedNodeClass; + /** + * @param Node[] $originalFileAst + * @param class-string $mutatorName + * @param array $attributes + * @param class-string $mutatedNodeClass + */ public function __construct( array $originalFileAst, - Mutator $mutator, - $mutatedNode, + string $mutatorName, + MutatedNode $mutatedNode, array $attributes, string $mutatedNodeClass ) { + parent::__construct( + '/path/to/Foo.php', + $mutatorName, + (int) $attributes[MutationAttributeKeys::START_LINE], + [], + static function (): MutationCalculatedState { + throw UnsupportedMethod::method(Mutation::class, 'calculateState'); + } + ); + $this->originalFileAst = $originalFileAst; - $this->mutator = $mutator; $this->mutatedNode = $mutatedNode; - $this->originalStartingLine = $attributes; + $this->attributes = $attributes; $this->mutatedNodeClass = $mutatedNodeClass; } - public function getMutator(): Mutator - { - return $this->mutator; - } - + /** + * @return Node[] + */ public function getOriginalFileAst(): array { return $this->originalFileAst; @@ -63,9 +62,12 @@ public function getMutatedNode(): MutatedNode return $this->mutatedNode; } - public function getOriginalStartingLine(): array + /** + * @return array + */ + public function getAttributes(): array { - return $this->originalStartingLine; + return $this->attributes; } public function getMutatedNodeClass(): string diff --git a/tests/phpunit/Fixtures/SimpleMutationsCollectorVisitor.php b/tests/phpunit/Fixtures/SimpleMutationsCollectorVisitor.php index 4c245c853..f2abefdf7 100644 --- a/tests/phpunit/Fixtures/SimpleMutationsCollectorVisitor.php +++ b/tests/phpunit/Fixtures/SimpleMutationsCollectorVisitor.php @@ -14,10 +14,8 @@ */ final class SimpleMutationsCollectorVisitor extends NodeVisitorAbstract { - /** - * @var Mutator[] - */ private $mutator; + private $fileAst; /** * @var SimpleMutation[] @@ -25,10 +23,9 @@ final class SimpleMutationsCollectorVisitor extends NodeVisitorAbstract private $mutations = []; /** - * @var Node[] + * @param Mutator $mutator + * @param Node[] $fileAst */ - private $fileAst; - public function __construct(Mutator $mutator, array $fileAst) { $this->mutator = $mutator; @@ -46,7 +43,7 @@ public function leaveNode(Node $node) foreach($this->mutator->mutate($node) as $mutatedNode) { $this->mutations[] = new SimpleMutation( $this->fileAst, - $this->mutator, + $this->mutator->getName(), MutatedNode::wrap($mutatedNode), $node->getAttributes(), get_class($node) diff --git a/tests/phpunit/Mutator/BaseMutatorTestCase.php b/tests/phpunit/Mutator/BaseMutatorTestCase.php index 3ab260ebd..760843e50 100644 --- a/tests/phpunit/Mutator/BaseMutatorTestCase.php +++ b/tests/phpunit/Mutator/BaseMutatorTestCase.php @@ -40,12 +40,12 @@ use function escapeshellarg; use function exec; use function get_class; +use Infection\Mutation\Mutation; use Infection\Mutator\Mutator; use Infection\PhpParser\NodeTraverserFactory; use Infection\PhpParser\Visitor\CloneVisitor; use Infection\PhpParser\Visitor\MutatorVisitor; use Infection\Tests\AutoReview\SourceTestClassNameScheme; -use Infection\Tests\Fixtures\SimpleMutation; use Infection\Tests\Fixtures\SimpleMutationsCollectorVisitor; use Infection\Tests\SingletonContainer; use Infection\Tests\StringNormalizer; @@ -138,7 +138,7 @@ final protected function mutate(string $code, array $settings = []): array foreach ($mutations as $mutation) { $mutatorVisitor = new MutatorVisitor( - $mutation->getOriginalStartingLine(), + $mutation->getAttributes(), $mutation->getMutatedNodeClass(), $mutation->getMutatedNode() ); @@ -156,7 +156,7 @@ final protected function mutate(string $code, array $settings = []): array } /** - * @return SimpleMutation[] + * @return Mutation[] */ private function getMutationsFromCode(string $code, array $settings): array { From cd8d20325017ab4868be8f64c3e2af45da15d6b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20FIDRY?= Date: Wed, 25 Mar 2020 15:30:47 +0100 Subject: [PATCH 12/21] Fix autoreview --- src/Mutation/MutationAttributeKeys.php | 3 +++ tests/phpunit/AutoReview/ProjectCode/ProjectCodeProvider.php | 2 ++ tests/phpunit/Mutator/BaseMutatorTestCase.php | 3 ++- 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Mutation/MutationAttributeKeys.php b/src/Mutation/MutationAttributeKeys.php index 2946d3b72..e2007ef81 100644 --- a/src/Mutation/MutationAttributeKeys.php +++ b/src/Mutation/MutationAttributeKeys.php @@ -37,6 +37,9 @@ use Infection\CannotBeInstantiated; +/** + * @internal + */ final class MutationAttributeKeys { use CannotBeInstantiated; diff --git a/tests/phpunit/AutoReview/ProjectCode/ProjectCodeProvider.php b/tests/phpunit/AutoReview/ProjectCode/ProjectCodeProvider.php index 7027d713b..5b22c522c 100644 --- a/tests/phpunit/AutoReview/ProjectCode/ProjectCodeProvider.php +++ b/tests/phpunit/AutoReview/ProjectCode/ProjectCodeProvider.php @@ -35,6 +35,7 @@ namespace Infection\Tests\AutoReview\ProjectCode; +use Infection\Mutation\MutationAttributeKeys; use const DIRECTORY_SEPARATOR; use function in_array; use Infection\CannotBeInstantiated; @@ -104,6 +105,7 @@ final class ProjectCodeProvider AdapterInstaller::class, DetectionStatus::class, DummyFileSystem::class, + MutationAttributeKeys::class, ]; /** diff --git a/tests/phpunit/Mutator/BaseMutatorTestCase.php b/tests/phpunit/Mutator/BaseMutatorTestCase.php index 760843e50..abe64d112 100644 --- a/tests/phpunit/Mutator/BaseMutatorTestCase.php +++ b/tests/phpunit/Mutator/BaseMutatorTestCase.php @@ -35,6 +35,7 @@ namespace Infection\Tests\Mutator; +use Infection\Tests\Fixtures\SimpleMutation; use function array_shift; use function count; use function escapeshellarg; @@ -156,7 +157,7 @@ final protected function mutate(string $code, array $settings = []): array } /** - * @return Mutation[] + * @return SimpleMutation[] */ private function getMutationsFromCode(string $code, array $settings): array { From 57eb6baa74db53f9c9f0203949e4eff76c63fed6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20FIDRY?= Date: Wed, 25 Mar 2020 15:52:50 +0100 Subject: [PATCH 13/21] Fix --- doc/nomenclature.md | 6 +++--- src/Configuration/ConfigurationFactory.php | 2 -- .../phpunit/AutoReview/ProjectCode/ProjectCodeProvider.php | 2 +- tests/phpunit/Mutator/BaseMutatorTestCase.php | 3 +-- 4 files changed, 5 insertions(+), 8 deletions(-) diff --git a/doc/nomenclature.md b/doc/nomenclature.md index 1d313d741..205656090 100644 --- a/doc/nomenclature.md +++ b/doc/nomenclature.md @@ -33,7 +33,7 @@ Process of creating a mutant from the original program. ### Mutant -New program that differs from the original by applying a mutation. +New program that differs from the original by applying a mutation. ### Mutation @@ -45,8 +45,8 @@ The result of applying a mutator to the AST of a subject and represents a change Define a possible transformation, which applied to the AST of a subject will result in a mutation. -In the Mutation Testing literature, mutators are also known as "mutant operator", -"mutagenic operator", "mutagen" and "mutation rule". +In the Mutation Testing literature, mutators are also known as "mutant operator", +"mutagenic operator", "mutagen" and "mutation rule". ## S diff --git a/src/Configuration/ConfigurationFactory.php b/src/Configuration/ConfigurationFactory.php index 98ca5fb81..8fb19a8ca 100644 --- a/src/Configuration/ConfigurationFactory.php +++ b/src/Configuration/ConfigurationFactory.php @@ -233,8 +233,6 @@ private static function retrieveCoverageBasePath( string $configDir, string $tmpDir ): string { - Assert::nullOrStringNotEmpty($existingCoveragePath); - if ($existingCoveragePath === null) { return $tmpDir; } diff --git a/tests/phpunit/AutoReview/ProjectCode/ProjectCodeProvider.php b/tests/phpunit/AutoReview/ProjectCode/ProjectCodeProvider.php index 5b22c522c..a6fcc59dd 100644 --- a/tests/phpunit/AutoReview/ProjectCode/ProjectCodeProvider.php +++ b/tests/phpunit/AutoReview/ProjectCode/ProjectCodeProvider.php @@ -35,7 +35,6 @@ namespace Infection\Tests\AutoReview\ProjectCode; -use Infection\Mutation\MutationAttributeKeys; use const DIRECTORY_SEPARATOR; use function in_array; use Infection\CannotBeInstantiated; @@ -60,6 +59,7 @@ use Infection\Http\StrykerDashboardClient; use Infection\Metrics\MetricsCalculator; use Infection\Mutation\DetectionStatus; +use Infection\Mutation\MutationAttributeKeys; use Infection\Mutator\NodeMutationGenerator; use Infection\Process\Builder\InitialTestRunProcessBuilder; use Infection\Resource\Memory\MemoryLimiterEnvironment; diff --git a/tests/phpunit/Mutator/BaseMutatorTestCase.php b/tests/phpunit/Mutator/BaseMutatorTestCase.php index abe64d112..947af1ce4 100644 --- a/tests/phpunit/Mutator/BaseMutatorTestCase.php +++ b/tests/phpunit/Mutator/BaseMutatorTestCase.php @@ -35,18 +35,17 @@ namespace Infection\Tests\Mutator; -use Infection\Tests\Fixtures\SimpleMutation; use function array_shift; use function count; use function escapeshellarg; use function exec; use function get_class; -use Infection\Mutation\Mutation; use Infection\Mutator\Mutator; use Infection\PhpParser\NodeTraverserFactory; use Infection\PhpParser\Visitor\CloneVisitor; use Infection\PhpParser\Visitor\MutatorVisitor; use Infection\Tests\AutoReview\SourceTestClassNameScheme; +use Infection\Tests\Fixtures\SimpleMutation; use Infection\Tests\Fixtures\SimpleMutationsCollectorVisitor; use Infection\Tests\SingletonContainer; use Infection\Tests\StringNormalizer; From 32a4908c32453b2ccf5e8218001105c12d00d94a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20FIDRY?= Date: Thu, 26 Mar 2020 10:20:16 +0100 Subject: [PATCH 14/21] Fix merge --- src/Configuration/ConfigurationFactory.php | 1 - src/Mutation/DetectionStatus.php | 2 -- 2 files changed, 3 deletions(-) diff --git a/src/Configuration/ConfigurationFactory.php b/src/Configuration/ConfigurationFactory.php index d9cf12dc8..99eb5900a 100644 --- a/src/Configuration/ConfigurationFactory.php +++ b/src/Configuration/ConfigurationFactory.php @@ -49,7 +49,6 @@ use Infection\TestFramework\TestFrameworkTypes; use function Safe\sprintf; use function sys_get_temp_dir; -use Webmozart\Assert\Assert; use Webmozart\PathUtil\Path; /** diff --git a/src/Mutation/DetectionStatus.php b/src/Mutation/DetectionStatus.php index 1bd82b643..4f7a78f2c 100644 --- a/src/Mutation/DetectionStatus.php +++ b/src/Mutation/DetectionStatus.php @@ -37,8 +37,6 @@ use Infection\CannotBeInstantiated; -use Infection\CannotBeInstantiated; - /** * @internal */ From 06556925cd29ec093a56da25c27b1718a2920ac3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20FIDRY?= Date: Fri, 27 Mar 2020 11:04:47 +0100 Subject: [PATCH 15/21] Remove the Mutation laziness --- src/Mutation/Mutation.php | 52 ++++++------ src/Mutation/MutationCalculatedState.php | 79 ------------------- src/Mutation/MutationFactory.php | 47 ++--------- tests/phpunit/Fixtures/SimpleMutation.php | 11 +-- .../Mutation/MutationCalculatedStateTest.php | 65 --------------- .../MutationExecutionResultFactoryTest.php | 61 +++++--------- .../Mutation/MutationExecutionResultTest.php | 13 +-- tests/phpunit/Mutation/MutationTest.php | 13 +-- .../Builder/MutationProcessFactoryTest.php | 13 +-- .../Runner/MutationTestingRunnerTest.php | 13 +-- 10 files changed, 70 insertions(+), 297 deletions(-) delete mode 100644 src/Mutation/MutationCalculatedState.php delete mode 100644 tests/phpunit/Mutation/MutationCalculatedStateTest.php diff --git a/src/Mutation/Mutation.php b/src/Mutation/Mutation.php index 0afe791ae..9b85e558b 100644 --- a/src/Mutation/Mutation.php +++ b/src/Mutation/Mutation.php @@ -53,23 +53,23 @@ class Mutation private $originalStartingLine; private $tests; private $executedByTests; - private $calculateState; - - /** - * @var MutationCalculatedState|null - */ - private $calculatedState; + private $mutationHash; + private $mutationFilePath; + private $mutatedCode; + private $diff; /** * @param TestLocation[] $tests - * @param Closure(): MutationCalculatedState $calculateState */ public function __construct( string $originalFilePath, string $mutatorName, int $originalStartingLine, array $tests, - Closure $calculateState + string $mutationHash, + string $mutationFilePath, + string $mutatedCode, + string $diff ) { Assert::oneOf($mutatorName, array_keys(ProfileList::ALL_MUTATORS)); @@ -78,12 +78,10 @@ public function __construct( $this->originalStartingLine = $originalStartingLine; $this->tests = $tests; $this->executedByTests = count($tests) > 0; - $this->calculateState = $calculateState; - } - - public function getFilePath(): string - { - return $this->getCalculatedState()->getMutationFilePath(); + $this->mutationHash = $mutationHash; + $this->mutationFilePath = $mutationFilePath; + $this->mutatedCode = $mutatedCode; + $this->diff = $diff; } public function getOriginalFilePath(): string @@ -106,16 +104,6 @@ public function hasTests(): bool return $this->executedByTests; } - public function getMutatedCode(): string - { - return $this->getCalculatedState()->getMutatedCode(); - } - - public function getDiff(): string - { - return $this->getCalculatedState()->getDiff(); - } - /** * @return TestLocation[] */ @@ -126,11 +114,21 @@ public function getTests(): array public function getHash(): string { - return $this->getCalculatedState()->getMutationHash(); + return $this->mutationHash; + } + + public function getFilePath(): string + { + return $this->mutationFilePath; + } + + public function getMutatedCode(): string + { + return $this->mutatedCode; } - private function getCalculatedState(): MutationCalculatedState + public function getDiff(): string { - return $this->calculatedState ?? $this->calculatedState = ($this->calculateState)(); + return $this->diff; } } diff --git a/src/Mutation/MutationCalculatedState.php b/src/Mutation/MutationCalculatedState.php deleted file mode 100644 index f0ed51ed8..000000000 --- a/src/Mutation/MutationCalculatedState.php +++ /dev/null @@ -1,79 +0,0 @@ -mutationHash = $mutationHash; - $this->mutationFilePath = $mutationFilePath; - $this->mutatedCode = $mutatedCode; - $this->diff = $diff; - } - - public function getMutationHash(): string - { - return $this->mutationHash; - } - - public function getMutationFilePath(): string - { - return $this->mutationFilePath; - } - - public function getMutatedCode(): string - { - return $this->mutatedCode; - } - - public function getDiff(): string - { - return $this->diff; - } -} diff --git a/src/Mutation/MutationFactory.php b/src/Mutation/MutationFactory.php index d577c5ac9..322c3f5da 100644 --- a/src/Mutation/MutationFactory.php +++ b/src/Mutation/MutationFactory.php @@ -97,47 +97,6 @@ public function create( $attributes = array_intersect_key($attributes, array_flip(MutationAttributeKeys::ALL)); - return new Mutation( - $originalFilePath, - $mutatorName, - (int) $attributes[MutationAttributeKeys::START_LINE], - $tests, - function () use ( - $originalFilePath, - $originalFileAst, - $mutatorName, - $attributes, - $mutatedNodeClass, - $mutatedNode, - $mutationByMutatorIndex - ): MutationCalculatedState { - return $this->calculateState( - $originalFilePath, - $originalFileAst, - $mutatorName, - $attributes, - $mutatedNodeClass, - $mutatedNode, - $mutationByMutatorIndex - ); - } - ); - } - - /** - * @param Node[] $originalFileAst - * @param array $attributes - * @param class-string $mutatedNodeClass - */ - private function calculateState( - string $originalFilePath, - array $originalFileAst, - string $mutatorName, - array $attributes, - string $mutatedNodeClass, - MutatedNode $mutatedNode, - int $mutationByMutatorIndex - ): MutationCalculatedState { $hash = self::createHash( $originalFilePath, $mutatorName, @@ -158,7 +117,11 @@ private function calculateState( $mutatedNode ); - return new MutationCalculatedState( + return new Mutation( + $originalFilePath, + $mutatorName, + (int) $attributes[MutationAttributeKeys::START_LINE], + $tests, $hash, $mutationFilePath, $mutatedCode, diff --git a/tests/phpunit/Fixtures/SimpleMutation.php b/tests/phpunit/Fixtures/SimpleMutation.php index 3339ea1bb..926c451ec 100644 --- a/tests/phpunit/Fixtures/SimpleMutation.php +++ b/tests/phpunit/Fixtures/SimpleMutation.php @@ -6,16 +6,12 @@ use Infection\Mutation\Mutation; use Infection\Mutation\MutationAttributeKeys; -use Infection\Mutation\MutationCalculatedState; -use Infection\Mutator\Mutator; use Infection\PhpParser\MutatedNode; -use Infection\Tests\UnsupportedMethod; use PhpParser\Node; class SimpleMutation extends Mutation { private $originalFileAst; - private $mutator; private $mutatedNode; private $attributes; private $mutatedNodeClass; @@ -38,9 +34,10 @@ public function __construct( $mutatorName, (int) $attributes[MutationAttributeKeys::START_LINE], [], - static function (): MutationCalculatedState { - throw UnsupportedMethod::method(Mutation::class, 'calculateState'); - } + 'hash', + '/path/to/MutatedFoo.php', + 'mutatedCode', + 'diff' ); $this->originalFileAst = $originalFileAst; diff --git a/tests/phpunit/Mutation/MutationCalculatedStateTest.php b/tests/phpunit/Mutation/MutationCalculatedStateTest.php deleted file mode 100644 index 60e2baf7b..000000000 --- a/tests/phpunit/Mutation/MutationCalculatedStateTest.php +++ /dev/null @@ -1,65 +0,0 @@ -assertSame($hash, $state->getMutationHash()); - $this->assertSame($filePath, $state->getMutationFilePath()); - $this->assertSame($code, $state->getMutatedCode()); - $this->assertSame($diff, $state->getDiff()); - } -} diff --git a/tests/phpunit/Mutation/MutationExecutionResultFactoryTest.php b/tests/phpunit/Mutation/MutationExecutionResultFactoryTest.php index 1cfac0fd2..0f091b5fa 100644 --- a/tests/phpunit/Mutation/MutationExecutionResultFactoryTest.php +++ b/tests/phpunit/Mutation/MutationExecutionResultFactoryTest.php @@ -39,7 +39,6 @@ use Infection\AbstractTestFramework\TestFrameworkAdapter; use Infection\Mutation\DetectionStatus; use Infection\Mutation\Mutation; -use Infection\Mutation\MutationCalculatedState; use Infection\Mutation\MutationExecutionResultFactory; use Infection\Mutator\ZeroIteration\For_; use Infection\Process\MutationProcess; @@ -109,14 +108,10 @@ public function test_it_can_create_a_result_from_a_non_covered_mutation_process( $mutatorName = MutatorName::getName(For_::class), $originalStartingLine = 10, [], - static function () use ($mutationDiff): MutationCalculatedState { - return new MutationCalculatedState( - '0800f', - '/path/to/mutation', - 'notCovered#0', - $mutationDiff - ); - } + '0800f', + '/path/to/mutation', + 'notCovered#0', + $mutationDiff ) ); @@ -178,14 +173,10 @@ public function test_it_can_create_a_result_from_a_timed_out_mutation_process(): 0.01 ), ], - static function () use ($mutationDiff): MutationCalculatedState { - return new MutationCalculatedState( - '0800f', - '/path/to/mutation', - 'timedOut#0', - $mutationDiff - ); - } + '0800f', + '/path/to/mutation', + 'timedOut#0', + $mutationDiff ) ); @@ -254,14 +245,10 @@ public function test_it_can_create_a_result_from_an_errored_mutation_process(): 0.01 ), ], - static function () use ($mutationDiff): MutationCalculatedState { - return new MutationCalculatedState( - '0800f', - '/path/to/mutation', - 'errored#0', - $mutationDiff - ); - } + '0800f', + '/path/to/mutation', + 'errored#0', + $mutationDiff ) ); @@ -330,14 +317,10 @@ public function test_it_can_crate_a_result_from_an_escaped_mutation_process(): v 0.01 ), ], - static function () use ($mutationDiff): MutationCalculatedState { - return new MutationCalculatedState( - '0800f', - '/path/to/mutation', - 'escaped#0', - $mutationDiff - ); - } + '0800f', + '/path/to/mutation', + 'escaped#0', + $mutationDiff ) ); @@ -406,14 +389,10 @@ public function test_it_can_crate_a_result_from_a_killed_mutation_process(): voi 0.01 ), ], - static function () use ($mutationDiff): MutationCalculatedState { - return new MutationCalculatedState( - '0800f', - '/path/to/mutation', - 'killed#0', - $mutationDiff - ); - } + '0800f', + '/path/to/mutation', + 'killed#0', + $mutationDiff ) ); diff --git a/tests/phpunit/Mutation/MutationExecutionResultTest.php b/tests/phpunit/Mutation/MutationExecutionResultTest.php index 968c31451..5e3bf20f9 100644 --- a/tests/phpunit/Mutation/MutationExecutionResultTest.php +++ b/tests/phpunit/Mutation/MutationExecutionResultTest.php @@ -38,7 +38,6 @@ use Infection\AbstractTestFramework\Coverage\TestLocation; use Infection\Mutation\DetectionStatus; use Infection\Mutation\Mutation; -use Infection\Mutation\MutationCalculatedState; use Infection\Mutation\MutationExecutionResult; use Infection\Mutator\ZeroIteration\For_; use Infection\Tests\Mutator\MutatorName; @@ -110,14 +109,10 @@ public function test_it_can_be_instantiated_from_a_mutation_non_executed_by_test 0.01 ), ], - static function () use ($mutationDiff): MutationCalculatedState { - return new MutationCalculatedState( - '0800f', - '/path/to/mutation', - 'notCovered#0', - $mutationDiff - ); - } + '0800f', + '/path/to/mutation', + 'notCovered#0', + $mutationDiff ); $this->assertResultStateIs( diff --git a/tests/phpunit/Mutation/MutationTest.php b/tests/phpunit/Mutation/MutationTest.php index d918f3a93..e98853a3c 100644 --- a/tests/phpunit/Mutation/MutationTest.php +++ b/tests/phpunit/Mutation/MutationTest.php @@ -37,7 +37,6 @@ use Infection\AbstractTestFramework\Coverage\TestLocation; use Infection\Mutation\Mutation; -use Infection\Mutation\MutationCalculatedState; use Infection\Mutator\Arithmetic\Plus; use Infection\Tests\Mutator\MutatorName; use PHPUnit\Framework\TestCase; @@ -65,14 +64,10 @@ public function test_it_can_be_instantiated( $mutatorName, $originalStartingLine, $tests, - static function () use ($hash, $filePath, $code, $diff): MutationCalculatedState { - return new MutationCalculatedState( - $hash, - $filePath, - $code, - $diff - ); - } + $hash, + $filePath, + $code, + $diff ); $this->assertSame($originalFilePath, $mutation->getOriginalFilePath()); diff --git a/tests/phpunit/Process/Builder/MutationProcessFactoryTest.php b/tests/phpunit/Process/Builder/MutationProcessFactoryTest.php index dc742ca89..3e1ceee26 100644 --- a/tests/phpunit/Process/Builder/MutationProcessFactoryTest.php +++ b/tests/phpunit/Process/Builder/MutationProcessFactoryTest.php @@ -40,7 +40,6 @@ use Infection\AbstractTestFramework\TestFrameworkAdapter; use Infection\Event\MutationProcessWasFinished; use Infection\Mutation\Mutation; -use Infection\Mutation\MutationCalculatedState; use Infection\Mutation\MutationExecutionResult; use Infection\Mutation\MutationExecutionResultFactory; use Infection\Mutator\ZeroIteration\For_; @@ -68,12 +67,10 @@ public function test_it_creates_a_process_with_timeout(): void 0.01 ), ], - static function () use ($hash, $mutationFilePath): MutationCalculatedState { - return new MutationCalculatedState( - $hash, - $mutationFilePath, - 'notCovered#0', - <<<'DIFF' + $hash, + $mutationFilePath, + 'notCovered#0', + <<<'DIFF' --- Original +++ New @@ @@ @@ -82,8 +79,6 @@ static function () use ($hash, $mutationFilePath): MutationCalculatedState { + echo 'killed#0'; DIFF - ); - } ); $testFrameworkExtraOptions = '--verbose'; diff --git a/tests/phpunit/Process/Runner/MutationTestingRunnerTest.php b/tests/phpunit/Process/Runner/MutationTestingRunnerTest.php index afb7f0943..e9e6ea05d 100644 --- a/tests/phpunit/Process/Runner/MutationTestingRunnerTest.php +++ b/tests/phpunit/Process/Runner/MutationTestingRunnerTest.php @@ -44,7 +44,6 @@ use Infection\Event\MutationTestingWasFinished; use Infection\Event\MutationTestingWasStarted; use Infection\Mutation\Mutation; -use Infection\Mutation\MutationCalculatedState; use Infection\Mutator\ZeroIteration\For_; use Infection\Process\Builder\MutationProcessFactory; use Infection\Process\MutationProcess; @@ -423,14 +422,10 @@ private function createMutation(int $i): Mutation 0.01 ), ], - static function () use ($i): MutationCalculatedState { - return new MutationCalculatedState( - 'mutationHash#' . $i, - '/path/to/mutation' . $i . '.php', - 'mutated code ' . $i, - 'diff' - ); - } + 'mutationHash#' . $i, + '/path/to/mutation' . $i . '.php', + 'mutated code ' . $i, + 'diff' ); } } From 6830cd645b0f33057b67d28cd6eadc9c802fd151 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20FIDRY?= Date: Fri, 27 Mar 2020 12:08:07 +0100 Subject: [PATCH 16/21] Fix CS --- src/Mutation/Mutation.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Mutation/Mutation.php b/src/Mutation/Mutation.php index 9b85e558b..a98b62d97 100644 --- a/src/Mutation/Mutation.php +++ b/src/Mutation/Mutation.php @@ -36,7 +36,6 @@ namespace Infection\Mutation; use function array_keys; -use Closure; use function count; use Infection\AbstractTestFramework\Coverage\TestLocation; use Infection\Mutator\ProfileList; From 4437597a88670bb14c6c3bd677b57ee78c995493 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20FIDRY?= Date: Fri, 3 Apr 2020 12:21:29 +0200 Subject: [PATCH 17/21] Revert ConfigurationFactory change --- src/Configuration/ConfigurationFactory.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Configuration/ConfigurationFactory.php b/src/Configuration/ConfigurationFactory.php index 99eb5900a..8402798a3 100644 --- a/src/Configuration/ConfigurationFactory.php +++ b/src/Configuration/ConfigurationFactory.php @@ -49,6 +49,7 @@ use Infection\TestFramework\TestFrameworkTypes; use function Safe\sprintf; use function sys_get_temp_dir; +use Webmozart\Assert\Assert; use Webmozart\PathUtil\Path; /** @@ -213,6 +214,8 @@ private static function retrieveCoverageBasePath( string $configDir, string $tmpDir ): string { + Assert::nullOrStringNotEmpty($existingCoveragePath); + if ($existingCoveragePath === null) { return $tmpDir; } From d73602d6a73bcd0228678a52bdba739455f4cfe8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20FIDRY?= Date: Fri, 3 Apr 2020 12:48:44 +0200 Subject: [PATCH 18/21] Revert name changes --- .../ValueProvider/ExcludeDirsProvider.php | 2 +- .../AbstractOutputFormatter.php | 4 +- src/Console/OutputFormatter/DotFormatter.php | 6 +-- .../OutputFormatter/OutputFormatter.php | 4 +- .../OutputFormatter/ProgressFormatter.php | 4 +- src/Container.php | 32 ++++++------- src/Engine.php | 4 +- ...ished.php => MutantProcessWasFinished.php} | 8 ++-- ...ationGeneratingConsoleLoggerSubscriber.php | 2 +- ...ationGeneratingConsoleLoggerSubscriber.php | 2 +- ...MutationTestingConsoleLoggerSubscriber.php | 14 +++--- src/Logger/DebugFileLogger.php | 6 +-- src/Logger/PerMutatorLogger.php | 2 +- src/Logger/SummaryFileLogger.php | 2 +- src/Logger/TextFileLogger.php | 6 +-- src/Metrics/Calculator.php | 2 +- src/Metrics/MetricsCalculator.php | 38 +++++++-------- ...php => SortableMutantExecutionResults.php} | 14 +++--- src/{Mutation => Mutant}/DetectionStatus.php | 2 +- .../MutantCodeFactory.php} | 4 +- .../MutantExecutionResult.php} | 5 +- ...y.php => MutantExecutionResultFactory.php} | 18 ++++---- src/Mutation/MutationFactory.php | 9 ++-- src/Mutator/MutatorParser.php | 2 +- ...ssFactory.php => MutantProcessFactory.php} | 24 +++++----- ...{MutationProcess.php => MutantProcess.php} | 2 +- src/Process/Runner/MutationTestingRunner.php | 12 ++--- .../AbstractTestFrameworkAdapter.php | 10 ++-- .../Config/MutationConfigBuilder.php | 2 +- .../Config/Builder/MutationConfigBuilder.php | 5 +- .../TestFrameworkExtraOptionsFilter.php | 2 +- .../ProjectCode/ProjectCodeProvider.php | 2 +- .../OutputFormatter/DotFormatterTest.php | 22 ++++----- ...t.php => MutantProcessWasFinishedTest.php} | 10 ++-- ...nitialTestsConsoleLoggerSubscriberTest.php | 2 +- ...nGeneratingConsoleLoggerSubscriberTest.php | 2 +- ...tionTestingConsoleLoggerSubscriberTest.php | 8 ++-- .../Logger/CreateMetricsCalculator.php | 8 ++-- .../phpunit/Metrics/MetricsCalculatorTest.php | 14 +++--- ...=> SortableMutantExecutionResultsTest.php} | 20 ++++---- .../MutantCodeFactoryTest.php} | 12 ++--- .../MutantExecutionResultTest.php} | 14 +++--- ...hp => MutantExecutionResultAssertions.php} | 6 +-- ...p => MutantExecutionResultFactoryTest.php} | 46 +++++++++---------- .../phpunit/Mutation/MutationFactoryTest.php | 6 +-- tests/phpunit/Mutator/MutatorParserTest.php | 2 +- ...yTest.php => MutantProcessFactoryTest.php} | 18 ++++---- ...nProcessTest.php => MutantProcessTest.php} | 10 ++-- .../Runner/MutationTestingRunnerTest.php | 12 ++--- .../TestFrameworkExtraOptionsFilterTest.php | 8 ++-- 50 files changed, 237 insertions(+), 234 deletions(-) rename src/Event/{MutationProcessWasFinished.php => MutantProcessWasFinished.php} (89%) rename src/Metrics/{SortableMutationExecutionResults.php => SortableMutantExecutionResults.php} (87%) rename src/{Mutation => Mutant}/DetectionStatus.php (98%) rename src/{Mutation/MutationCodeFactory.php => Mutant/MutantCodeFactory.php} (97%) rename src/{Mutation/MutationExecutionResult.php => Mutant/MutantExecutionResult.php} (97%) rename src/Mutation/{MutationExecutionResultFactory.php => MutantExecutionResultFactory.php} (86%) rename src/Process/Builder/{MutationProcessFactory.php => MutantProcessFactory.php} (84%) rename src/Process/{MutationProcess.php => MutantProcess.php} (98%) rename tests/phpunit/Event/{MutationProcessWasFinishedTest.php => MutantProcessWasFinishedTest.php} (85%) rename tests/phpunit/Metrics/{SortableMutationExecutionResultsTest.php => SortableMutantExecutionResultsTest.php} (91%) rename tests/phpunit/{Mutation/MutationCodeFactoryTest.php => Mutant/MutantCodeFactoryTest.php} (96%) rename tests/phpunit/{Mutation/MutationExecutionResultTest.php => Mutant/MutantExecutionResultTest.php} (93%) rename tests/phpunit/Mutation/{MutationExecutionResultAssertions.php => MutantExecutionResultAssertions.php} (95%) rename tests/phpunit/Mutation/{MutationExecutionResultFactoryTest.php => MutantExecutionResultFactoryTest.php} (90%) rename tests/phpunit/Process/Builder/{MutationProcessFactoryTest.php => MutantProcessFactoryTest.php} (89%) rename tests/phpunit/Process/{MutationProcessTest.php => MutantProcessTest.php} (93%) diff --git a/src/Config/ValueProvider/ExcludeDirsProvider.php b/src/Config/ValueProvider/ExcludeDirsProvider.php index bba913f24..da16e561f 100644 --- a/src/Config/ValueProvider/ExcludeDirsProvider.php +++ b/src/Config/ValueProvider/ExcludeDirsProvider.php @@ -75,7 +75,7 @@ public function get(InputInterface $input, OutputInterface $output, array $dirsI { $output->writeln([ '', - 'There can be situations when you want to exclude some folders from generating mutations.', + 'There can be situations when you want to exclude some folders from generating mutants.', 'You can use glob pattern (*Bundle/**/*/Tests) for them or just regular dir path.', 'It should be relative to the source directory.', 'You should not mutate test suite files.', diff --git a/src/Console/OutputFormatter/AbstractOutputFormatter.php b/src/Console/OutputFormatter/AbstractOutputFormatter.php index ce42d5e62..bcc6a7d6c 100644 --- a/src/Console/OutputFormatter/AbstractOutputFormatter.php +++ b/src/Console/OutputFormatter/AbstractOutputFormatter.php @@ -35,7 +35,7 @@ namespace Infection\Console\OutputFormatter; -use Infection\Mutation\MutationExecutionResult; +use Infection\Mutant\MutantExecutionResult; /** * @internal @@ -59,7 +59,7 @@ public function start(int $mutationCount): void $this->callsCount = 0; } - public function advance(MutationExecutionResult $executionResult, int $mutationCount): void + public function advance(MutantExecutionResult $executionResult, int $mutationCount): void { ++$this->callsCount; } diff --git a/src/Console/OutputFormatter/DotFormatter.php b/src/Console/OutputFormatter/DotFormatter.php index 2e87f670f..d557888ab 100644 --- a/src/Console/OutputFormatter/DotFormatter.php +++ b/src/Console/OutputFormatter/DotFormatter.php @@ -35,8 +35,8 @@ namespace Infection\Console\OutputFormatter; -use Infection\Mutation\DetectionStatus; -use Infection\Mutation\MutationExecutionResult; +use Infection\Mutant\DetectionStatus; +use Infection\Mutant\MutantExecutionResult; use function Safe\sprintf; use function str_repeat; use function strlen; @@ -71,7 +71,7 @@ public function start(int $mutationCount): void ]); } - public function advance(MutationExecutionResult $executionResult, int $mutationCount): void + public function advance(MutantExecutionResult $executionResult, int $mutationCount): void { parent::advance($executionResult, $mutationCount); diff --git a/src/Console/OutputFormatter/OutputFormatter.php b/src/Console/OutputFormatter/OutputFormatter.php index 2e5e7e964..65fdf0b1a 100644 --- a/src/Console/OutputFormatter/OutputFormatter.php +++ b/src/Console/OutputFormatter/OutputFormatter.php @@ -35,7 +35,7 @@ namespace Infection\Console\OutputFormatter; -use Infection\Mutation\MutationExecutionResult; +use Infection\Mutant\MutantExecutionResult; interface OutputFormatter { @@ -47,7 +47,7 @@ public function start(int $mutationCount): void; /** * Triggered each time mutation process is finished for one Mutant */ - public function advance(MutationExecutionResult $executionResult, int $mutationCount): void; + public function advance(MutantExecutionResult $executionResult, int $mutationCount): void; /** * Triggered when mutation testing is finished diff --git a/src/Console/OutputFormatter/ProgressFormatter.php b/src/Console/OutputFormatter/ProgressFormatter.php index 2d98e5deb..8645c2b13 100644 --- a/src/Console/OutputFormatter/ProgressFormatter.php +++ b/src/Console/OutputFormatter/ProgressFormatter.php @@ -35,7 +35,7 @@ namespace Infection\Console\OutputFormatter; -use Infection\Mutation\MutationExecutionResult; +use Infection\Mutant\MutantExecutionResult; use Symfony\Component\Console\Helper\ProgressBar; /** @@ -57,7 +57,7 @@ public function start(int $mutationCount): void $this->progressBar->start($mutationCount); } - public function advance(MutationExecutionResult $executionResult, int $mutationCount): void + public function advance(MutantExecutionResult $executionResult, int $mutationCount): void { parent::advance($executionResult, $mutationCount); diff --git a/src/Container.php b/src/Container.php index 3573454ac..ba074022d 100644 --- a/src/Container.php +++ b/src/Container.php @@ -62,10 +62,10 @@ use Infection\Logger\LoggerFactory; use Infection\Metrics\MetricsCalculator; use Infection\Metrics\MinMsiChecker; +use Infection\Mutant\MutantCodeFactory; use Infection\Mutation\FileMutationGenerator; +use Infection\Mutation\MutantExecutionResultFactory; use Infection\Mutation\MutationAttributeKeys; -use Infection\Mutation\MutationCodeFactory; -use Infection\Mutation\MutationExecutionResultFactory; use Infection\Mutation\MutationFactory; use Infection\Mutation\MutationGenerator; use Infection\Mutator\MutatorFactory; @@ -74,7 +74,7 @@ use Infection\PhpParser\FileParser; use Infection\PhpParser\NodeTraverserFactory; use Infection\Process\Builder\InitialTestRunProcessBuilder; -use Infection\Process\Builder\MutationProcessFactory; +use Infection\Process\Builder\MutantProcessFactory; use Infection\Process\Builder\SubscriberBuilder; use Infection\Process\Runner\DryProcessRunner; use Infection\Process\Runner\InitialTestsRunner; @@ -221,15 +221,15 @@ public static function create(): self GeneratedExtensionsConfig::EXTENSIONS ); }, - MutationCodeFactory::class => static function (self $container): MutationCodeFactory { - return new MutationCodeFactory($container->getPrinter()); + MutantCodeFactory::class => static function (self $container): MutantCodeFactory { + return new MutantCodeFactory($container->getPrinter()); }, MutationFactory::class => static function (self $container): MutationFactory { return new MutationFactory( $container->getConfiguration()->getTmpDir(), $container->getDiffer(), $container->getPrinter(), - $container->getMutationCodeFactory() + $container->getMutantCodeFactory() ); }, Differ::class => static function (): Differ { @@ -432,8 +432,8 @@ public static function create(): self $container->getEventDispatcher() ); }, - MutationProcessFactory::class => static function (self $container): MutationProcessFactory { - return new MutationProcessFactory( + MutantProcessFactory::class => static function (self $container): MutantProcessFactory { + return new MutantProcessFactory( $container->getTestFrameworkAdapter(), $container->getConfiguration()->getProcessTimeout(), $container->getEventDispatcher(), @@ -477,8 +477,8 @@ public static function create(): self AdapterInstaller::class => static function (): AdapterInstaller { return new AdapterInstaller(new ComposerExecutableFinder()); }, - MutationExecutionResultFactory::class => static function (self $container): MutationExecutionResultFactory { - return new MutationExecutionResultFactory($container->getTestFrameworkAdapter()); + MutantExecutionResultFactory::class => static function (self $container): MutantExecutionResultFactory { + return new MutantExecutionResultFactory($container->getTestFrameworkAdapter()); }, ]); } @@ -649,9 +649,9 @@ public function getFactory(): Factory return $this->get(Factory::class); } - public function getMutationCodeFactory(): MutationCodeFactory + public function getMutantCodeFactory(): MutantCodeFactory { - return $this->get(MutationCodeFactory::class); + return $this->get(MutantCodeFactory::class); } public function getMutationFactory(): MutationFactory @@ -834,9 +834,9 @@ public function getInitialTestsRunner(): InitialTestsRunner return $this->get(InitialTestsRunner::class); } - public function getMutationProcessFactory(): MutationProcessFactory + public function getMutationProcessFactory(): MutantProcessFactory { - return $this->get(MutationProcessFactory::class); + return $this->get(MutantProcessFactory::class); } public function getMutationGenerator(): MutationGenerator @@ -884,9 +884,9 @@ public function getAdapterInstaller(): AdapterInstaller return $this->get(AdapterInstaller::class); } - public function getMutationExecutionResultFactory(): MutationExecutionResultFactory + public function getMutationExecutionResultFactory(): MutantExecutionResultFactory { - return $this->get(MutationExecutionResultFactory::class); + return $this->get(MutantExecutionResultFactory::class); } /** diff --git a/src/Engine.php b/src/Engine.php index e3810b5db..8cf28368a 100644 --- a/src/Engine.php +++ b/src/Engine.php @@ -110,7 +110,7 @@ public function execute(): void $this->runMutationAnalysis(); $this->minMsiChecker->checkMetrics( - $this->metricsCalculator->getTotalMutationsCount(), + $this->metricsCalculator->getTotalMutantsCount(), $this->metricsCalculator->getMutationScoreIndicator(), $this->metricsCalculator->getCoveredCodeMutationScoreIndicator(), $this->consoleOutput @@ -160,7 +160,7 @@ private function runMutationAnalysis(): void $extraOptions = $this->config->getTestFrameworkExtraOptions(); $mutationExtraOptions = $this->adapter instanceof ProvidesInitialRunOnlyOptions - ? $this->testFrameworkExtraOptionsFilter->filterForMutationProcess( + ? $this->testFrameworkExtraOptionsFilter->filterForMutantProcess( $extraOptions, $this->adapter->getInitialRunOnlyOptions() ) diff --git a/src/Event/MutationProcessWasFinished.php b/src/Event/MutantProcessWasFinished.php similarity index 89% rename from src/Event/MutationProcessWasFinished.php rename to src/Event/MutantProcessWasFinished.php index 6b0f8e166..0e488f7b9 100644 --- a/src/Event/MutationProcessWasFinished.php +++ b/src/Event/MutantProcessWasFinished.php @@ -35,21 +35,21 @@ namespace Infection\Event; -use Infection\Mutation\MutationExecutionResult; +use Infection\Mutant\MutantExecutionResult; /** * @internal */ -final class MutationProcessWasFinished +final class MutantProcessWasFinished { private $executionResult; - public function __construct(MutationExecutionResult $executionResult) + public function __construct(MutantExecutionResult $executionResult) { $this->executionResult = $executionResult; } - public function getExecutionResult(): MutationExecutionResult + public function getExecutionResult(): MutantExecutionResult { return $this->executionResult; } diff --git a/src/Event/Subscriber/CiMutationGeneratingConsoleLoggerSubscriber.php b/src/Event/Subscriber/CiMutationGeneratingConsoleLoggerSubscriber.php index aa3a993be..5a8e4b05c 100644 --- a/src/Event/Subscriber/CiMutationGeneratingConsoleLoggerSubscriber.php +++ b/src/Event/Subscriber/CiMutationGeneratingConsoleLoggerSubscriber.php @@ -55,7 +55,7 @@ public function onMutationGenerationWasStarted(MutationGenerationWasStarted $eve { $this->output->writeln([ '', - 'Generate mutations...', + 'Generate mutants...', '', sprintf('Processing source code files: %s', $event->getMutableFilesCount()), ]); diff --git a/src/Event/Subscriber/MutationGeneratingConsoleLoggerSubscriber.php b/src/Event/Subscriber/MutationGeneratingConsoleLoggerSubscriber.php index a0ce162c8..9e8df10d3 100644 --- a/src/Event/Subscriber/MutationGeneratingConsoleLoggerSubscriber.php +++ b/src/Event/Subscriber/MutationGeneratingConsoleLoggerSubscriber.php @@ -59,7 +59,7 @@ public function __construct(OutputInterface $output) public function onMutationGenerationWasStarted(MutationGenerationWasStarted $event): void { - $this->output->writeln(['', '', 'Generate mutations...', '']); + $this->output->writeln(['', '', 'Generate mutants...', '']); $this->progressBar->start($event->getMutableFilesCount()); } diff --git a/src/Event/Subscriber/MutationTestingConsoleLoggerSubscriber.php b/src/Event/Subscriber/MutationTestingConsoleLoggerSubscriber.php index 97a573db6..da72885d4 100644 --- a/src/Event/Subscriber/MutationTestingConsoleLoggerSubscriber.php +++ b/src/Event/Subscriber/MutationTestingConsoleLoggerSubscriber.php @@ -38,11 +38,11 @@ use function floor; use Infection\Console\OutputFormatter\OutputFormatter; use Infection\Differ\DiffColorizer; -use Infection\Event\MutationProcessWasFinished; +use Infection\Event\MutantProcessWasFinished; use Infection\Event\MutationTestingWasFinished; use Infection\Event\MutationTestingWasStarted; use Infection\Metrics\MetricsCalculator; -use Infection\Mutation\MutationExecutionResult; +use Infection\Mutant\MutantExecutionResult; use function Safe\sprintf; use function str_pad; use function str_repeat; @@ -81,14 +81,14 @@ public function __construct( $this->diffColorizer = $diffColorizer; } - public function onMutationTestingWasStarted(MutationTestingWasStarted $event): void + public function onMutationProcessWasFinished(MutationTestingWasStarted $event): void { $this->mutationCount = $event->getMutationCount(); $this->outputFormatter->start($this->mutationCount); } - public function onMutationProcessWasFinished(MutationProcessWasFinished $event): void + public function MutantProcessWasFinished(MutantProcessWasFinished $event): void { $executionResult = $event->getExecutionResult(); @@ -113,11 +113,11 @@ public function onMutationTestingWasFinished(MutationTestingWasFinished $event): } /** - * @param MutationExecutionResult[] $executionResults + * @param MutantExecutionResult[] $executionResults */ private function showMutations(array $executionResults, string $headlinePrefix): void { - $headline = sprintf('%s mutations:', $headlinePrefix); + $headline = sprintf('%s mutants:', $headlinePrefix); $this->output->writeln([ '', @@ -145,7 +145,7 @@ private function showMutations(array $executionResults, string $headlinePrefix): private function showMetrics(): void { $this->output->writeln(['', '']); - $this->output->writeln('' . $this->metricsCalculator->getTotalMutationsCount() . ' mutations were generated:'); + $this->output->writeln('' . $this->metricsCalculator->getTotalMutantsCount() . ' mutations were generated:'); $this->output->writeln('' . $this->getPadded($this->metricsCalculator->getKilledCount()) . ' mutants were killed'); $this->output->writeln('' . $this->getPadded($this->metricsCalculator->getNotTestedCount()) . ' mutants were not covered by tests'); $this->output->writeln('' . $this->getPadded($this->metricsCalculator->getEscapedCount()) . ' covered mutants were not detected'); diff --git a/src/Logger/DebugFileLogger.php b/src/Logger/DebugFileLogger.php index 15aec3e97..ce267e1c0 100644 --- a/src/Logger/DebugFileLogger.php +++ b/src/Logger/DebugFileLogger.php @@ -37,7 +37,7 @@ use function implode; use Infection\Metrics\MetricsCalculator; -use Infection\Mutation\MutationExecutionResult; +use Infection\Mutant\MutantExecutionResult; use const PHP_EOL; use function Safe\sprintf; use function str_repeat; @@ -66,7 +66,7 @@ public function getLogLines(): array $logs = []; - $logs[] = 'Total: ' . $this->metricsCalculator->getTotalMutationsCount(); + $logs[] = 'Total: ' . $this->metricsCalculator->getTotalMutantsCount(); $logs[] = ''; $logs[] = $this->getResultsLine( $this->metricsCalculator->getKilledExecutionResults(), @@ -105,7 +105,7 @@ public function getLogLines(): array } /** - * @param MutationExecutionResult[] $executionResults + * @param MutantExecutionResult[] $executionResults */ private function getResultsLine( array $executionResults, diff --git a/src/Logger/PerMutatorLogger.php b/src/Logger/PerMutatorLogger.php index 038fefea8..149844263 100644 --- a/src/Logger/PerMutatorLogger.php +++ b/src/Logger/PerMutatorLogger.php @@ -76,7 +76,7 @@ public function getLogLines(): array /* @var MetricsCalculator $calculator */ $table[] = [ $mutatorName, - (string) $calculator->getTotalMutationsCount(), + (string) $calculator->getTotalMutantsCount(), (string) $calculator->getKilledCount(), (string) $calculator->getEscapedCount(), (string) $calculator->getErrorCount(), diff --git a/src/Logger/SummaryFileLogger.php b/src/Logger/SummaryFileLogger.php index a5b01b0cc..8a5dcbc73 100644 --- a/src/Logger/SummaryFileLogger.php +++ b/src/Logger/SummaryFileLogger.php @@ -55,7 +55,7 @@ public function __construct(MetricsCalculator $metricsCalculator) public function getLogLines(): array { return [ - 'Total: ' . $this->metricsCalculator->getTotalMutationsCount(), + 'Total: ' . $this->metricsCalculator->getTotalMutantsCount(), '', 'Killed: ' . $this->metricsCalculator->getKilledCount(), 'Errored: ' . $this->metricsCalculator->getErrorCount(), diff --git a/src/Logger/TextFileLogger.php b/src/Logger/TextFileLogger.php index e12c29712..5ae03179d 100644 --- a/src/Logger/TextFileLogger.php +++ b/src/Logger/TextFileLogger.php @@ -39,7 +39,7 @@ use function explode; use function implode; use Infection\Metrics\MetricsCalculator; -use Infection\Mutation\MutationExecutionResult; +use Infection\Mutant\MutantExecutionResult; use Infection\Str; use const PHP_EOL; use function Safe\sprintf; @@ -112,7 +112,7 @@ public function getLogLines(): array } /** - * @param MutationExecutionResult[] $executionResults + * @param MutantExecutionResult[] $executionResults */ private function getResultsLine( array $executionResults, @@ -173,7 +173,7 @@ private static function getHeadlineLines(string $headlinePrefix): string ); } - private static function getMutatorLine(int $index, MutationExecutionResult $mutantProcess): string + private static function getMutatorLine(int $index, MutantExecutionResult $mutantProcess): string { return sprintf( '%d) %s:%d [M] %s', diff --git a/src/Metrics/Calculator.php b/src/Metrics/Calculator.php index a3b7b6e6e..24fac73e7 100644 --- a/src/Metrics/Calculator.php +++ b/src/Metrics/Calculator.php @@ -89,7 +89,7 @@ public static function fromMetrics(MetricsCalculator $calculator): self $calculator->getErrorCount(), $calculator->getTimedOutCount(), $calculator->getNotTestedCount(), - $calculator->getTotalMutationsCount() + $calculator->getTotalMutantsCount() ); } diff --git a/src/Metrics/MetricsCalculator.php b/src/Metrics/MetricsCalculator.php index e90d79196..9d9a305db 100644 --- a/src/Metrics/MetricsCalculator.php +++ b/src/Metrics/MetricsCalculator.php @@ -36,8 +36,8 @@ namespace Infection\Metrics; use function count; -use Infection\Mutation\DetectionStatus; -use Infection\Mutation\MutationExecutionResult; +use Infection\Mutant\DetectionStatus; +use Infection\Mutant\MutantExecutionResult; use InvalidArgumentException; use function Safe\sprintf; @@ -77,7 +77,7 @@ class MetricsCalculator /** * @var int */ - private $notExecutedByTestsCount = 0; + private $notCoveredByTestsCount = 0; /** * @var int @@ -92,15 +92,15 @@ class MetricsCalculator public function __construct(int $roundingPrecision) { $this->roundingPrecision = $roundingPrecision; - $this->killedExecutionResults = new SortableMutationExecutionResults(); - $this->errorExecutionResults = new SortableMutationExecutionResults(); - $this->escapedExecutionResults = new SortableMutationExecutionResults(); - $this->timedOutExecutionResults = new SortableMutationExecutionResults(); - $this->notCoveredExecutionResults = new SortableMutationExecutionResults(); - $this->allExecutionResults = new SortableMutationExecutionResults(); + $this->killedExecutionResults = new SortableMutantExecutionResults(); + $this->errorExecutionResults = new SortableMutantExecutionResults(); + $this->escapedExecutionResults = new SortableMutantExecutionResults(); + $this->timedOutExecutionResults = new SortableMutantExecutionResults(); + $this->notCoveredExecutionResults = new SortableMutantExecutionResults(); + $this->allExecutionResults = new SortableMutantExecutionResults(); } - public function collect(MutationExecutionResult ...$executionResults): void + public function collect(MutantExecutionResult ...$executionResults): void { if (count($executionResults) > 0) { // Reset the calculator if any result is added @@ -119,7 +119,7 @@ public function collect(MutationExecutionResult ...$executionResults): void break; case DetectionStatus::NOT_COVERED: - $this->notExecutedByTestsCount++; + $this->notCoveredByTestsCount++; $this->notCoveredExecutionResults->add($executionResult); break; @@ -157,7 +157,7 @@ public function getRoundingPrecision(): int } /** - * @return MutationExecutionResult[] + * @return MutantExecutionResult[] */ public function getKilledExecutionResults(): array { @@ -165,7 +165,7 @@ public function getKilledExecutionResults(): array } /** - * @return MutationExecutionResult[] + * @return MutantExecutionResult[] */ public function getErrorExecutionResults(): array { @@ -173,7 +173,7 @@ public function getErrorExecutionResults(): array } /** - * @return MutationExecutionResult[] + * @return MutantExecutionResult[] */ public function getEscapedExecutionResults(): array { @@ -181,7 +181,7 @@ public function getEscapedExecutionResults(): array } /** - * @return MutationExecutionResult[] + * @return MutantExecutionResult[] */ public function getTimedOutExecutionResults(): array { @@ -189,7 +189,7 @@ public function getTimedOutExecutionResults(): array } /** - * @return MutationExecutionResult[] + * @return MutantExecutionResult[] */ public function getNotCoveredExecutionResults(): array { @@ -197,7 +197,7 @@ public function getNotCoveredExecutionResults(): array } /** - * @return MutationExecutionResult[] + * @return MutantExecutionResult[] */ public function getAllExecutionResults(): array { @@ -226,10 +226,10 @@ public function getTimedOutCount(): int public function getNotTestedCount(): int { - return $this->notExecutedByTestsCount; + return $this->notCoveredByTestsCount; } - public function getTotalMutationsCount(): int + public function getTotalMutantsCount(): int { return $this->totalMutantsCount; } diff --git a/src/Metrics/SortableMutationExecutionResults.php b/src/Metrics/SortableMutantExecutionResults.php similarity index 87% rename from src/Metrics/SortableMutationExecutionResults.php rename to src/Metrics/SortableMutantExecutionResults.php index 1db92ff6c..9a9ea6f7e 100644 --- a/src/Metrics/SortableMutationExecutionResults.php +++ b/src/Metrics/SortableMutantExecutionResults.php @@ -35,16 +35,16 @@ namespace Infection\Metrics; -use Infection\Mutation\MutationExecutionResult; +use Infection\Mutant\MutantExecutionResult; use function Safe\usort; /** * @internal */ -final class SortableMutationExecutionResults +final class SortableMutantExecutionResults { /** - * @var MutationExecutionResult[] + * @var MutantExecutionResult[] */ private $executionResults = []; @@ -53,14 +53,14 @@ final class SortableMutationExecutionResults */ private $sorted = false; - public function add(MutationExecutionResult $executionResult): void + public function add(MutantExecutionResult $executionResult): void { $this->executionResults[] = $executionResult; $this->sorted = false; } /** - * @return MutationExecutionResult[] + * @return MutantExecutionResult[] */ public function getSortedExecutionResults(): array { @@ -73,13 +73,13 @@ public function getSortedExecutionResults(): array } /** - * @param MutationExecutionResult[] $executionResults + * @param MutantExecutionResult[] $executionResults */ private static function sortResults(array &$executionResults): void { usort( $executionResults, - static function (MutationExecutionResult $a, MutationExecutionResult $b): int { + static function (MutantExecutionResult $a, MutantExecutionResult $b): int { if ($a->getOriginalFilePath() === $b->getOriginalFilePath()) { return $a->getOriginalStartingLine() <=> $b->getOriginalStartingLine(); } diff --git a/src/Mutation/DetectionStatus.php b/src/Mutant/DetectionStatus.php similarity index 98% rename from src/Mutation/DetectionStatus.php rename to src/Mutant/DetectionStatus.php index 4f7a78f2c..b2fdeeeee 100644 --- a/src/Mutation/DetectionStatus.php +++ b/src/Mutant/DetectionStatus.php @@ -33,7 +33,7 @@ declare(strict_types=1); -namespace Infection\Mutation; +namespace Infection\Mutant; use Infection\CannotBeInstantiated; diff --git a/src/Mutation/MutationCodeFactory.php b/src/Mutant/MutantCodeFactory.php similarity index 97% rename from src/Mutation/MutationCodeFactory.php rename to src/Mutant/MutantCodeFactory.php index b548e8e45..9ec08113b 100644 --- a/src/Mutation/MutationCodeFactory.php +++ b/src/Mutant/MutantCodeFactory.php @@ -33,7 +33,7 @@ declare(strict_types=1); -namespace Infection\Mutation; +namespace Infection\Mutant; use Infection\PhpParser\MutatedNode; use Infection\PhpParser\Visitor\CloneVisitor; @@ -46,7 +46,7 @@ * @internal * @final */ -class MutationCodeFactory +class MutantCodeFactory { private $printer; diff --git a/src/Mutation/MutationExecutionResult.php b/src/Mutant/MutantExecutionResult.php similarity index 97% rename from src/Mutation/MutationExecutionResult.php rename to src/Mutant/MutantExecutionResult.php index 252645a36..3addbb098 100644 --- a/src/Mutation/MutationExecutionResult.php +++ b/src/Mutant/MutantExecutionResult.php @@ -33,9 +33,10 @@ declare(strict_types=1); -namespace Infection\Mutation; +namespace Infection\Mutant; use function array_keys; +use Infection\Mutation\Mutation; use Infection\Mutator\ProfileList; use Webmozart\Assert\Assert; @@ -43,7 +44,7 @@ * @internal * @final */ -class MutationExecutionResult +class MutantExecutionResult { private $processCommandLine; private $processOutput; diff --git a/src/Mutation/MutationExecutionResultFactory.php b/src/Mutation/MutantExecutionResultFactory.php similarity index 86% rename from src/Mutation/MutationExecutionResultFactory.php rename to src/Mutation/MutantExecutionResultFactory.php index b81112650..f089c586f 100644 --- a/src/Mutation/MutationExecutionResultFactory.php +++ b/src/Mutation/MutantExecutionResultFactory.php @@ -36,7 +36,9 @@ namespace Infection\Mutation; use Infection\AbstractTestFramework\TestFrameworkAdapter; -use Infection\Process\MutationProcess; +use Infection\Mutant\DetectionStatus; +use Infection\Mutant\MutantExecutionResult; +use Infection\Process\MutantProcess; use function Safe\sprintf; use Symfony\Component\Process\Process; use Webmozart\Assert\Assert; @@ -45,7 +47,7 @@ * @internal * @final */ -class MutationExecutionResultFactory +class MutantExecutionResultFactory { private $testFrameworkAdapter; @@ -54,12 +56,12 @@ public function __construct(TestFrameworkAdapter $testFrameworkAdapter) $this->testFrameworkAdapter = $testFrameworkAdapter; } - public function createFromProcess(MutationProcess $mutationProcess): MutationExecutionResult + public function createFromProcess(MutantProcess $mutationProcess): MutantExecutionResult { $process = $mutationProcess->getProcess(); $mutation = $mutationProcess->getMutation(); - return new MutationExecutionResult( + return new MutantExecutionResult( $process->getCommandLine(), $this->retrieveProcessOutput($process), $this->retrieveDetectionStatus($mutationProcess), @@ -83,17 +85,17 @@ private function retrieveProcessOutput(Process $process): string return $process->getOutput(); } - private function retrieveDetectionStatus(MutationProcess $mutationProcess): string + private function retrieveDetectionStatus(MutantProcess $mutantProcess): string { - if (!$mutationProcess->getMutation()->hasTests()) { + if (!$mutantProcess->getMutation()->hasTests()) { return DetectionStatus::NOT_COVERED; } - if ($mutationProcess->isTimedOut()) { + if ($mutantProcess->isTimedOut()) { return DetectionStatus::TIMED_OUT; } - $process = $mutationProcess->getProcess(); + $process = $mutantProcess->getProcess(); if ($process->getExitCode() > 100) { // See \Symfony\Component\Process\Process::$exitCodes diff --git a/src/Mutation/MutationFactory.php b/src/Mutation/MutationFactory.php index 322c3f5da..ee63ff225 100644 --- a/src/Mutation/MutationFactory.php +++ b/src/Mutation/MutationFactory.php @@ -39,6 +39,7 @@ use function implode; use Infection\AbstractTestFramework\Coverage\TestLocation; use Infection\Differ\Differ; +use Infection\Mutant\MutantCodeFactory; use Infection\PhpParser\MutatedNode; use function md5; use PhpParser\Node; @@ -61,18 +62,18 @@ class MutationFactory * @var string[] */ private $printedFileCache = []; - private $mutationCodeFactory; + private $codeFactory; public function __construct( string $tmpDir, Differ $differ, PrettyPrinterAbstract $printer, - MutationCodeFactory $mutationCodeFactory + MutantCodeFactory $mutantCodeFactory ) { $this->tmpDir = $tmpDir; $this->differ = $differ; $this->printer = $printer; - $this->mutationCodeFactory = $mutationCodeFactory; + $this->codeFactory = $mutantCodeFactory; } /** @@ -110,7 +111,7 @@ public function create( $hash ); - $mutatedCode = $this->mutationCodeFactory->createCode( + $mutatedCode = $this->codeFactory->createCode( $attributes, $originalFileAst, $mutatedNodeClass, diff --git a/src/Mutator/MutatorParser.php b/src/Mutator/MutatorParser.php index 0924a4946..c61e554b0 100644 --- a/src/Mutator/MutatorParser.php +++ b/src/Mutator/MutatorParser.php @@ -89,7 +89,7 @@ public function parse(string $unparsedMutators): array throw new UnexpectedValueException( sprintf( 'Expected "%s" to be a known mutator or profile. See "%s" and "%s" for ' - . 'the list of available mutations and profiles.', + . 'the list of available mutants and profiles.', $profileOrMutator, 'https://infection.github.io/guide/mutators.html', 'https://infection.github.io/guide/profiles.html' diff --git a/src/Process/Builder/MutationProcessFactory.php b/src/Process/Builder/MutantProcessFactory.php similarity index 84% rename from src/Process/Builder/MutationProcessFactory.php rename to src/Process/Builder/MutantProcessFactory.php index 975fc4942..4496ed2e1 100644 --- a/src/Process/Builder/MutationProcessFactory.php +++ b/src/Process/Builder/MutantProcessFactory.php @@ -37,10 +37,10 @@ use Infection\AbstractTestFramework\TestFrameworkAdapter; use Infection\Event\EventDispatcher\EventDispatcher; -use Infection\Event\MutationProcessWasFinished; +use Infection\Event\MutantProcessWasFinished; +use Infection\Mutation\MutantExecutionResultFactory; use Infection\Mutation\Mutation; -use Infection\Mutation\MutationExecutionResultFactory; -use Infection\Process\MutationProcess; +use Infection\Process\MutantProcess; use function method_exists; use Symfony\Component\Process\Process; @@ -48,7 +48,7 @@ * @internal * @final */ -class MutationProcessFactory +class MutantProcessFactory { private $testFrameworkAdapter; private $timeout; @@ -60,7 +60,7 @@ public function __construct( TestFrameworkAdapter $testFrameworkAdapter, int $timeout, EventDispatcher $eventDispatcher, - MutationExecutionResultFactory $resultFactory + MutantExecutionResultFactory $resultFactory ) { $this->testFrameworkAdapter = $testFrameworkAdapter; $this->timeout = $timeout; @@ -68,7 +68,7 @@ public function __construct( $this->resultFactory = $resultFactory; } - public function createProcessForMutation(Mutation $mutation, string $testFrameworkExtraOptions = ''): MutationProcess + public function createProcessForMutation(Mutation $mutation, string $testFrameworkExtraOptions = ''): MutantProcess { $process = new Process( $this->testFrameworkAdapter->getMutantCommandLine( @@ -87,21 +87,21 @@ public function createProcessForMutation(Mutation $mutation, string $testFramewo $process->inheritEnvironmentVariables(); } - $mutationProcess = new MutationProcess($process, $mutation); + $mutantProcess = new MutantProcess($process, $mutation); $eventDispatcher = $this->eventDispatcher; $resultFactory = $this->resultFactory; - $mutationProcess->registerTerminateProcessClosure(static function () use ( - $mutationProcess, + $mutantProcess->registerTerminateProcessClosure(static function () use ( + $mutantProcess, $eventDispatcher, $resultFactory ): void { - $eventDispatcher->dispatch(new MutationProcessWasFinished( - $resultFactory->createFromProcess($mutationProcess)) + $eventDispatcher->dispatch(new MutantProcessWasFinished( + $resultFactory->createFromProcess($mutantProcess)) ); }); - return $mutationProcess; + return $mutantProcess; } } diff --git a/src/Process/MutationProcess.php b/src/Process/MutantProcess.php similarity index 98% rename from src/Process/MutationProcess.php rename to src/Process/MutantProcess.php index 1d0f3dd9e..a01b2f994 100644 --- a/src/Process/MutationProcess.php +++ b/src/Process/MutantProcess.php @@ -44,7 +44,7 @@ * @internal * @final */ -class MutationProcess implements ProcessBearer +class MutantProcess implements ProcessBearer { private $process; private $mutation; diff --git a/src/Process/Runner/MutationTestingRunner.php b/src/Process/Runner/MutationTestingRunner.php index 90c6f75de..2a437c394 100644 --- a/src/Process/Runner/MutationTestingRunner.php +++ b/src/Process/Runner/MutationTestingRunner.php @@ -36,13 +36,13 @@ namespace Infection\Process\Runner; use Infection\Event\EventDispatcher\EventDispatcher; -use Infection\Event\MutationProcessWasFinished; +use Infection\Event\MutantProcessWasFinished; use Infection\Event\MutationTestingWasFinished; use Infection\Event\MutationTestingWasStarted; use Infection\IterableCounter; +use Infection\Mutant\MutantExecutionResult; use Infection\Mutation\Mutation; -use Infection\Mutation\MutationExecutionResult; -use Infection\Process\Builder\MutationProcessFactory; +use Infection\Process\Builder\MutantProcessFactory; use function Pipeline\take; use Symfony\Component\Filesystem\Filesystem; @@ -58,7 +58,7 @@ final class MutationTestingRunner private $runConcurrently; public function __construct( - MutationProcessFactory $processFactory, + MutantProcessFactory $processFactory, ProcessRunner $processRunner, EventDispatcher $eventDispatcher, Filesystem $fileSystem, @@ -85,8 +85,8 @@ public function run(iterable $mutations, string $testFrameworkExtraOptions): voi return true; } - $this->eventDispatcher->dispatch(new MutationProcessWasFinished( - MutationExecutionResult::createFromNonExecutedByTestsMutation($mutation) + $this->eventDispatcher->dispatch(new MutantProcessWasFinished( + MutantExecutionResult::createFromNonExecutedByTestsMutation($mutation) )); return false; diff --git a/src/TestFramework/AbstractTestFrameworkAdapter.php b/src/TestFramework/AbstractTestFrameworkAdapter.php index 362f0cfc6..09cf0ba05 100644 --- a/src/TestFramework/AbstractTestFrameworkAdapter.php +++ b/src/TestFramework/AbstractTestFrameworkAdapter.php @@ -98,7 +98,7 @@ public function getInitialTestRunCommandLine( } /** - * Returns array of arguments to pass them into the Mutation Symfony's process + * Returns array of arguments to pass them into the Mutant Symfony's process * * @param TestLocation[] $tests * @@ -106,7 +106,7 @@ public function getInitialTestRunCommandLine( */ public function getMutantCommandLine( array $tests, - string $mutationFilePath, + string $mutantFilePath, string $mutationHash, string $mutationOriginalFilePath, string $extraOptions @@ -114,7 +114,7 @@ public function getMutantCommandLine( return $this->getCommandLine( $this->buildMutationConfigFile( $tests, - $mutationFilePath, + $mutantFilePath, $mutationHash, $mutationOriginalFilePath ), @@ -166,13 +166,13 @@ protected function buildInitialConfigFile(): string */ protected function buildMutationConfigFile( array $tests, - string $mutationFilePath, + string $mutantFilePath, string $mutationHash, string $mutationOriginalFilePath ): string { return $this->mutationConfigBuilder->build( $tests, - $mutationFilePath, + $mutantFilePath, $mutationHash, $mutationOriginalFilePath ); diff --git a/src/TestFramework/Config/MutationConfigBuilder.php b/src/TestFramework/Config/MutationConfigBuilder.php index 1cb9cffe4..7996c531d 100644 --- a/src/TestFramework/Config/MutationConfigBuilder.php +++ b/src/TestFramework/Config/MutationConfigBuilder.php @@ -53,7 +53,7 @@ abstract class MutationConfigBuilder */ abstract public function build( array $tests, - string $mutationFilePath, + string $mutantFilePath, string $mutationHash, string $mutationOriginalFilePath ): string; diff --git a/src/TestFramework/PhpUnit/Config/Builder/MutationConfigBuilder.php b/src/TestFramework/PhpUnit/Config/Builder/MutationConfigBuilder.php index b5df447ad..6669def32 100644 --- a/src/TestFramework/PhpUnit/Config/Builder/MutationConfigBuilder.php +++ b/src/TestFramework/PhpUnit/Config/Builder/MutationConfigBuilder.php @@ -78,7 +78,6 @@ public function __construct( ) { $this->tmpDir = $tmpDir; $this->projectDir = $projectDir; - $this->originalXmlConfigContent = $originalXmlConfigContent; $this->configManipulator = $configManipulator; $this->jUnitTestCaseSorter = $jUnitTestCaseSorter; @@ -89,7 +88,7 @@ public function __construct( */ public function build( array $tests, - string $mutationFilePath, + string $mutantFilePath, string $mutationHash, string $mutationOriginalFilePath ): string { @@ -125,7 +124,7 @@ public function build( $customAutoloadFilePath, $this->createCustomAutoloadWithInterceptor( $mutationOriginalFilePath, - $mutationFilePath, + $mutantFilePath, $originalBootstrapFile ) ); diff --git a/src/TestFramework/TestFrameworkExtraOptionsFilter.php b/src/TestFramework/TestFrameworkExtraOptionsFilter.php index 79b6b6088..926462b97 100644 --- a/src/TestFramework/TestFrameworkExtraOptionsFilter.php +++ b/src/TestFramework/TestFrameworkExtraOptionsFilter.php @@ -48,7 +48,7 @@ final class TestFrameworkExtraOptionsFilter /** * @param string[] $initialRunOnlyOptions */ - public function filterForMutationProcess( + public function filterForMutantProcess( string $actualExtraOptions, array $initialRunOnlyOptions ): string { diff --git a/tests/phpunit/AutoReview/ProjectCode/ProjectCodeProvider.php b/tests/phpunit/AutoReview/ProjectCode/ProjectCodeProvider.php index 15afff80b..7f4549845 100644 --- a/tests/phpunit/AutoReview/ProjectCode/ProjectCodeProvider.php +++ b/tests/phpunit/AutoReview/ProjectCode/ProjectCodeProvider.php @@ -59,7 +59,7 @@ use Infection\Http\StrykerCurlClient; use Infection\Http\StrykerDashboardClient; use Infection\Metrics\MetricsCalculator; -use Infection\Mutation\DetectionStatus; +use Infection\Mutant\DetectionStatus; use Infection\Mutation\MutationAttributeKeys; use Infection\Mutator\NodeMutationGenerator; use Infection\Process\Builder\InitialTestRunProcessBuilder; diff --git a/tests/phpunit/Console/OutputFormatter/DotFormatterTest.php b/tests/phpunit/Console/OutputFormatter/DotFormatterTest.php index 0eeb18186..d88974388 100644 --- a/tests/phpunit/Console/OutputFormatter/DotFormatterTest.php +++ b/tests/phpunit/Console/OutputFormatter/DotFormatterTest.php @@ -36,8 +36,8 @@ namespace Infection\Tests\Console\OutputFormatter; use Infection\Console\OutputFormatter\DotFormatter; -use Infection\Mutation\DetectionStatus; -use Infection\Mutation\MutationExecutionResult; +use Infection\Mutant\DetectionStatus; +use Infection\Mutant\MutantExecutionResult; use const PHP_EOL; use PHPUnit\Framework\TestCase; use function strip_tags; @@ -77,7 +77,7 @@ public function test_killed_logs_correctly_in_console(): void $dot = new DotFormatter($outputKilled); $dot->start(10); $dot->advance( - $this->createMutationExecutionResultsOfType(DetectionStatus::KILLED)[0], + $this->createMutantExecutionResultsOfType(DetectionStatus::KILLED)[0], 10 ); } @@ -94,7 +94,7 @@ public function test_escaped_logs_correctly_in_console(): void $dot = new DotFormatter($outputEscaped); $dot->start(10); $dot->advance( - $this->createMutationExecutionResultsOfType(DetectionStatus::ESCAPED)[0], + $this->createMutantExecutionResultsOfType(DetectionStatus::ESCAPED)[0], 10 ); } @@ -111,7 +111,7 @@ public function test_errored_logs_correctly_in_console(): void $dot = new DotFormatter($outputErrored); $dot->start(10); $dot->advance( - $this->createMutationExecutionResultsOfType(DetectionStatus::ERROR)[0], + $this->createMutantExecutionResultsOfType(DetectionStatus::ERROR)[0], 10 ); } @@ -128,7 +128,7 @@ public function test_timed_out_logs_correctly_in_console(): void $dot = new DotFormatter($outputTimedOut); $dot->start(10); $dot->advance( - $this->createMutationExecutionResultsOfType(DetectionStatus::TIMED_OUT)[0], + $this->createMutantExecutionResultsOfType(DetectionStatus::TIMED_OUT)[0], 10 ); } @@ -145,7 +145,7 @@ public function test_not_covered_correctly_in_console(): void $dot = new DotFormatter($outputNotCovered); $dot->start(10); $dot->advance( - $this->createMutationExecutionResultsOfType(DetectionStatus::NOT_COVERED)[0], + $this->createMutantExecutionResultsOfType(DetectionStatus::NOT_COVERED)[0], 10 ); } @@ -159,7 +159,7 @@ public function test_it_prints_total_number_of_mutations(): void $dot->start($totalMutations); for ($i = 0; $i < $totalMutations; ++$i) { - $dot->advance($this->createMutationExecutionResultsOfType(DetectionStatus::KILLED)[0], $totalMutations); + $dot->advance($this->createMutantExecutionResultsOfType(DetectionStatus::KILLED)[0], $totalMutations); } $this->assertSame(str_replace("\n", PHP_EOL, @@ -186,7 +186,7 @@ public function test_it_prints_current_number_of_pending_mutations(): void for ($i = 0; $i < $totalMutations; ++$i) { $dot->advance( - $this->createMutationExecutionResultsOfType(DetectionStatus::KILLED)[0], + $this->createMutantExecutionResultsOfType(DetectionStatus::KILLED)[0], 0 ); } @@ -205,14 +205,14 @@ public function test_it_prints_current_number_of_pending_mutations(): void ); } - private function createMutationExecutionResultsOfType( + private function createMutantExecutionResultsOfType( string $detectionStatus, int $count = 1 ): array { $executionResults = []; for ($i = 0; $i < $count; ++$i) { - $executionResult = $this->createMock(MutationExecutionResult::class); + $executionResult = $this->createMock(MutantExecutionResult::class); $executionResult ->expects($this->once()) ->method('getDetectionStatus') diff --git a/tests/phpunit/Event/MutationProcessWasFinishedTest.php b/tests/phpunit/Event/MutantProcessWasFinishedTest.php similarity index 85% rename from tests/phpunit/Event/MutationProcessWasFinishedTest.php rename to tests/phpunit/Event/MutantProcessWasFinishedTest.php index 246df59a8..4636faf24 100644 --- a/tests/phpunit/Event/MutationProcessWasFinishedTest.php +++ b/tests/phpunit/Event/MutantProcessWasFinishedTest.php @@ -35,17 +35,17 @@ namespace Infection\Tests\Event; -use Infection\Event\MutationProcessWasFinished; -use Infection\Mutation\MutationExecutionResult; +use Infection\Event\MutantProcessWasFinished; +use Infection\Mutant\MutantExecutionResult; use PHPUnit\Framework\TestCase; -final class MutationProcessWasFinishedTest extends TestCase +final class MutantProcessWasFinishedTest extends TestCase { public function test_it_exposes_its_mutation_process(): void { - $executionResultMock = $this->createMock(MutationExecutionResult::class); + $executionResultMock = $this->createMock(MutantExecutionResult::class); - $event = new MutationProcessWasFinished($executionResultMock); + $event = new MutantProcessWasFinished($executionResultMock); $this->assertSame($executionResultMock, $event->getExecutionResult()); } diff --git a/tests/phpunit/Event/Subscriber/CiInitialTestsConsoleLoggerSubscriberTest.php b/tests/phpunit/Event/Subscriber/CiInitialTestsConsoleLoggerSubscriberTest.php index 38922a95c..424359f78 100644 --- a/tests/phpunit/Event/Subscriber/CiInitialTestsConsoleLoggerSubscriberTest.php +++ b/tests/phpunit/Event/Subscriber/CiInitialTestsConsoleLoggerSubscriberTest.php @@ -63,7 +63,7 @@ protected function setUp(): void $this->testFramework = $this->createMock(AbstractTestFrameworkAdapter::class); } - public function test_it_reacts_on_mutations_creating_event(): void + public function test_it_reacts_on_mutants_creating_event(): void { $this->output->expects($this->once()) ->method('writeln') diff --git a/tests/phpunit/Event/Subscriber/CiMutationGeneratingConsoleLoggerSubscriberTest.php b/tests/phpunit/Event/Subscriber/CiMutationGeneratingConsoleLoggerSubscriberTest.php index 2d97cc187..d0ae92855 100644 --- a/tests/phpunit/Event/Subscriber/CiMutationGeneratingConsoleLoggerSubscriberTest.php +++ b/tests/phpunit/Event/Subscriber/CiMutationGeneratingConsoleLoggerSubscriberTest.php @@ -62,7 +62,7 @@ public function test_it_reacts_on_mutation_generating_started_event(): void ->method('writeln') ->with([ '', - 'Generate mutations...', + 'Generate mutants...', '', 'Processing source code files: 123', ]); diff --git a/tests/phpunit/Event/Subscriber/MutationTestingConsoleLoggerSubscriberTest.php b/tests/phpunit/Event/Subscriber/MutationTestingConsoleLoggerSubscriberTest.php index 4f17e7888..dd54223e9 100644 --- a/tests/phpunit/Event/Subscriber/MutationTestingConsoleLoggerSubscriberTest.php +++ b/tests/phpunit/Event/Subscriber/MutationTestingConsoleLoggerSubscriberTest.php @@ -38,12 +38,12 @@ use Infection\Console\OutputFormatter\OutputFormatter; use Infection\Differ\DiffColorizer; use Infection\Event\EventDispatcher\SyncEventDispatcher; -use Infection\Event\MutationProcessWasFinished; +use Infection\Event\MutantProcessWasFinished; use Infection\Event\MutationTestingWasFinished; use Infection\Event\MutationTestingWasStarted; use Infection\Event\Subscriber\MutationTestingConsoleLoggerSubscriber; use Infection\Metrics\MetricsCalculator; -use Infection\Mutation\MutationExecutionResult; +use Infection\Mutant\MutantExecutionResult; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Symfony\Component\Console\Output\OutputInterface; @@ -116,8 +116,8 @@ public function test_it_reacts_on_mutation_process_finished(): void )); $dispatcher->dispatch( - new MutationProcessWasFinished( - $this->createMock(MutationExecutionResult::class) + new MutantProcessWasFinished( + $this->createMock(MutantExecutionResult::class) ) ); } diff --git a/tests/phpunit/Logger/CreateMetricsCalculator.php b/tests/phpunit/Logger/CreateMetricsCalculator.php index 64b11f3d4..f0c09275b 100644 --- a/tests/phpunit/Logger/CreateMetricsCalculator.php +++ b/tests/phpunit/Logger/CreateMetricsCalculator.php @@ -36,8 +36,8 @@ namespace Infection\Tests\Logger; use Infection\Metrics\MetricsCalculator; -use Infection\Mutation\DetectionStatus; -use Infection\Mutation\MutationExecutionResult; +use Infection\Mutant\DetectionStatus; +use Infection\Mutant\MutantExecutionResult; use Infection\Mutator\Regex\PregQuote; use Infection\Mutator\ZeroIteration\For_; use Infection\Tests\Mutator\MutatorName; @@ -121,8 +121,8 @@ private function createMutantExecutionResult( string $mutatorClassName, string $detectionStatus, string $echoMutatedMessage - ): MutationExecutionResult { - return new MutationExecutionResult( + ): MutantExecutionResult { + return new MutantExecutionResult( 'bin/phpunit --configuration infection-tmp-phpunit.xml --filter "tests/Acme/FooTest.php"', 'process output', $detectionStatus, diff --git a/tests/phpunit/Metrics/MetricsCalculatorTest.php b/tests/phpunit/Metrics/MetricsCalculatorTest.php index 6c11f1221..b40b7d384 100644 --- a/tests/phpunit/Metrics/MetricsCalculatorTest.php +++ b/tests/phpunit/Metrics/MetricsCalculatorTest.php @@ -37,8 +37,8 @@ use function array_merge; use Infection\Metrics\MetricsCalculator; -use Infection\Mutation\DetectionStatus; -use Infection\Mutation\MutationExecutionResult; +use Infection\Mutant\DetectionStatus; +use Infection\Mutant\MutantExecutionResult; use Infection\Mutator\ZeroIteration\For_; use Infection\Tests\Mutator\MutatorName; use PHPUnit\Framework\TestCase; @@ -56,7 +56,7 @@ public function test_it_shows_zero_values_by_default(): void $this->assertSame(0, $calculator->getEscapedCount()); $this->assertSame(0, $calculator->getTimedOutCount()); $this->assertSame(0, $calculator->getNotTestedCount()); - $this->assertSame(0, $calculator->getTotalMutationsCount()); + $this->assertSame(0, $calculator->getTotalMutantsCount()); $this->assertSame([], $calculator->getKilledExecutionResults()); $this->assertSame([], $calculator->getErrorExecutionResults()); @@ -122,7 +122,7 @@ public function test_it_collects_all_values(): void $calculator->getAllExecutionResults() ); - $this->assertSame(14, $calculator->getTotalMutationsCount()); + $this->assertSame(14, $calculator->getTotalMutantsCount()); $this->assertSame(78.57, $calculator->getMutationScoreIndicator()); $this->assertSame(92.86, $calculator->getCoverageRate()); $this->assertSame(84.62, $calculator->getCoveredCodeMutationScoreIndicator()); @@ -154,7 +154,7 @@ public function test_its_metrics_are_properly_updated_when_adding_a_new_process( } /** - * @return MutationExecutionResult[] + * @return MutantExecutionResult[] */ private function addMutationExecutionResult( MetricsCalculator $calculator, @@ -172,12 +172,12 @@ private function addMutationExecutionResult( return $executionResults; } - private function createMutationExecutionResult(string $detectionStatus): MutationExecutionResult + private function createMutationExecutionResult(string $detectionStatus): MutantExecutionResult { $id = $this->id; ++$this->id; - return new MutationExecutionResult( + return new MutantExecutionResult( 'bin/phpunit --configuration infection-tmp-phpunit.xml --filter "tests/Acme/FooTest.php"', 'process output', $detectionStatus, diff --git a/tests/phpunit/Metrics/SortableMutationExecutionResultsTest.php b/tests/phpunit/Metrics/SortableMutantExecutionResultsTest.php similarity index 91% rename from tests/phpunit/Metrics/SortableMutationExecutionResultsTest.php rename to tests/phpunit/Metrics/SortableMutantExecutionResultsTest.php index 216a50c51..166426479 100644 --- a/tests/phpunit/Metrics/SortableMutationExecutionResultsTest.php +++ b/tests/phpunit/Metrics/SortableMutantExecutionResultsTest.php @@ -35,24 +35,24 @@ namespace Infection\Tests\Metrics; -use Infection\Metrics\SortableMutationExecutionResults; -use Infection\Mutation\DetectionStatus; -use Infection\Mutation\MutationExecutionResult; +use Infection\Metrics\SortableMutantExecutionResults; +use Infection\Mutant\DetectionStatus; +use Infection\Mutant\MutantExecutionResult; use Infection\Mutator\ZeroIteration\For_; use Infection\Tests\Mutator\MutatorName; use PHPUnit\Framework\TestCase; -final class SortableMutationExecutionResultsTest extends TestCase +final class SortableMutantExecutionResultsTest extends TestCase { /** * @dataProvider resultsProvider * - * @param MutationExecutionResult[] $executionResults - * @param MutationExecutionResult[] $expectedResults + * @param MutantExecutionResult[] $executionResults + * @param MutantExecutionResult[] $expectedResults */ public function test_it_can_sort_results(array $executionResults, array $expectedResults): void { - $sortableResults = new SortableMutationExecutionResults(); + $sortableResults = new SortableMutantExecutionResults(); foreach ($executionResults as $executionResult) { $sortableResults->add($executionResult); @@ -63,7 +63,7 @@ public function test_it_can_sort_results(array $executionResults, array $expecte public function test_it_keeps_results_sorted_as_they_are_added(): void { - $sortableResults = new SortableMutationExecutionResults(); + $sortableResults = new SortableMutantExecutionResults(); $result0 = $this->createExecutionResult( 0, @@ -186,8 +186,8 @@ private function createExecutionResult( int $id, string $originalFilePath, int $originalStartingLine - ): MutationExecutionResult { - return new MutationExecutionResult( + ): MutantExecutionResult { + return new MutantExecutionResult( 'bin/phpunit --configuration infection-tmp-phpunit.xml --filter "tests/Acme/FooTest.php"', 'Passed!', DetectionStatus::ESCAPED, diff --git a/tests/phpunit/Mutation/MutationCodeFactoryTest.php b/tests/phpunit/Mutant/MutantCodeFactoryTest.php similarity index 96% rename from tests/phpunit/Mutation/MutationCodeFactoryTest.php rename to tests/phpunit/Mutant/MutantCodeFactoryTest.php index b5a658d92..2bbf47d5b 100644 --- a/tests/phpunit/Mutation/MutationCodeFactoryTest.php +++ b/tests/phpunit/Mutant/MutantCodeFactoryTest.php @@ -33,24 +33,24 @@ declare(strict_types=1); -namespace Infection\Tests\Mutation; +namespace Infection\Tests\Mutant; -use Infection\Mutation\MutationCodeFactory; +use Infection\Mutant\MutantCodeFactory; use Infection\PhpParser\MutatedNode; use Infection\Tests\SingletonContainer; use PhpParser\Node; use PHPUnit\Framework\TestCase; -final class MutationCodeFactoryTest extends TestCase +final class MutantCodeFactoryTest extends TestCase { /** - * @var MutationCodeFactory + * @var MutantCodeFactory */ private $codeFactory; protected function setUp(): void { - $this->codeFactory = SingletonContainer::getContainer()->getMutationCodeFactory(); + $this->codeFactory = SingletonContainer::getContainer()->getMutantCodeFactory(); } /** @@ -60,7 +60,7 @@ protected function setUp(): void * @param Node[] $originalFileAst * @param class-string $mutatedNodeClass */ - public function test_it_creates_the_mutation_code_from_the_given_mutation( + public function test_it_creates_the_mutation_code_from_the_given_nodes( array $attributes, array $originalFileAst, string $mutatedNodeClass, diff --git a/tests/phpunit/Mutation/MutationExecutionResultTest.php b/tests/phpunit/Mutant/MutantExecutionResultTest.php similarity index 93% rename from tests/phpunit/Mutation/MutationExecutionResultTest.php rename to tests/phpunit/Mutant/MutantExecutionResultTest.php index 5e3bf20f9..eabd6fb07 100644 --- a/tests/phpunit/Mutation/MutationExecutionResultTest.php +++ b/tests/phpunit/Mutant/MutantExecutionResultTest.php @@ -33,17 +33,17 @@ declare(strict_types=1); -namespace Infection\Tests\Mutation; +namespace Infection\Tests\Mutant; use Infection\AbstractTestFramework\Coverage\TestLocation; -use Infection\Mutation\DetectionStatus; +use Infection\Mutant\DetectionStatus; +use Infection\Mutant\MutantExecutionResult; use Infection\Mutation\Mutation; -use Infection\Mutation\MutationExecutionResult; use Infection\Mutator\ZeroIteration\For_; use Infection\Tests\Mutator\MutatorName; use PHPUnit\Framework\TestCase; -final class MutationExecutionResultTest extends TestCase +final class MutantExecutionResultTest extends TestCase { public function test_it_can_be_instantiated(): void { @@ -64,7 +64,7 @@ public function test_it_can_be_instantiated(): void $originalFilePath = 'path/to/Foo.php'; $originalStartingLine = 10; - $result = new MutationExecutionResult( + $result = new MutantExecutionResult( $processCommandLine, $processOutput, $processResultCode, @@ -116,7 +116,7 @@ public function test_it_can_be_instantiated_from_a_mutation_non_executed_by_test ); $this->assertResultStateIs( - MutationExecutionResult::createFromNonExecutedByTestsMutation($mutation), + MutantExecutionResult::createFromNonExecutedByTestsMutation($mutation), '', '', DetectionStatus::NOT_COVERED, @@ -128,7 +128,7 @@ public function test_it_can_be_instantiated_from_a_mutation_non_executed_by_test } private function assertResultStateIs( - MutationExecutionResult $result, + MutantExecutionResult $result, string $expectedProcessCommandLine, string $expectedProcessOutput, string $expectedDetectionStatus, diff --git a/tests/phpunit/Mutation/MutationExecutionResultAssertions.php b/tests/phpunit/Mutation/MutantExecutionResultAssertions.php similarity index 95% rename from tests/phpunit/Mutation/MutationExecutionResultAssertions.php rename to tests/phpunit/Mutation/MutantExecutionResultAssertions.php index 3f67d41b0..a638db98c 100644 --- a/tests/phpunit/Mutation/MutationExecutionResultAssertions.php +++ b/tests/phpunit/Mutation/MutantExecutionResultAssertions.php @@ -35,12 +35,12 @@ namespace Infection\Tests\Mutation; -use Infection\Mutation\MutationExecutionResult; +use Infection\Mutant\MutantExecutionResult; -trait MutationExecutionResultAssertions +trait MutantExecutionResultAssertions { private function assertResultStateIs( - MutationExecutionResult $result, + MutantExecutionResult $result, string $expectedProcessCommandLine, string $expectedProcessOutput, string $expectedDetectionStatus, diff --git a/tests/phpunit/Mutation/MutationExecutionResultFactoryTest.php b/tests/phpunit/Mutation/MutantExecutionResultFactoryTest.php similarity index 90% rename from tests/phpunit/Mutation/MutationExecutionResultFactoryTest.php rename to tests/phpunit/Mutation/MutantExecutionResultFactoryTest.php index 0f091b5fa..17477500f 100644 --- a/tests/phpunit/Mutation/MutationExecutionResultFactoryTest.php +++ b/tests/phpunit/Mutation/MutantExecutionResultFactoryTest.php @@ -37,19 +37,19 @@ use Infection\AbstractTestFramework\Coverage\TestLocation; use Infection\AbstractTestFramework\TestFrameworkAdapter; -use Infection\Mutation\DetectionStatus; +use Infection\Mutant\DetectionStatus; +use Infection\Mutation\MutantExecutionResultFactory; use Infection\Mutation\Mutation; -use Infection\Mutation\MutationExecutionResultFactory; use Infection\Mutator\ZeroIteration\For_; -use Infection\Process\MutationProcess; +use Infection\Process\MutantProcess; use Infection\Tests\Mutator\MutatorName; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Symfony\Component\Process\Process; -final class MutationExecutionResultFactoryTest extends TestCase +final class MutantExecutionResultFactoryTest extends TestCase { - use MutationExecutionResultAssertions; + use MutantExecutionResultAssertions; /** * @var TestFrameworkAdapter|MockObject @@ -57,7 +57,7 @@ final class MutationExecutionResultFactoryTest extends TestCase private $testFrameworkAdapterMock; /** - * @var MutationExecutionResultFactory + * @var MutantExecutionResultFactory */ private $resultFactory; @@ -65,10 +65,10 @@ protected function setUp(): void { $this->testFrameworkAdapterMock = $this->createMock(TestFrameworkAdapter::class); - $this->resultFactory = new MutationExecutionResultFactory($this->testFrameworkAdapterMock); + $this->resultFactory = new MutantExecutionResultFactory($this->testFrameworkAdapterMock); } - public function test_it_can_create_a_result_from_a_non_covered_mutation_process(): void + public function test_it_can_create_a_result_from_a_non_covered_mutant_process(): void { $processMock = $this->createMock(Process::class); $processMock @@ -101,7 +101,7 @@ public function test_it_can_create_a_result_from_a_non_covered_mutation_process( DIFF; - $mutationProcess = new MutationProcess( + $mutantProcess = new MutantProcess( $processMock, new Mutation( $originalFilePath = 'path/to/Foo.php', @@ -116,7 +116,7 @@ public function test_it_can_create_a_result_from_a_non_covered_mutation_process( ); $this->assertResultStateIs( - $this->resultFactory->createFromProcess($mutationProcess), + $this->resultFactory->createFromProcess($mutantProcess), $processCommandLine, $processOutput, DetectionStatus::NOT_COVERED, @@ -127,7 +127,7 @@ public function test_it_can_create_a_result_from_a_non_covered_mutation_process( ); } - public function test_it_can_create_a_result_from_a_timed_out_mutation_process(): void + public function test_it_can_create_a_result_from_a_timed_out_mutant_process(): void { $processMock = $this->createMock(Process::class); $processMock @@ -160,7 +160,7 @@ public function test_it_can_create_a_result_from_a_timed_out_mutation_process(): DIFF; - $mutationProcess = new MutationProcess( + $mutantProcess = new MutantProcess( $processMock, new Mutation( $originalFilePath = 'path/to/Foo.php', @@ -180,10 +180,10 @@ public function test_it_can_create_a_result_from_a_timed_out_mutation_process(): ) ); - $mutationProcess->markAsTimedOut(); + $mutantProcess->markAsTimedOut(); $this->assertResultStateIs( - $this->resultFactory->createFromProcess($mutationProcess), + $this->resultFactory->createFromProcess($mutantProcess), $processCommandLine, $processOutput, DetectionStatus::TIMED_OUT, @@ -194,7 +194,7 @@ public function test_it_can_create_a_result_from_a_timed_out_mutation_process(): ); } - public function test_it_can_create_a_result_from_an_errored_mutation_process(): void + public function test_it_can_create_a_result_from_an_errored_mutant_process(): void { $processMock = $this->createMock(Process::class); $processMock @@ -232,7 +232,7 @@ public function test_it_can_create_a_result_from_an_errored_mutation_process(): DIFF; - $mutationProcess = new MutationProcess( + $mutantProcess = new MutantProcess( $processMock, new Mutation( $originalFilePath = 'path/to/Foo.php', @@ -253,7 +253,7 @@ public function test_it_can_create_a_result_from_an_errored_mutation_process(): ); $this->assertResultStateIs( - $this->resultFactory->createFromProcess($mutationProcess), + $this->resultFactory->createFromProcess($mutantProcess), $processCommandLine, $processOutput, DetectionStatus::ERROR, @@ -264,7 +264,7 @@ public function test_it_can_create_a_result_from_an_errored_mutation_process(): ); } - public function test_it_can_crate_a_result_from_an_escaped_mutation_process(): void + public function test_it_can_crate_a_result_from_an_escaped_mutant_process(): void { $processMock = $this->createMock(Process::class); $processMock @@ -304,7 +304,7 @@ public function test_it_can_crate_a_result_from_an_escaped_mutation_process(): v DIFF; - $mutationProcess = new MutationProcess( + $mutantProcess = new MutantProcess( $processMock, new Mutation( $originalFilePath = 'path/to/Foo.php', @@ -325,7 +325,7 @@ public function test_it_can_crate_a_result_from_an_escaped_mutation_process(): v ); $this->assertResultStateIs( - $this->resultFactory->createFromProcess($mutationProcess), + $this->resultFactory->createFromProcess($mutantProcess), $processCommandLine, 'Tests passed!', DetectionStatus::ESCAPED, @@ -336,7 +336,7 @@ public function test_it_can_crate_a_result_from_an_escaped_mutation_process(): v ); } - public function test_it_can_crate_a_result_from_a_killed_mutation_process(): void + public function test_it_can_crate_a_result_from_a_killed_mutant_process(): void { $processMock = $this->createMock(Process::class); $processMock @@ -376,7 +376,7 @@ public function test_it_can_crate_a_result_from_a_killed_mutation_process(): voi DIFF; - $mutationProcess = new MutationProcess( + $mutantProcess = new MutantProcess( $processMock, new Mutation( $originalFilePath = 'path/to/Foo.php', @@ -397,7 +397,7 @@ public function test_it_can_crate_a_result_from_a_killed_mutation_process(): voi ); $this->assertResultStateIs( - $this->resultFactory->createFromProcess($mutationProcess), + $this->resultFactory->createFromProcess($mutantProcess), $processCommandLine, 'Tests failed!', DetectionStatus::KILLED, diff --git a/tests/phpunit/Mutation/MutationFactoryTest.php b/tests/phpunit/Mutation/MutationFactoryTest.php index 8a493ba4d..a6a96c04f 100644 --- a/tests/phpunit/Mutation/MutationFactoryTest.php +++ b/tests/phpunit/Mutation/MutationFactoryTest.php @@ -38,7 +38,7 @@ use function array_merge; use Infection\AbstractTestFramework\Coverage\TestLocation; use Infection\Differ\Differ; -use Infection\Mutation\MutationCodeFactory; +use Infection\Mutant\MutantCodeFactory; use Infection\Mutation\MutationFactory; use Infection\Mutator\Arithmetic\Plus; use Infection\PhpParser\MutatedNode; @@ -55,7 +55,7 @@ final class MutationFactoryTest extends TestCase use MutationAssertions; /** - * @var MutationCodeFactory|MockObject + * @var MutantCodeFactory|MockObject */ private $codeFactoryMock; @@ -78,7 +78,7 @@ protected function setUp(): void { parent::setUp(); - $this->codeFactoryMock = $this->createMock(MutationCodeFactory::class); + $this->codeFactoryMock = $this->createMock(MutantCodeFactory::class); $this->printerMock = $this->createMock(PrettyPrinterAbstract::class); $this->differMock = $this->createMock(Differ::class); diff --git a/tests/phpunit/Mutator/MutatorParserTest.php b/tests/phpunit/Mutator/MutatorParserTest.php index b64ecc038..e4e96e6d7 100644 --- a/tests/phpunit/Mutator/MutatorParserTest.php +++ b/tests/phpunit/Mutator/MutatorParserTest.php @@ -68,7 +68,7 @@ public function test_it_can_parse_the_provided_input( public function test_it_cannot_parse_unknown_mutator(): void { $this->expectException(UnexpectedValueException::class); - $this->expectExceptionMessage('Expected "Unknown" to be a known mutator or profile. See "https://infection.github.io/guide/mutators.html" and "https://infection.github.io/guide/profiles.html" for the list of available mutations and profiles.'); + $this->expectExceptionMessage('Expected "Unknown" to be a known mutator or profile. See "https://infection.github.io/guide/mutators.html" and "https://infection.github.io/guide/profiles.html" for the list of available mutants and profiles.'); $this->mutatorParser->parse('Unknown'); } diff --git a/tests/phpunit/Process/Builder/MutationProcessFactoryTest.php b/tests/phpunit/Process/Builder/MutantProcessFactoryTest.php similarity index 89% rename from tests/phpunit/Process/Builder/MutationProcessFactoryTest.php rename to tests/phpunit/Process/Builder/MutantProcessFactoryTest.php index 3e1ceee26..196b73405 100644 --- a/tests/phpunit/Process/Builder/MutationProcessFactoryTest.php +++ b/tests/phpunit/Process/Builder/MutantProcessFactoryTest.php @@ -38,18 +38,18 @@ use function current; use Infection\AbstractTestFramework\Coverage\TestLocation; use Infection\AbstractTestFramework\TestFrameworkAdapter; -use Infection\Event\MutationProcessWasFinished; +use Infection\Event\MutantProcessWasFinished; +use Infection\Mutant\MutantExecutionResult; +use Infection\Mutation\MutantExecutionResultFactory; use Infection\Mutation\Mutation; -use Infection\Mutation\MutationExecutionResult; -use Infection\Mutation\MutationExecutionResultFactory; use Infection\Mutator\ZeroIteration\For_; -use Infection\Process\Builder\MutationProcessFactory; +use Infection\Process\Builder\MutantProcessFactory; use Infection\Tests\Fixtures\Event\EventDispatcherCollector; use Infection\Tests\Mutator\MutatorName; use const PHP_OS_FAMILY; use PHPUnit\Framework\TestCase; -final class MutationProcessFactoryTest extends TestCase +final class MutantProcessFactoryTest extends TestCase { public function test_it_creates_a_process_with_timeout(): void { @@ -98,19 +98,19 @@ public function test_it_creates_a_process_with_timeout(): void $eventDispatcher = new EventDispatcherCollector(); - $executionResultMock = $this->createMock(MutationExecutionResult::class); + $executionResultMock = $this->createMock(MutantExecutionResult::class); $executionResultMock ->expects($this->never()) ->method($this->anything()) ; - $resultFactoryMock = $this->createMock(MutationExecutionResultFactory::class); + $resultFactoryMock = $this->createMock(MutantExecutionResultFactory::class); $resultFactoryMock ->method('createFromProcess') ->willReturn($executionResultMock) ; - $factory = new MutationProcessFactory( + $factory = new MutantProcessFactory( $testFrameworkAdapterMock, 100, $eventDispatcher, @@ -143,7 +143,7 @@ public function test_it_creates_a_process_with_timeout(): void $event = current($eventsAfterCallbackCall); - $this->assertInstanceOf(MutationProcessWasFinished::class, $event); + $this->assertInstanceOf(MutantProcessWasFinished::class, $event); $this->assertSame($executionResultMock, $event->getExecutionResult()); } } diff --git a/tests/phpunit/Process/MutationProcessTest.php b/tests/phpunit/Process/MutantProcessTest.php similarity index 93% rename from tests/phpunit/Process/MutationProcessTest.php rename to tests/phpunit/Process/MutantProcessTest.php index 30f089376..8f7460a26 100644 --- a/tests/phpunit/Process/MutationProcessTest.php +++ b/tests/phpunit/Process/MutantProcessTest.php @@ -36,12 +36,12 @@ namespace Infection\Tests\Process; use Infection\Mutation\Mutation; -use Infection\Process\MutationProcess; +use Infection\Process\MutantProcess; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Symfony\Component\Process\Process; -final class MutationProcessTest extends TestCase +final class MutantProcessTest extends TestCase { /** * @var MockObject|Process @@ -54,7 +54,7 @@ final class MutationProcessTest extends TestCase private $mutationMock; /** - * @var MutationProcess + * @var MutantProcess */ private $mutationProcess; @@ -63,7 +63,7 @@ protected function setUp(): void $this->processMock = $this->createMock(Process::class); $this->mutationMock = $this->createMock(Mutation::class); - $this->mutationProcess = new MutationProcess($this->processMock, $this->mutationMock); + $this->mutationProcess = new MutantProcess($this->processMock, $this->mutationMock); } public function test_it_exposes_its_state(): void @@ -106,7 +106,7 @@ static function () use (&$called): void { } private function assertMutationProcessStateIs( - MutationProcess $mutationProcess, + MutantProcess $mutationProcess, Process $expectedProcess, Mutation $expectedMutation, bool $expectedTimedOut diff --git a/tests/phpunit/Process/Runner/MutationTestingRunnerTest.php b/tests/phpunit/Process/Runner/MutationTestingRunnerTest.php index e9e6ea05d..936b5df14 100644 --- a/tests/phpunit/Process/Runner/MutationTestingRunnerTest.php +++ b/tests/phpunit/Process/Runner/MutationTestingRunnerTest.php @@ -45,8 +45,8 @@ use Infection\Event\MutationTestingWasStarted; use Infection\Mutation\Mutation; use Infection\Mutator\ZeroIteration\For_; -use Infection\Process\Builder\MutationProcessFactory; -use Infection\Process\MutationProcess; +use Infection\Process\Builder\MutantProcessFactory; +use Infection\Process\MutantProcess; use Infection\Process\Runner\MutationTestingRunner; use Infection\Process\Runner\ProcessRunner; use Infection\Tests\Fixtures\Event\EventDispatcherCollector; @@ -65,7 +65,7 @@ final class MutationTestingRunnerTest extends TestCase { /** - * @var MutationProcessFactory|MockObject + * @var MutantProcessFactory|MockObject */ private $processFactoryMock; @@ -91,7 +91,7 @@ final class MutationTestingRunnerTest extends TestCase protected function setUp(): void { - $this->processFactoryMock = $this->createMock(MutationProcessFactory::class); + $this->processFactoryMock = $this->createMock(MutantProcessFactory::class); $this->processRunnerMock = $this->createMock(ProcessRunner::class); $this->eventDispatcher = new EventDispatcherCollector(); $this->fileSystemMock = $this->createMock(Filesystem::class); @@ -363,7 +363,7 @@ private function formatExpectedEvents(array $events): string ); } - private function buildCoveredMutationProcess(Mutation $mutation): MutationProcess + private function buildCoveredMutationProcess(Mutation $mutation): MutantProcess { $processMock = $this->createMock(Process::class); $processMock @@ -371,7 +371,7 @@ private function buildCoveredMutationProcess(Mutation $mutation): MutationProces ->method($this->anything()) ; - return new MutationProcess($processMock, $mutation); + return new MutantProcess($processMock, $mutation); } private function someIterable(?callable $callback = null): Callback diff --git a/tests/phpunit/TestFramework/TestFrameworkExtraOptionsFilterTest.php b/tests/phpunit/TestFramework/TestFrameworkExtraOptionsFilterTest.php index c8bef4cbb..480735b43 100644 --- a/tests/phpunit/TestFramework/TestFrameworkExtraOptionsFilterTest.php +++ b/tests/phpunit/TestFramework/TestFrameworkExtraOptionsFilterTest.php @@ -41,11 +41,11 @@ final class TestFrameworkExtraOptionsFilterTest extends TestCase { /** - * @dataProvider mutationProcessProvider + * @dataProvider mutantProcessProvider */ - public function test_it_skips_filter_for_mutation_process(string $actualExtraOptions, string $expectedExtraOptions): void + public function test_it_skips_filter_for_mutant_process(string $actualExtraOptions, string $expectedExtraOptions): void { - $filteredOptions = (new TestFrameworkExtraOptionsFilter())->filterForMutationProcess( + $filteredOptions = (new TestFrameworkExtraOptionsFilter())->filterForMutantProcess( $actualExtraOptions, ['--configuration', '--filter', '--testsuite'] ); @@ -53,7 +53,7 @@ public function test_it_skips_filter_for_mutation_process(string $actualExtraOpt $this->assertSame($expectedExtraOptions, $filteredOptions); } - public function mutationProcessProvider(): iterable + public function mutantProcessProvider(): iterable { yield ['--filter=someTest#2 --a --b=value', '--a --b=value']; From b28b7d81a5a7b489f64e0ee43d96c2ae549c392a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20FIDRY?= Date: Fri, 3 Apr 2020 12:59:17 +0200 Subject: [PATCH 19/21] More revert --- src/Container.php | 12 ++++++------ .../MutationTestingConsoleLoggerSubscriber.php | 2 +- src/Mutant/MutantExecutionResult.php | 2 +- .../MutantExecutionResultFactory.php | 12 +++++------- src/{Mutation => Mutant}/MutationFactory.php | 5 +++-- src/Mutation/FileMutationGenerator.php | 1 + src/Mutator/NodeMutationGenerator.php | 2 +- src/Process/Builder/MutantProcessFactory.php | 2 +- src/Process/Runner/MutationTestingRunner.php | 2 +- src/TestFramework/Config/MutationConfigBuilder.php | 4 ++-- .../PhpUnit/Config/Builder/MutationConfigBuilder.php | 4 ++-- tests/phpunit/Event/MutantProcessWasFinishedTest.php | 2 +- tests/phpunit/Metrics/MetricsCalculatorTest.php | 4 ++-- .../MutantExecutionResultFactoryTest.php | 5 +++-- tests/phpunit/Mutant/MutantExecutionResultTest.php | 4 ++-- .../{Mutation => Mutant}/MutationFactoryTest.php | 5 +++-- tests/phpunit/Mutation/FileMutationGeneratorTest.php | 5 ++--- .../Process/Builder/MutantProcessFactoryTest.php | 12 ++++++------ .../Process/Runner/MutationTestingRunnerTest.php | 10 +++++----- 19 files changed, 48 insertions(+), 47 deletions(-) rename src/{Mutation => Mutant}/MutantExecutionResultFactory.php (90%) rename src/{Mutation => Mutant}/MutationFactory.php (98%) rename tests/phpunit/{Mutation => Mutant}/MutantExecutionResultFactoryTest.php (98%) rename tests/phpunit/{Mutation => Mutant}/MutationFactoryTest.php (98%) diff --git a/src/Container.php b/src/Container.php index ba074022d..9e31cd7e9 100644 --- a/src/Container.php +++ b/src/Container.php @@ -63,10 +63,10 @@ use Infection\Metrics\MetricsCalculator; use Infection\Metrics\MinMsiChecker; use Infection\Mutant\MutantCodeFactory; +use Infection\Mutant\MutantExecutionResultFactory; +use Infection\Mutant\MutationFactory; use Infection\Mutation\FileMutationGenerator; -use Infection\Mutation\MutantExecutionResultFactory; use Infection\Mutation\MutationAttributeKeys; -use Infection\Mutation\MutationFactory; use Infection\Mutation\MutationGenerator; use Infection\Mutator\MutatorFactory; use Infection\Mutator\MutatorParser; @@ -437,7 +437,7 @@ public static function create(): self $container->getTestFrameworkAdapter(), $container->getConfiguration()->getProcessTimeout(), $container->getEventDispatcher(), - $container->getMutationExecutionResultFactory() + $container->getMutantExecutionResultFactory() ); }, MutationGenerator::class => static function (self $container): MutationGenerator { @@ -453,7 +453,7 @@ public static function create(): self }, MutationTestingRunner::class => static function (self $container): MutationTestingRunner { return new MutationTestingRunner( - $container->getMutationProcessFactory(), + $container->getMutantProcessFactory(), $container->getProcessRunner(), $container->getEventDispatcher(), $container->getConfiguration()->isDryRun() @@ -834,7 +834,7 @@ public function getInitialTestsRunner(): InitialTestsRunner return $this->get(InitialTestsRunner::class); } - public function getMutationProcessFactory(): MutantProcessFactory + public function getMutantProcessFactory(): MutantProcessFactory { return $this->get(MutantProcessFactory::class); } @@ -884,7 +884,7 @@ public function getAdapterInstaller(): AdapterInstaller return $this->get(AdapterInstaller::class); } - public function getMutationExecutionResultFactory(): MutantExecutionResultFactory + public function getMutantExecutionResultFactory(): MutantExecutionResultFactory { return $this->get(MutantExecutionResultFactory::class); } diff --git a/src/Event/Subscriber/MutationTestingConsoleLoggerSubscriber.php b/src/Event/Subscriber/MutationTestingConsoleLoggerSubscriber.php index da72885d4..13a022223 100644 --- a/src/Event/Subscriber/MutationTestingConsoleLoggerSubscriber.php +++ b/src/Event/Subscriber/MutationTestingConsoleLoggerSubscriber.php @@ -88,7 +88,7 @@ public function onMutationProcessWasFinished(MutationTestingWasStarted $event): $this->outputFormatter->start($this->mutationCount); } - public function MutantProcessWasFinished(MutantProcessWasFinished $event): void + public function onMutantProcessWasFinished(MutantProcessWasFinished $event): void { $executionResult = $event->getExecutionResult(); diff --git a/src/Mutant/MutantExecutionResult.php b/src/Mutant/MutantExecutionResult.php index 3addbb098..05e4a5b61 100644 --- a/src/Mutant/MutantExecutionResult.php +++ b/src/Mutant/MutantExecutionResult.php @@ -75,7 +75,7 @@ public function __construct( $this->originalStartingLine = $originalStartingLine; } - public static function createFromNonExecutedByTestsMutation(Mutation $mutation): self + public static function createFromNonCoveredByTestsMutation(Mutation $mutation): self { return new self( '', diff --git a/src/Mutation/MutantExecutionResultFactory.php b/src/Mutant/MutantExecutionResultFactory.php similarity index 90% rename from src/Mutation/MutantExecutionResultFactory.php rename to src/Mutant/MutantExecutionResultFactory.php index f089c586f..4149a5520 100644 --- a/src/Mutation/MutantExecutionResultFactory.php +++ b/src/Mutant/MutantExecutionResultFactory.php @@ -33,11 +33,9 @@ declare(strict_types=1); -namespace Infection\Mutation; +namespace Infection\Mutant; use Infection\AbstractTestFramework\TestFrameworkAdapter; -use Infection\Mutant\DetectionStatus; -use Infection\Mutant\MutantExecutionResult; use Infection\Process\MutantProcess; use function Safe\sprintf; use Symfony\Component\Process\Process; @@ -56,15 +54,15 @@ public function __construct(TestFrameworkAdapter $testFrameworkAdapter) $this->testFrameworkAdapter = $testFrameworkAdapter; } - public function createFromProcess(MutantProcess $mutationProcess): MutantExecutionResult + public function createFromProcess(MutantProcess $mutantProcess): MutantExecutionResult { - $process = $mutationProcess->getProcess(); - $mutation = $mutationProcess->getMutation(); + $process = $mutantProcess->getProcess(); + $mutation = $mutantProcess->getMutation(); return new MutantExecutionResult( $process->getCommandLine(), $this->retrieveProcessOutput($process), - $this->retrieveDetectionStatus($mutationProcess), + $this->retrieveDetectionStatus($mutantProcess), $mutation->getDiff(), $mutation->getMutatorName(), $mutation->getOriginalFilePath(), diff --git a/src/Mutation/MutationFactory.php b/src/Mutant/MutationFactory.php similarity index 98% rename from src/Mutation/MutationFactory.php rename to src/Mutant/MutationFactory.php index ee63ff225..c9f47b508 100644 --- a/src/Mutation/MutationFactory.php +++ b/src/Mutant/MutationFactory.php @@ -33,13 +33,14 @@ declare(strict_types=1); -namespace Infection\Mutation; +namespace Infection\Mutant; use function array_intersect_key; use function implode; use Infection\AbstractTestFramework\Coverage\TestLocation; use Infection\Differ\Differ; -use Infection\Mutant\MutantCodeFactory; +use Infection\Mutation\Mutation; +use Infection\Mutation\MutationAttributeKeys; use Infection\PhpParser\MutatedNode; use function md5; use PhpParser\Node; diff --git a/src/Mutation/FileMutationGenerator.php b/src/Mutation/FileMutationGenerator.php index ee6f89843..a389ad897 100644 --- a/src/Mutation/FileMutationGenerator.php +++ b/src/Mutation/FileMutationGenerator.php @@ -35,6 +35,7 @@ namespace Infection\Mutation; +use Infection\Mutant\MutationFactory; use Infection\Mutator\Mutator; use Infection\Mutator\NodeMutationGenerator; use Infection\PhpParser\FileParser; diff --git a/src/Mutator/NodeMutationGenerator.php b/src/Mutator/NodeMutationGenerator.php index 8ecd51d6e..c191d7df6 100644 --- a/src/Mutator/NodeMutationGenerator.php +++ b/src/Mutator/NodeMutationGenerator.php @@ -37,8 +37,8 @@ use function count; use function get_class; +use Infection\Mutant\MutationFactory; use Infection\Mutation\Mutation; -use Infection\Mutation\MutationFactory; use Infection\PhpParser\MutatedNode; use Infection\PhpParser\Visitor\ReflectionVisitor; use Infection\TestFramework\Coverage\LineRangeCalculator; diff --git a/src/Process/Builder/MutantProcessFactory.php b/src/Process/Builder/MutantProcessFactory.php index 4496ed2e1..fadd76c3c 100644 --- a/src/Process/Builder/MutantProcessFactory.php +++ b/src/Process/Builder/MutantProcessFactory.php @@ -38,7 +38,7 @@ use Infection\AbstractTestFramework\TestFrameworkAdapter; use Infection\Event\EventDispatcher\EventDispatcher; use Infection\Event\MutantProcessWasFinished; -use Infection\Mutation\MutantExecutionResultFactory; +use Infection\Mutant\MutantExecutionResultFactory; use Infection\Mutation\Mutation; use Infection\Process\MutantProcess; use function method_exists; diff --git a/src/Process/Runner/MutationTestingRunner.php b/src/Process/Runner/MutationTestingRunner.php index 2a437c394..510aa1ac5 100644 --- a/src/Process/Runner/MutationTestingRunner.php +++ b/src/Process/Runner/MutationTestingRunner.php @@ -86,7 +86,7 @@ public function run(iterable $mutations, string $testFrameworkExtraOptions): voi } $this->eventDispatcher->dispatch(new MutantProcessWasFinished( - MutantExecutionResult::createFromNonExecutedByTestsMutation($mutation) + MutantExecutionResult::createFromNonCoveredByTestsMutation($mutation) )); return false; diff --git a/src/TestFramework/Config/MutationConfigBuilder.php b/src/TestFramework/Config/MutationConfigBuilder.php index 7996c531d..62124a302 100644 --- a/src/TestFramework/Config/MutationConfigBuilder.php +++ b/src/TestFramework/Config/MutationConfigBuilder.php @@ -61,7 +61,7 @@ abstract public function build( protected function getInterceptorFileContent( string $interceptorPath, string $originalFilePath, - string $mutationFilePath + string $mutantFilePath ): string { $infectionPhar = ''; @@ -81,7 +81,7 @@ protected function getInterceptorFileContent( use {$namespacePrefix}Infection\StreamWrapper\IncludeInterceptor; -IncludeInterceptor::intercept('{$originalFilePath}', '{$mutationFilePath}'); +IncludeInterceptor::intercept('{$originalFilePath}', '{$mutantFilePath}'); IncludeInterceptor::enable(); CONTENT; } diff --git a/src/TestFramework/PhpUnit/Config/Builder/MutationConfigBuilder.php b/src/TestFramework/PhpUnit/Config/Builder/MutationConfigBuilder.php index 6669def32..623b45e0e 100644 --- a/src/TestFramework/PhpUnit/Config/Builder/MutationConfigBuilder.php +++ b/src/TestFramework/PhpUnit/Config/Builder/MutationConfigBuilder.php @@ -154,7 +154,7 @@ private function getDom(): DOMDocument private function createCustomAutoloadWithInterceptor( string $originalFilePath, - string $mutationFilePath, + string $mutantFilePath, string $originalAutoloadFile ): string { $interceptorPath = IncludeInterceptor::LOCATION; @@ -171,7 +171,7 @@ private function createCustomAutoloadWithInterceptor( PHP , - $this->getInterceptorFileContent($interceptorPath, $originalFilePath, $mutationFilePath), + $this->getInterceptorFileContent($interceptorPath, $originalFilePath, $mutantFilePath), $originalAutoloadFile ); } diff --git a/tests/phpunit/Event/MutantProcessWasFinishedTest.php b/tests/phpunit/Event/MutantProcessWasFinishedTest.php index 4636faf24..63dab4023 100644 --- a/tests/phpunit/Event/MutantProcessWasFinishedTest.php +++ b/tests/phpunit/Event/MutantProcessWasFinishedTest.php @@ -41,7 +41,7 @@ final class MutantProcessWasFinishedTest extends TestCase { - public function test_it_exposes_its_mutation_process(): void + public function test_it_exposes_its_execution_result(): void { $executionResultMock = $this->createMock(MutantExecutionResult::class); diff --git a/tests/phpunit/Metrics/MetricsCalculatorTest.php b/tests/phpunit/Metrics/MetricsCalculatorTest.php index b40b7d384..d76e467dd 100644 --- a/tests/phpunit/Metrics/MetricsCalculatorTest.php +++ b/tests/phpunit/Metrics/MetricsCalculatorTest.php @@ -164,7 +164,7 @@ private function addMutationExecutionResult( $executionResults = []; for ($i = 0; $i < $count; ++$i) { - $executionResults[] = $this->createMutationExecutionResult($detectionStatus); + $executionResults[] = $this->createMutantExecutionResult($detectionStatus); } $calculator->collect(...$executionResults); @@ -172,7 +172,7 @@ private function addMutationExecutionResult( return $executionResults; } - private function createMutationExecutionResult(string $detectionStatus): MutantExecutionResult + private function createMutantExecutionResult(string $detectionStatus): MutantExecutionResult { $id = $this->id; ++$this->id; diff --git a/tests/phpunit/Mutation/MutantExecutionResultFactoryTest.php b/tests/phpunit/Mutant/MutantExecutionResultFactoryTest.php similarity index 98% rename from tests/phpunit/Mutation/MutantExecutionResultFactoryTest.php rename to tests/phpunit/Mutant/MutantExecutionResultFactoryTest.php index 17477500f..845024648 100644 --- a/tests/phpunit/Mutation/MutantExecutionResultFactoryTest.php +++ b/tests/phpunit/Mutant/MutantExecutionResultFactoryTest.php @@ -33,15 +33,16 @@ declare(strict_types=1); -namespace Infection\Tests\Mutation; +namespace Infection\Tests\Mutant; use Infection\AbstractTestFramework\Coverage\TestLocation; use Infection\AbstractTestFramework\TestFrameworkAdapter; use Infection\Mutant\DetectionStatus; -use Infection\Mutation\MutantExecutionResultFactory; +use Infection\Mutant\MutantExecutionResultFactory; use Infection\Mutation\Mutation; use Infection\Mutator\ZeroIteration\For_; use Infection\Process\MutantProcess; +use Infection\Tests\Mutation\MutantExecutionResultAssertions; use Infection\Tests\Mutator\MutatorName; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; diff --git a/tests/phpunit/Mutant/MutantExecutionResultTest.php b/tests/phpunit/Mutant/MutantExecutionResultTest.php index eabd6fb07..a92a9a588 100644 --- a/tests/phpunit/Mutant/MutantExecutionResultTest.php +++ b/tests/phpunit/Mutant/MutantExecutionResultTest.php @@ -86,7 +86,7 @@ public function test_it_can_be_instantiated(): void ); } - public function test_it_can_be_instantiated_from_a_mutation_non_executed_by_tests(): void + public function test_it_can_be_instantiated_from_a_mutation_non_covered_by_tests(): void { $mutationDiff = <<<'DIFF' --- Original @@ -116,7 +116,7 @@ public function test_it_can_be_instantiated_from_a_mutation_non_executed_by_test ); $this->assertResultStateIs( - MutantExecutionResult::createFromNonExecutedByTestsMutation($mutation), + MutantExecutionResult::createFromNonCoveredByTestsMutation($mutation), '', '', DetectionStatus::NOT_COVERED, diff --git a/tests/phpunit/Mutation/MutationFactoryTest.php b/tests/phpunit/Mutant/MutationFactoryTest.php similarity index 98% rename from tests/phpunit/Mutation/MutationFactoryTest.php rename to tests/phpunit/Mutant/MutationFactoryTest.php index a6a96c04f..806c56efc 100644 --- a/tests/phpunit/Mutation/MutationFactoryTest.php +++ b/tests/phpunit/Mutant/MutationFactoryTest.php @@ -33,15 +33,16 @@ declare(strict_types=1); -namespace Infection\Tests\Mutation; +namespace Infection\Tests\Mutant; use function array_merge; use Infection\AbstractTestFramework\Coverage\TestLocation; use Infection\Differ\Differ; use Infection\Mutant\MutantCodeFactory; -use Infection\Mutation\MutationFactory; +use Infection\Mutant\MutationFactory; use Infection\Mutator\Arithmetic\Plus; use Infection\PhpParser\MutatedNode; +use Infection\Tests\Mutation\MutationAssertions; use Infection\Tests\Mutator\MutatorName; use function md5; use PhpParser\Node; diff --git a/tests/phpunit/Mutation/FileMutationGeneratorTest.php b/tests/phpunit/Mutation/FileMutationGeneratorTest.php index 4558cd2a9..304a792af 100644 --- a/tests/phpunit/Mutation/FileMutationGeneratorTest.php +++ b/tests/phpunit/Mutation/FileMutationGeneratorTest.php @@ -39,7 +39,6 @@ use Infection\Container; use Infection\Mutation\FileMutationGenerator; use Infection\Mutation\Mutation; -use Infection\Mutation\MutationFactory; use Infection\Mutator\Arithmetic\Plus; use Infection\Mutator\IgnoreConfig; use Infection\Mutator\IgnoreMutator; @@ -72,7 +71,7 @@ final class FileMutationGeneratorTest extends TestCase private $traverserFactoryMock; /** - * @var MutationFactory|MockObject + * @var \Infection\Mutant\MutationFactory|MockObject */ private $mutationFactoryMock; @@ -85,7 +84,7 @@ protected function setUp(): void { $this->fileParserMock = $this->createMock(FileParser::class); $this->traverserFactoryMock = $this->createMock(NodeTraverserFactory::class); - $this->mutationFactoryMock = $this->createMock(MutationFactory::class); + $this->mutationFactoryMock = $this->createMock(\Infection\Mutant\MutationFactory::class); $this->mutationGenerator = new FileMutationGenerator( $this->fileParserMock, diff --git a/tests/phpunit/Process/Builder/MutantProcessFactoryTest.php b/tests/phpunit/Process/Builder/MutantProcessFactoryTest.php index 196b73405..f72a1785f 100644 --- a/tests/phpunit/Process/Builder/MutantProcessFactoryTest.php +++ b/tests/phpunit/Process/Builder/MutantProcessFactoryTest.php @@ -40,7 +40,7 @@ use Infection\AbstractTestFramework\TestFrameworkAdapter; use Infection\Event\MutantProcessWasFinished; use Infection\Mutant\MutantExecutionResult; -use Infection\Mutation\MutantExecutionResultFactory; +use Infection\Mutant\MutantExecutionResultFactory; use Infection\Mutation\Mutation; use Infection\Mutator\ZeroIteration\For_; use Infection\Process\Builder\MutantProcessFactory; @@ -117,9 +117,9 @@ public function test_it_creates_a_process_with_timeout(): void $resultFactoryMock ); - $mutationProcess = $factory->createProcessForMutation($mutation, $testFrameworkExtraOptions); + $mutantProcess = $factory->createProcessForMutation($mutation, $testFrameworkExtraOptions); - $process = $mutationProcess->getProcess(); + $process = $mutantProcess->getProcess(); $this->assertSame( PHP_OS_FAMILY === 'Windows' @@ -130,12 +130,12 @@ public function test_it_creates_a_process_with_timeout(): void $this->assertSame(100., $process->getTimeout()); $this->assertFalse($process->isStarted()); - $this->assertSame($mutation, $mutationProcess->getMutation()); - $this->assertFalse($mutationProcess->isTimedOut()); + $this->assertSame($mutation, $mutantProcess->getMutation()); + $this->assertFalse($mutantProcess->isTimedOut()); $this->assertSame([], $eventDispatcher->getEvents()); - $mutationProcess->terminateProcess(); + $mutantProcess->terminateProcess(); $eventsAfterCallbackCall = $eventDispatcher->getEvents(); diff --git a/tests/phpunit/Process/Runner/MutationTestingRunnerTest.php b/tests/phpunit/Process/Runner/MutationTestingRunnerTest.php index 936b5df14..8507cb030 100644 --- a/tests/phpunit/Process/Runner/MutationTestingRunnerTest.php +++ b/tests/phpunit/Process/Runner/MutationTestingRunnerTest.php @@ -151,8 +151,8 @@ public function test_it_applies_and_run_the_mutations(): void [$mutation1, $testFrameworkExtraOptions] ) ->willReturnOnConsecutiveCalls( - $process0 = $this->buildCoveredMutationProcess($mutation0), - $process1 = $this->buildCoveredMutationProcess($mutation1) + $process0 = $this->buildCoveredMutantProcess($mutation0), + $process1 = $this->buildCoveredMutantProcess($mutation1) ) ; @@ -198,8 +198,8 @@ public function test_it_applies_and_run_the_mutations_when_concurrent_execution_ [$mutation1, $testFrameworkExtraOptions] ) ->willReturnOnConsecutiveCalls( - $process0 = $this->buildCoveredMutationProcess($mutation0), - $process1 = $this->buildCoveredMutationProcess($mutation1) + $process0 = $this->buildCoveredMutantProcess($mutation0), + $process1 = $this->buildCoveredMutantProcess($mutation1) ) ; @@ -363,7 +363,7 @@ private function formatExpectedEvents(array $events): string ); } - private function buildCoveredMutationProcess(Mutation $mutation): MutantProcess + private function buildCoveredMutantProcess(Mutation $mutation): MutantProcess { $processMock = $this->createMock(Process::class); $processMock From 84c0707eb0178254e466563792aae0985eb17a13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20FIDRY?= Date: Fri, 3 Apr 2020 13:03:36 +0200 Subject: [PATCH 20/21] Polishing --- .../Subscriber/MutationTestingConsoleLoggerSubscriber.php | 2 +- tests/phpunit/AutoReview/Event/SubscriberTest.php | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Event/Subscriber/MutationTestingConsoleLoggerSubscriber.php b/src/Event/Subscriber/MutationTestingConsoleLoggerSubscriber.php index 13a022223..ab02f56d9 100644 --- a/src/Event/Subscriber/MutationTestingConsoleLoggerSubscriber.php +++ b/src/Event/Subscriber/MutationTestingConsoleLoggerSubscriber.php @@ -81,7 +81,7 @@ public function __construct( $this->diffColorizer = $diffColorizer; } - public function onMutationProcessWasFinished(MutationTestingWasStarted $event): void + public function onMutationTestingWasStarted(MutationTestingWasStarted $event): void { $this->mutationCount = $event->getMutationCount(); diff --git a/tests/phpunit/AutoReview/Event/SubscriberTest.php b/tests/phpunit/AutoReview/Event/SubscriberTest.php index 6ca6660f8..394659077 100644 --- a/tests/phpunit/AutoReview/Event/SubscriberTest.php +++ b/tests/phpunit/AutoReview/Event/SubscriberTest.php @@ -109,7 +109,10 @@ private function assertIsSubscriptionMethod(string $subscriberClass, ReflectionM $this->assertSame( $expectedSubscriptionMethodName, $method->getName(), - 'Expected the subscription method to follow the project naming convention' + sprintf( + 'Expected the subscription method of "%s" to follow the project naming convention', + $subscriberClass + ) ); } } From b7b93ef34ee23f0f4f30cbf9d1f0a56ac6cf4ebc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20FIDRY?= Date: Mon, 13 Apr 2020 21:04:40 +0200 Subject: [PATCH 21/21] Revert undesired renaming --- src/Mutant/MutantExecutionResultFactory.php | 2 +- src/Mutation/Mutation.php | 10 +++++----- src/Process/Factory/MutantProcessFactory.php | 2 +- src/Process/Runner/MutationTestingRunner.php | 2 +- tests/phpunit/Mutation/MutationAssertions.php | 4 ++-- tests/phpunit/Mutation/MutationTest.php | 4 ++-- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/Mutant/MutantExecutionResultFactory.php b/src/Mutant/MutantExecutionResultFactory.php index 4149a5520..8198485a5 100644 --- a/src/Mutant/MutantExecutionResultFactory.php +++ b/src/Mutant/MutantExecutionResultFactory.php @@ -85,7 +85,7 @@ private function retrieveProcessOutput(Process $process): string private function retrieveDetectionStatus(MutantProcess $mutantProcess): string { - if (!$mutantProcess->getMutation()->hasTests()) { + if (!$mutantProcess->getMutation()->isCoveredByTest()) { return DetectionStatus::NOT_COVERED; } diff --git a/src/Mutation/Mutation.php b/src/Mutation/Mutation.php index a98b62d97..5d1a93110 100644 --- a/src/Mutation/Mutation.php +++ b/src/Mutation/Mutation.php @@ -51,7 +51,7 @@ class Mutation private $mutatorName; private $originalStartingLine; private $tests; - private $executedByTests; + private $coveredByTests; private $mutationHash; private $mutationFilePath; private $mutatedCode; @@ -76,7 +76,7 @@ public function __construct( $this->mutatorName = $mutatorName; $this->originalStartingLine = $originalStartingLine; $this->tests = $tests; - $this->executedByTests = count($tests) > 0; + $this->coveredByTests = count($tests) > 0; $this->mutationHash = $mutationHash; $this->mutationFilePath = $mutationFilePath; $this->mutatedCode = $mutatedCode; @@ -98,15 +98,15 @@ public function getOriginalStartingLine(): int return $this->originalStartingLine; } - public function hasTests(): bool + public function isCoveredByTest(): bool { - return $this->executedByTests; + return $this->coveredByTests; } /** * @return TestLocation[] */ - public function getTests(): array + public function getAllTests(): array { return $this->tests; } diff --git a/src/Process/Factory/MutantProcessFactory.php b/src/Process/Factory/MutantProcessFactory.php index 094e05c68..469791c67 100644 --- a/src/Process/Factory/MutantProcessFactory.php +++ b/src/Process/Factory/MutantProcessFactory.php @@ -72,7 +72,7 @@ public function createProcessForMutation(Mutation $mutation, string $testFramewo { $process = new Process( $this->testFrameworkAdapter->getMutantCommandLine( - $mutation->getTests(), + $mutation->getAllTests(), $mutation->getFilePath(), $mutation->getHash(), $mutation->getOriginalFilePath(), diff --git a/src/Process/Runner/MutationTestingRunner.php b/src/Process/Runner/MutationTestingRunner.php index 25600c0d5..6458641e7 100644 --- a/src/Process/Runner/MutationTestingRunner.php +++ b/src/Process/Runner/MutationTestingRunner.php @@ -81,7 +81,7 @@ public function run(iterable $mutations, string $testFrameworkExtraOptions): voi $processes = take($mutations) ->filter(function (Mutation $mutation) { - if ($mutation->hasTests()) { + if ($mutation->isCoveredByTest()) { return true; } diff --git a/tests/phpunit/Mutation/MutationAssertions.php b/tests/phpunit/Mutation/MutationAssertions.php index a2d1473b3..1639e3e40 100644 --- a/tests/phpunit/Mutation/MutationAssertions.php +++ b/tests/phpunit/Mutation/MutationAssertions.php @@ -54,8 +54,8 @@ private function assertMutationSateIs( $this->assertSame($expectedOriginalFilePath, $mutation->getOriginalFilePath()); $this->assertSame($expectedMutatorName, $mutation->getMutatorName()); $this->assertSame($expectedOriginalStartingLine, $mutation->getOriginalStartingLine()); - $this->assertSame($expectedTests, $mutation->getTests()); - $this->assertSame($expectedHasTests, $mutation->hasTests()); + $this->assertSame($expectedTests, $mutation->getAllTests()); + $this->assertSame($expectedHasTests, $mutation->isCoveredByTest()); $this->assertSame($expectedHash, $mutation->getHash()); $this->assertSame($expectedFilePath, $mutation->getFilePath()); $this->assertSame($expectedCode, $mutation->getMutatedCode()); diff --git a/tests/phpunit/Mutation/MutationTest.php b/tests/phpunit/Mutation/MutationTest.php index e98853a3c..8b0d99f13 100644 --- a/tests/phpunit/Mutation/MutationTest.php +++ b/tests/phpunit/Mutation/MutationTest.php @@ -73,8 +73,8 @@ public function test_it_can_be_instantiated( $this->assertSame($originalFilePath, $mutation->getOriginalFilePath()); $this->assertSame($mutatorName, $mutation->getMutatorName()); $this->assertSame($originalStartingLine, $mutation->getOriginalStartingLine()); - $this->assertSame($tests, $mutation->getTests()); - $this->assertSame($expectedHasTests, $mutation->hasTests()); + $this->assertSame($tests, $mutation->getAllTests()); + $this->assertSame($expectedHasTests, $mutation->isCoveredByTest()); $this->assertSame($hash, $mutation->getHash()); $this->assertSame($filePath, $mutation->getFilePath()); $this->assertSame($code, $mutation->getMutatedCode());