Skip to content

Commit

Permalink
Support custom mutators (#1686)
Browse files Browse the repository at this point in the history
* Support custom mutators

* Add e2e test to make sure Custom Mutator works as expected

- exclude Mutator, Definition, MutatorCategory from being prefixes by Box/Scoper

* Update expectations of e2e test

* Play with exposing/excluding extension points to work with bot `bin/infection` and `infection.phar`

* Allow custom mutators only as `RooNamespace\SubNamespace\Class`

Invalid FQCN are forbidden

* Replace `exclude-namespaces` with `expose-namespaces` for scoper config as per comments

* Revert "Replace `exclude-namespaces` with `expose-namespaces` for scoper config as per comments"

This reverts commit 809d8f2.

---------

Co-authored-by: Stanislav Vozhov <svozhov@plesk.com>
Co-authored-by: maks-rafalko <b0rn@list.ru>
  • Loading branch information
3 people committed May 14, 2024
1 parent 97818a8 commit 0d5fd7e
Show file tree
Hide file tree
Showing 42 changed files with 358 additions and 52 deletions.
2 changes: 1 addition & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 2 additions & 7 deletions devTools/phpstan-src-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,12 @@ parameters:
path: ../src/Mutator/MutatorResolver.php

-
message: "#^Parameter &\\$mutators by\\-ref type of method Infection\\\\Mutator\\\\MutatorResolver\\:\\:registerFromClass\\(\\) expects array\\<string, array\\<string\\>\\>, array\\<string, array\\<array\\<string\\>\\|string\\>\\> given\\.$#"
message: "#^Parameter &\\$mutators by\\-ref type of method Infection\\\\Mutator\\\\MutatorResolver\\:\\:registerFromClass\\(\\) expects array\\<string, array\\<string, string\\>\\>, array\\<string, array\\<string, array\\<string\\>\\|string\\>\\> given\\.$#"
count: 1
path: ../src/Mutator/MutatorResolver.php

-
message: "#^Parameter &\\$mutators by\\-ref type of method Infection\\\\Mutator\\\\MutatorResolver\\:\\:registerFromClass\\(\\) expects array\\<string, array\\<string\\>\\>, array\\<string, array\\> given\\.$#"
count: 1
path: ../src/Mutator/MutatorResolver.php

-
message: "#^Parameter &\\$mutators by\\-ref type of method Infection\\\\Mutator\\\\MutatorResolver\\:\\:registerFromName\\(\\) expects array\\<string, array\\<string, string\\>\\>, array\\<string, array\\<string\\>\\> given\\.$#"
message: "#^Parameter &\\$mutators by\\-ref type of method Infection\\\\Mutator\\\\MutatorResolver\\:\\:registerFromClass\\(\\) expects array\\<string, array\\<string, string\\>\\>, array\\<string, array\\> given\\.$#"
count: 1
path: ../src/Mutator/MutatorResolver.php

Expand Down
5 changes: 0 additions & 5 deletions devTools/phpstan-src.neon
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,6 @@ parameters:
count: 1
path: ../src/Logger/Html/StrykerHtmlReportBuilder.php

-
message: "#^PHPDoc tag @var with type Infection\\\\Mutator\\\\Mutator\\<PhpParser\\\\NodeAbstract\\> is not subtype of native type 'Infection\\\\\\\\Mutator\\\\\\\\Arithmetic\\\\\\\\Assignment'\\|'Infection\\\\\\\\Mutator\\\\\\\\Arithmetic\\\\\\\\AssignmentEqual'\\|'Infection\\\\\\\\Mutator\\\\\\\\Arithmetic\\\\\\\\BitwiseAnd'\\|'Infection\\\\\\\\Mutator\\\\\\\\Arithmetic\\\\\\\\BitwiseNot'\\|'Infection\\\\\\\\Mutator\\\\\\\\Arithmetic\\\\\\\\BitwiseOr'\\|'Infection\\\\\\\\Mutator\\\\\\\\Arithmetic\\\\\\\\BitwiseXor'\\|'Infection\\\\\\\\Mutator\\\\\\\\Arithmetic\\\\\\\\Decrement'\\|'Infection\\\\\\\\Mutator\\\\\\\\Arithmetic\\\\\\\\DivEqual'\\|'Infection\\\\\\\\Mutator\\\\\\\\Arithmetic\\\\\\\\Division'\\|'Infection\\\\\\\\Mutator\\\\\\\\Arithmetic\\\\\\\\Exponentiation'\\|'Infection\\\\\\\\Mutator\\\\\\\\Arithmetic\\\\\\\\Increment'\\|'Infection\\\\\\\\Mutator\\\\\\\\Arithmetic\\\\\\\\Minus'\\|'Infection\\\\\\\\Mutator\\\\\\\\Arithmetic\\\\\\\\MinusEqual'\\|'Infection\\\\\\\\Mutator\\\\\\\\Arithmetic\\\\\\\\ModEqual'\\|'Infection\\\\\\\\Mutator\\\\\\\\Arithmetic\\\\\\\\Modulus'\\|'Infection\\\\\\\\Mutator\\\\\\\\Arithmetic\\\\\\\\MulEqual'\\|'Infection\\\\\\\\Mutator\\\\\\\\Arithmetic\\\\\\\\Multiplication'\\|'Infection\\\\\\\\Mutator\\\\\\\\Arithmetic\\\\\\\\Plus'\\|'Infection\\\\\\\\Mutator\\\\\\\\Arithmetic\\\\\\\\PlusEqual'\\|'Infection\\\\\\\\Mutator\\\\\\\\Arithmetic\\\\\\\\PowEqual'\\|'Infection\\\\\\\\Mutator\\\\\\\\Arithmetic\\\\\\\\RoundingFamily'\\|'Infection\\\\\\\\Mutator\\\\\\\\Arithmetic\\\\\\\\ShiftLeft'\\|'Infection\\\\\\\\Mutator\\\\\\\\Arithmetic\\\\\\\\ShiftRight'\\|'Infection\\\\\\\\Mutator\\\\\\\\Boolean\\\\\\\\ArrayItem'\\|'Infection\\\\\\\\Mutator\\\\\\\\Boolean\\\\\\\\EqualIdentical'\\|'Infection\\\\\\\\Mutator\\\\\\\\Boolean\\\\\\\\FalseValue'\\|'Infection\\\\\\\\Mutator\\\\\\\\Boolean\\\\\\\\IdenticalEqual'\\|'Infection\\\\\\\\Mutator\\\\\\\\Boolean\\\\\\\\InstanceOf_'\\|'Infection\\\\\\\\Mutator\\\\\\\\Boolean\\\\\\\\LogicalAnd'\\|'Infection\\\\\\\\Mutator\\\\\\\\Boolean\\\\\\\\LogicalAndAllSubExprNegation'\\|'Infection\\\\\\\\Mutator\\\\\\\\Boolean\\\\\\\\LogicalAndNegation'\\|'Infection\\\\\\\\Mutator\\\\\\\\Boolean\\\\\\\\LogicalAndSingleSubExprNegation'\\|'Infection\\\\\\\\Mutator\\\\\\\\Boolean\\\\\\\\LogicalLowerAnd'\\|'Infection\\\\\\\\Mutator\\\\\\\\Boolean\\\\\\\\LogicalLowerOr'\\|'Infection\\\\\\\\Mutator\\\\\\\\Boolean\\\\\\\\LogicalNot'\\|'Infection\\\\\\\\Mutator\\\\\\\\Boolean\\\\\\\\LogicalOr'\\|'Infection\\\\\\\\Mutator\\\\\\\\Boolean\\\\\\\\LogicalOrAllSubExprNegation'\\|'Infection\\\\\\\\Mutator\\\\\\\\Boolean\\\\\\\\LogicalOrNegation'\\|'Infection\\\\\\\\Mutator\\\\\\\\Boolean\\\\\\\\LogicalOrSingleSubExprNegation'\\|'Infection\\\\\\\\Mutator\\\\\\\\Boolean\\\\\\\\NotEqualNotIdentical'\\|'Infection\\\\\\\\Mutator\\\\\\\\Boolean\\\\\\\\NotIdenticalNotEqual'\\|'Infection\\\\\\\\Mutator\\\\\\\\Boolean\\\\\\\\TrueValue'\\|'Infection\\\\\\\\Mutator\\\\\\\\Boolean\\\\\\\\Yield_'\\|'Infection\\\\\\\\Mutator\\\\\\\\Cast\\\\\\\\CastArray'\\|'Infection\\\\\\\\Mutator\\\\\\\\Cast\\\\\\\\CastBool'\\|'Infection\\\\\\\\Mutator\\\\\\\\Cast\\\\\\\\CastFloat'\\|'Infection\\\\\\\\Mutator\\\\\\\\Cast\\\\\\\\CastInt'\\|'Infection\\\\\\\\Mutator\\\\\\\\Cast\\\\\\\\CastObject'\\|'Infection\\\\\\\\Mutator\\\\\\\\Cast\\\\\\\\CastString'\\|'Infection\\\\\\\\Mutator\\\\\\\\ConditionalBoundary\\\\\\\\GreaterThan'\\|'Infection\\\\\\\\Mutator\\\\\\\\ConditionalBoundary\\\\\\\\GreaterThanOrEqualTo'\\|'Infection\\\\\\\\Mutator\\\\\\\\ConditionalBoundary\\\\\\\\LessThan'\\|'Infection\\\\\\\\Mutator\\\\\\\\ConditionalBoundary\\\\\\\\LessThanOrEqualTo'\\|'Infection\\\\\\\\Mutator\\\\\\\\ConditionalNegotiation\\\\\\\\Equal'\\|'Infection\\\\\\\\Mutator\\\\\\\\ConditionalNegotiation\\\\\\\\GreaterThanNegotiation'\\|'Infection\\\\\\\\Mutator\\\\\\\\ConditionalNegotiation\\\\\\\\GreaterThanOrEqualToNegotiation'\\|'Infection\\\\\\\\Mutator\\\\\\\\ConditionalNegotiation\\\\\\\\Identical'\\|'Infection\\\\\\\\Mutator\\\\\\\\ConditionalNegotiation\\\\\\\\LessThanNegotiation'\\|'Infection\\\\\\\\Mutator\\\\\\\\ConditionalNegotiation\\\\\\\\LessThanOrEqualToNegotiation'\\|'Infection\\\\\\\\Mutator\\\\\\\\ConditionalNegotiation\\\\\\\\NotEqual'\\|'Infection\\\\\\\\Mutator\\\\\\\\ConditionalNegotiation\\\\\\\\NotIdentical'\\|'Infection\\\\\\\\Mutator\\\\\\\\Extensions\\\\\\\\BCMath'\\|'Infection\\\\\\\\Mutator\\\\\\\\Extensions\\\\\\\\MBString'\\|'Infection\\\\\\\\Mutator\\\\\\\\FunctionSignature\\\\\\\\ProtectedVisibility'\\|'Infection\\\\\\\\Mutator\\\\\\\\FunctionSignature\\\\\\\\PublicVisibility'\\|'Infection\\\\\\\\Mutator\\\\\\\\Loop\\\\\\\\DoWhile'\\|'Infection\\\\\\\\Mutator\\\\\\\\Loop\\\\\\\\For_'\\|'Infection\\\\\\\\Mutator\\\\\\\\Loop\\\\\\\\Foreach_'\\|'Infection\\\\\\\\Mutator\\\\\\\\Loop\\\\\\\\While_'\\|'Infection\\\\\\\\Mutator\\\\\\\\Number\\\\\\\\DecrementInteger'\\|'Infection\\\\\\\\Mutator\\\\\\\\Number\\\\\\\\IncrementInteger'\\|'Infection\\\\\\\\Mutator\\\\\\\\Number\\\\\\\\OneZeroFloat'\\|'Infection\\\\\\\\Mutator\\\\\\\\Operator\\\\\\\\AssignCoalesce'\\|'Infection\\\\\\\\Mutator\\\\\\\\Operator\\\\\\\\Break_'\\|'Infection\\\\\\\\Mutator\\\\\\\\Operator\\\\\\\\Catch_'\\|'Infection\\\\\\\\Mutator\\\\\\\\Operator\\\\\\\\Coalesce'\\|'Infection\\\\\\\\Mutator\\\\\\\\Operator\\\\\\\\Concat'\\|'Infection\\\\\\\\Mutator\\\\\\\\Operator\\\\\\\\Continue_'\\|'Infection\\\\\\\\Mutator\\\\\\\\Operator\\\\\\\\ElseIfNegation'\\|'Infection\\\\\\\\Mutator\\\\\\\\Operator\\\\\\\\Finally_'\\|'Infection\\\\\\\\Mutator\\\\\\\\Operator\\\\\\\\IfNegation'\\|'Infection\\\\\\\\Mutator\\\\\\\\Operator\\\\\\\\NullSafeMethodCall'\\|'Infection\\\\\\\\Mutator\\\\\\\\Operator\\\\\\\\NullSafePropertyCall'\\|'Infection\\\\\\\\Mutator\\\\\\\\Operator\\\\\\\\SpreadAssignment'\\|'Infection\\\\\\\\Mutator\\\\\\\\Operator\\\\\\\\SpreadOneItem'\\|'Infection\\\\\\\\Mutator\\\\\\\\Operator\\\\\\\\SpreadRemoval'\\|'Infection\\\\\\\\Mutator\\\\\\\\Operator\\\\\\\\Ternary'\\|'Infection\\\\\\\\Mutator\\\\\\\\Operator\\\\\\\\Throw_'\\|'Infection\\\\\\\\Mutator\\\\\\\\Regex\\\\\\\\PregMatchMatches'\\|'Infection\\\\\\\\Mutator\\\\\\\\Regex\\\\\\\\PregMatchRemoveCaret'\\|'Infection\\\\\\\\Mutator\\\\\\\\Regex\\\\\\\\PregMatchRemoveDollar'\\|'Infection\\\\\\\\Mutator\\\\\\\\Regex\\\\\\\\PregMatchRemoveFlags'\\|'Infection\\\\\\\\Mutator\\\\\\\\Regex\\\\\\\\PregQuote'\\|'Infection\\\\\\\\Mutator\\\\\\\\Removal\\\\\\\\ArrayItemRemoval'\\|'Infection\\\\\\\\Mutator\\\\\\\\Removal\\\\\\\\CatchBlockRemoval'\\|'Infection\\\\\\\\Mutator\\\\\\\\Removal\\\\\\\\CloneRemoval'\\|'Infection\\\\\\\\Mutator\\\\\\\\Removal\\\\\\\\ConcatOperandRemoval'\\|'Infection\\\\\\\\Mutator\\\\\\\\Removal\\\\\\\\FunctionCallRemoval'\\|'Infection\\\\\\\\Mutator\\\\\\\\Removal\\\\\\\\MatchArmRemoval'\\|'Infection\\\\\\\\Mutator\\\\\\\\Removal\\\\\\\\MethodCallRemoval'\\|'Infection\\\\\\\\Mutator\\\\\\\\Removal\\\\\\\\SharedCaseRemoval'\\|'Infection\\\\\\\\Mutator\\\\\\\\ReturnValue\\\\\\\\ArrayOneItem'\\|'Infection\\\\\\\\Mutator\\\\\\\\ReturnValue\\\\\\\\FloatNegation'\\|'Infection\\\\\\\\Mutator\\\\\\\\ReturnValue\\\\\\\\FunctionCall'\\|'Infection\\\\\\\\Mutator\\\\\\\\ReturnValue\\\\\\\\IntegerNegation'\\|'Infection\\\\\\\\Mutator\\\\\\\\ReturnValue\\\\\\\\NewObject'\\|'Infection\\\\\\\\Mutator\\\\\\\\ReturnValue\\\\\\\\This'\\|'Infection\\\\\\\\Mutator\\\\\\\\ReturnValue\\\\\\\\YieldValue'\\|'Infection\\\\\\\\Mutator\\\\\\\\Sort\\\\\\\\Spaceship'\\|'Infection\\\\\\\\Mutator\\\\\\\\SyntaxError'\\|'Infection\\\\\\\\Mutator\\\\\\\\Unwrap\\\\\\\\UnwrapArrayChangeKeyCase'\\|'Infection\\\\\\\\Mutator\\\\\\\\Unwrap\\\\\\\\UnwrapArrayChunk'\\|'Infection\\\\\\\\Mutator\\\\\\\\Unwrap\\\\\\\\UnwrapArrayColumn'\\|'Infection\\\\\\\\Mutator\\\\\\\\Unwrap\\\\\\\\UnwrapArrayCombine'\\|'Infection\\\\\\\\Mutator\\\\\\\\Unwrap\\\\\\\\UnwrapArrayDiff'\\|'Infection\\\\\\\\Mutator\\\\\\\\Unwrap\\\\\\\\UnwrapArrayDiffAssoc'\\|'Infection\\\\\\\\Mutator\\\\\\\\Unwrap\\\\\\\\UnwrapArrayDiffKey'\\|'Infection\\\\\\\\Mutator\\\\\\\\Unwrap\\\\\\\\UnwrapArrayDiffUassoc'\\|'Infection\\\\\\\\Mutator\\\\\\\\Unwrap\\\\\\\\UnwrapArrayDiffUkey'\\|'Infection\\\\\\\\Mutator\\\\\\\\Unwrap\\\\\\\\UnwrapArrayFilter'\\|'Infection\\\\\\\\Mutator\\\\\\\\Unwrap\\\\\\\\UnwrapArrayFlip'\\|'Infection\\\\\\\\Mutator\\\\\\\\Unwrap\\\\\\\\UnwrapArrayIntersect'\\|'Infection\\\\\\\\Mutator\\\\\\\\Unwrap\\\\\\\\UnwrapArrayIntersectAssoc'\\|'Infection\\\\\\\\Mutator\\\\\\\\Unwrap\\\\\\\\UnwrapArrayIntersectKey'\\|'Infection\\\\\\\\Mutator\\\\\\\\Unwrap\\\\\\\\UnwrapArrayIntersectUassoc'\\|'Infection\\\\\\\\Mutator\\\\\\\\Unwrap\\\\\\\\UnwrapArrayIntersectUkey'\\|'Infection\\\\\\\\Mutator\\\\\\\\Unwrap\\\\\\\\UnwrapArrayKeys'\\|'Infection\\\\\\\\Mutator\\\\\\\\Unwrap\\\\\\\\UnwrapArrayMap'\\|'Infection\\\\\\\\Mutator\\\\\\\\Unwrap\\\\\\\\UnwrapArrayMerge'\\|'Infection\\\\\\\\Mutator\\\\\\\\Unwrap\\\\\\\\UnwrapArrayMergeRecursive'\\|'Infection\\\\\\\\Mutator\\\\\\\\Unwrap\\\\\\\\UnwrapArrayPad'\\|'Infection\\\\\\\\Mutator\\\\\\\\Unwrap\\\\\\\\UnwrapArrayReduce'\\|'Infection\\\\\\\\Mutator\\\\\\\\Unwrap\\\\\\\\UnwrapArrayReplace'\\|'Infection\\\\\\\\Mutator\\\\\\\\Unwrap\\\\\\\\UnwrapArrayReplaceRecursive'\\|'Infection\\\\\\\\Mutator\\\\\\\\Unwrap\\\\\\\\UnwrapArrayReverse'\\|'Infection\\\\\\\\Mutator\\\\\\\\Unwrap\\\\\\\\UnwrapArraySlice'\\|'Infection\\\\\\\\Mutator\\\\\\\\Unwrap\\\\\\\\UnwrapArraySplice'\\|'Infection\\\\\\\\Mutator\\\\\\\\Unwrap\\\\\\\\UnwrapArrayUdiff'\\|'Infection\\\\\\\\Mutator\\\\\\\\Unwrap\\\\\\\\UnwrapArrayUdiffAssoc'\\|'Infection\\\\\\\\Mutator\\\\\\\\Unwrap\\\\\\\\UnwrapArrayUdiffUassoc'\\|'Infection\\\\\\\\Mutator\\\\\\\\Unwrap\\\\\\\\UnwrapArrayUintersect'\\|'Infection\\\\\\\\Mutator\\\\\\\\Unwrap\\\\\\\\UnwrapArrayUintersectAssoc'\\|'Infection\\\\\\\\Mutator\\\\\\\\Unwrap\\\\\\\\UnwrapArrayUintersectUassoc'\\|'Infection\\\\\\\\Mutator\\\\\\\\Unwrap\\\\\\\\UnwrapArrayUnique'\\|'Infection\\\\\\\\Mutator\\\\\\\\Unwrap\\\\\\\\UnwrapArrayValues'\\|'Infection\\\\\\\\Mutator\\\\\\\\Unwrap\\\\\\\\UnwrapFinally'\\|'Infection\\\\\\\\Mutator\\\\\\\\Unwrap\\\\\\\\UnwrapLcFirst'\\|'Infection\\\\\\\\Mutator\\\\\\\\Unwrap\\\\\\\\UnwrapLtrim'\\|'Infection\\\\\\\\Mutator\\\\\\\\Unwrap\\\\\\\\UnwrapRtrim'\\|'Infection\\\\\\\\Mutator\\\\\\\\Unwrap\\\\\\\\UnwrapStrIreplace'\\|'Infection\\\\\\\\Mutator\\\\\\\\Unwrap\\\\\\\\UnwrapStrRepeat'\\|'Infection\\\\\\\\Mutator\\\\\\\\Unwrap\\\\\\\\UnwrapStrReplace'\\|'Infection\\\\\\\\Mutator\\\\\\\\Unwrap\\\\\\\\UnwrapStrRev'\\|'Infection\\\\\\\\Mutator\\\\\\\\Unwrap\\\\\\\\UnwrapStrShuffle'\\|'Infection\\\\\\\\Mutator\\\\\\\\Unwrap\\\\\\\\UnwrapStrToLower'\\|'Infection\\\\\\\\Mutator\\\\\\\\Unwrap\\\\\\\\UnwrapStrToUpper'\\|'Infection\\\\\\\\Mutator\\\\\\\\Unwrap\\\\\\\\UnwrapSubstr'\\|'Infection\\\\\\\\Mutator\\\\\\\\Unwrap\\\\\\\\UnwrapTrim'\\|'Infection\\\\\\\\Mutator\\\\\\\\Unwrap\\\\\\\\UnwrapUcFirst'\\|'Infection\\\\\\\\Mutator\\\\\\\\Unwrap\\\\\\\\UnwrapUcWords'\\.$#"
count: 1
path: ../src/Logger/Html/StrykerHtmlReportBuilder.php

-
message: "#^Generator expects value type list\\<PhpParser\\\\Node\\\\Stmt\\>, array\\<PhpParser\\\\Node\\\\Stmt\\> given\\.$#"
count: 1
Expand Down
3 changes: 3 additions & 0 deletions resources/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@
"mutators": {
"type": "object",
"additionalProperties": false,
"patternProperties": {
"^[\\w]+(?:\\\\[\\w]+){1,}$": { "$ref": "#/definitions/default-mutator-config" }
},
"description": "Contains the settings for different mutations and profiles",
"properties": {
"global-ignore": {
Expand Down
9 changes: 9 additions & 0 deletions scoper.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@

return [
'prefix' => 'Infected',
'expose-classes' => [
'Infection\Mutator\Definition',
'Infection\Mutator\Mutator',
'Infection\Mutator\MutatorCategory',
],
'exclude-namespaces' => [
// we have to exclude it cause Mutator depends on PhpParser/Node interface, and it's not in a separate package
'/^PhpParser/',
],
'exclude-constants' => [
// Symfony global constants
'/^SYMFONY\_[\p{L}_]+$/',
Expand Down
7 changes: 5 additions & 2 deletions src/Command/DescribeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
use Infection\Console\IO;
use Infection\Mutator\Definition;
use Infection\Mutator\Mutator;
use Infection\Mutator\MutatorResolver;
use Infection\Mutator\ProfileList;
use function sprintf;
use Symfony\Component\Console\Input\InputArgument;
Expand Down Expand Up @@ -71,7 +72,9 @@ protected function executeCommand(IO $io): bool
);
}

if (!array_key_exists($mutator, ProfileList::ALL_MUTATORS)) {
if (!array_key_exists($mutator, ProfileList::ALL_MUTATORS)
&& !MutatorResolver::isValidMutator($mutator)
) {
$io->error(sprintf(
'"The %s mutator does not exist"',
$mutator,
Expand All @@ -80,7 +83,7 @@ protected function executeCommand(IO $io): bool
return false;
}

$mutatorClass = ProfileList::ALL_MUTATORS[$mutator];
$mutatorClass = ProfileList::ALL_MUTATORS[$mutator] ?? $mutator;

Assert::subclassOf($mutatorClass, Mutator::class);

Expand Down
14 changes: 5 additions & 9 deletions src/Logger/Html/StrykerHtmlReportBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,17 @@
use Infection\Mutant\MutantExecutionResult;
use Infection\Mutator\FunctionSignature\ProtectedVisibility;
use Infection\Mutator\FunctionSignature\PublicVisibility;
use Infection\Mutator\Mutator;
use Infection\Mutator\MutatorFactory;
use Infection\Mutator\ProfileList;
use Infection\Mutator\MutatorResolver;
use Infection\Mutator\Removal\MethodCallRemoval;
use Infection\Str;
use function ltrim;
use function md5;
use const PHP_EOL;
use PhpParser\NodeAbstract;
use function Safe\file_get_contents;
use function Safe\preg_match;
use function Safe\preg_split;
use function sprintf;
use function str_starts_with;
use function strlen;
use function substr;
Expand Down Expand Up @@ -247,7 +246,7 @@ function (MutantExecutionResult $result) use ($originalCode): array {
'id' => $result->getMutantHash(),
'mutatorName' => $result->getMutatorName(),
'replacement' => Str::convertToUtf8(Str::trimLineReturns(ltrim($replacement))),
'description' => $this->getMutatorDescription($result->getMutatorName()),
'description' => $this->getMutatorDescription($result->getMutatorClass()),
'location' => [
'start' => ['line' => $result->getOriginalStartingLine(), 'column' => $startingColumn],
'end' => ['line' => $endingLine, 'column' => $endingColumn],
Expand Down Expand Up @@ -313,12 +312,9 @@ private function getTestsCompleted(string $processOutput): int
return 0;
}

private function getMutatorDescription(string $mutatorName): string
private function getMutatorDescription(string $mutatorClass): string
{
Assert::keyExists(ProfileList::ALL_MUTATORS, $mutatorName);

/** @var Mutator<NodeAbstract> $mutatorClass */
$mutatorClass = ProfileList::ALL_MUTATORS[$mutatorName];
Assert::true(MutatorResolver::isValidMutator($mutatorClass), sprintf('Unknown mutator "%s"', $mutatorClass));

$definition = $mutatorClass::getDefinition();

Expand Down
20 changes: 14 additions & 6 deletions src/Mutant/MutantExecutionResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@

namespace Infection\Mutant;

use function array_keys;
use Infection\AbstractTestFramework\Coverage\TestLocation;
use Infection\Mutator\ProfileList;
use Infection\Mutator\MutatorResolver;
use Later\Interfaces\Deferred;
use RuntimeException;
use function Safe\sprintf;
use function strlen;
use function strrpos;
use Webmozart\Assert\Assert;
Expand All @@ -51,7 +51,7 @@
class MutantExecutionResult
{
private readonly string $detectionStatus;
private readonly string $mutatorName;
private readonly string $mutatorClass;

/**
* @param Deferred<string> $mutantDiff
Expand All @@ -65,7 +65,8 @@ public function __construct(
string $detectionStatus,
private readonly Deferred $mutantDiff,
private readonly string $mutantHash,
string $mutatorName,
string $mutatorClass,
private readonly string $mutatorName,
private readonly string $originalFilePath,
private readonly int $originalStartingLine,
private readonly int $originalEndingLine,
Expand All @@ -76,9 +77,10 @@ public function __construct(
private readonly array $tests,
) {
Assert::oneOf($detectionStatus, DetectionStatus::ALL);
Assert::oneOf($mutatorName, array_keys(ProfileList::ALL_MUTATORS));
Assert::true(MutatorResolver::isValidMutator($mutatorClass), sprintf('Unknown mutator "%s"', $mutatorClass));

$this->detectionStatus = $detectionStatus;
$this->mutatorName = $mutatorName;
$this->mutatorClass = $mutatorClass;
}

public static function createFromNonCoveredMutant(Mutant $mutant): self
Expand Down Expand Up @@ -121,6 +123,11 @@ public function getMutantHash(): string
return $this->mutantHash;
}

public function getMutatorClass(): string
{
return $this->mutatorClass;
}

public function getMutatorName(): string
{
return $this->mutatorName;
Expand Down Expand Up @@ -197,6 +204,7 @@ private static function createFromMutant(Mutant $mutant, string $detectionStatus
$detectionStatus,
$mutant->getDiff(),
$mutant->getMutation()->getHash(),
$mutant->getMutation()->getMutatorClass(),
$mutant->getMutation()->getMutatorName(),
$mutation->getOriginalFilePath(),
$mutation->getOriginalStartingLine(),
Expand Down
1 change: 1 addition & 0 deletions src/Mutant/MutantExecutionResultFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public function createFromProcess(MutantProcess $mutantProcess): MutantExecution
$this->retrieveDetectionStatus($mutantProcess),
$mutant->getDiff(),
$mutation->getHash(),
$mutation->getMutatorClass(),
$mutation->getMutatorName(),
$mutation->getOriginalFilePath(),
$mutation->getOriginalStartingLine(),
Expand Down

0 comments on commit 0d5fd7e

Please sign in to comment.