Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove Mutant #1209

Open
wants to merge 27 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
c5fca90
Remove Mutant::isCoveredByTests() and rename Mutation::isCoveredByTes…
theofidry Mar 24, 2020
2980168
Remove redundant method
theofidry Mar 24, 2020
5d3835b
PoC: move mutant into mutation
theofidry Mar 24, 2020
ed88454
Fix most of the direct tests
theofidry Mar 24, 2020
18549c9
Merge remote-tracking branch 'upstream/master' into refactor/mutant-less
theofidry Mar 25, 2020
8ea638a
Remove occurrences of mutants
theofidry Mar 25, 2020
581b6a2
Fix CS
theofidry Mar 25, 2020
c163e11
Simplify FQCN
theofidry Mar 25, 2020
7c41456
Merge remote-tracking branch 'upstream/master' into refactor/mutant-less
theofidry Mar 25, 2020
c8f4c86
Fix some tests
theofidry Mar 25, 2020
a6993c5
Fix more tests
theofidry Mar 25, 2020
56e8026
Fix more tests
theofidry Mar 25, 2020
9e3bb0e
Fix SimpleMutation
theofidry Mar 25, 2020
cd8d203
Fix autoreview
theofidry Mar 25, 2020
57eb6ba
Fix
theofidry Mar 25, 2020
5a8428a
Merge remote-tracking branch 'upstream/master' into refactor/mutant-less
theofidry Mar 26, 2020
32a4908
Fix merge
theofidry Mar 26, 2020
0655692
Remove the Mutation laziness
theofidry Mar 27, 2020
6830cd6
Fix CS
theofidry Mar 27, 2020
e00f078
Merge remote-tracking branch 'upstream/master' into refactor/mutant-less
theofidry Mar 29, 2020
4437597
Revert ConfigurationFactory change
theofidry Apr 3, 2020
d73602d
Revert name changes
theofidry Apr 3, 2020
b28b7d8
More revert
theofidry Apr 3, 2020
0880fe7
Merge remote-tracking branch 'upstream/master' into refactor/mutant-less
theofidry Apr 3, 2020
84c0707
Polishing
theofidry Apr 3, 2020
5e1cdc6
Merge remote-tracking branch 'upstream/master' into refactor/mutant-less
theofidry Apr 13, 2020
b7b93ef
Revert undesired renaming
theofidry Apr 13, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
60 changes: 58 additions & 2 deletions doc/nomenclature.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -23,5 +72,12 @@ Artifact produced by a tracer: provides the piece of source code and its associa

<hr />

[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
14 changes: 7 additions & 7 deletions src/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
use Infection\Metrics\MinMsiChecker;
use Infection\Mutant\MutantCodeFactory;
use Infection\Mutant\MutantExecutionResultFactory;
use Infection\Mutant\MutantFactory;
use Infection\Mutant\MutationFactory;
use Infection\Mutation\FileMutationGenerator;
use Infection\Mutation\MutationAttributeKeys;
use Infection\Mutation\MutationGenerator;
Expand Down Expand Up @@ -224,8 +224,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(),
Expand Down Expand Up @@ -398,7 +398,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 {
Expand Down Expand Up @@ -453,7 +454,6 @@ public static function create(): self
MutationTestingRunner::class => static function (self $container): MutationTestingRunner {
return new MutationTestingRunner(
$container->getMutantProcessFactory(),
$container->getMutantFactory(),
$container->getProcessRunner(),
$container->getEventDispatcher(),
$container->getConfiguration()->isDryRun()
Expand Down Expand Up @@ -654,9 +654,9 @@ public function getMutantCodeFactory(): MutantCodeFactory
return $this->get(MutantCodeFactory::class);
}

public function getMutantFactory(): MutantFactory
public function getMutationFactory(): MutationFactory
{
return $this->get(MutantFactory::class);
return $this->get(MutationFactory::class);
}

public function getDiffer(): Differ
Expand Down
13 changes: 8 additions & 5 deletions src/Engine.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,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->filterForMutantProcess(
$extraOptions,
$this->adapter->getInitialRunOnlyOptions()
)
: $extraOptions;

$this->mutationTestingRunner->run($mutations, $filteredExtraOptionsForMutant);
$this->mutationTestingRunner->run($mutations, $mutationExtraOptions);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ private function showMutations(array $executionResults, string $headlinePrefix):
),
]);

$this->output->writeln($this->diffColorizer->colorize($executionResult->getMutantDiff()));
$this->output->writeln($this->diffColorizer->colorize($executionResult->getMutationDiff()));
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Logger/TextFileLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -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[] = '';
Expand Down
96 changes: 0 additions & 96 deletions src/Mutant/Mutant.php

This file was deleted.

20 changes: 15 additions & 5 deletions src/Mutant/MutantCodeFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@

namespace Infection\Mutant;

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;

Expand All @@ -54,14 +55,23 @@ public function __construct(PrettyPrinterAbstract $prettyPrinter)
$this->printer = $prettyPrinter;
}

public function createCode(Mutation $mutation): string
{
/**
* @param array<string|int|float> $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);
}
Expand Down
19 changes: 9 additions & 10 deletions src/Mutant/MutantExecutionResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
namespace Infection\Mutant;

use function array_keys;
use Infection\Mutation\Mutation;
use Infection\Mutator\ProfileList;
use Webmozart\Assert\Assert;

Expand All @@ -48,7 +49,7 @@ class MutantExecutionResult
private $processCommandLine;
private $processOutput;
private $detectionStatus;
private $mutantDiff;
private $mutationDiff;
private $mutatorName;
private $originalFilePath;
private $originalStartingLine;
Expand All @@ -57,7 +58,7 @@ public function __construct(
string $processCommandLine,
string $processOutput,
string $detectionStatus,
string $mutantDiff,
string $mutationDiff,
string $mutatorName,
string $originalFilePath,
int $originalStartingLine
Expand All @@ -68,22 +69,20 @@ 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(Mutant $mutant): self
public static function createFromNonCoveredByTestsMutation(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()
);
Expand All @@ -104,9 +103,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
Expand Down
7 changes: 3 additions & 4 deletions src/Mutant/MutantExecutionResultFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -86,7 +85,7 @@ private function retrieveProcessOutput(Process $process): string

private function retrieveDetectionStatus(MutantProcess $mutantProcess): string
{
if (!$mutantProcess->getMutant()->isCoveredByTest()) {
if (!$mutantProcess->getMutation()->hasTests()) {
theofidry marked this conversation as resolved.
Show resolved Hide resolved
return DetectionStatus::NOT_COVERED;
}

Expand Down