diff --git a/devTools/Dockerfile b/devTools/Dockerfile index d213f3a19..96b46f548 100644 --- a/devTools/Dockerfile +++ b/devTools/Dockerfile @@ -35,7 +35,7 @@ RUN apk add --no-cache \ git \ zip -COPY --from=composer:2.1 /usr/bin/composer /usr/bin/composer +COPY --from=composer:2 /usr/bin/composer /usr/bin/composer COPY memory-limit.ini xdebug.ini ${PHP_INI_DIR}/conf.d/ RUN adduser -h /opt/infection -s /bin/bash -D infection diff --git a/devTools/phpstan-src-baseline.neon b/devTools/phpstan-src-baseline.neon index cf2c568b4..4cfab9fe2 100644 --- a/devTools/phpstan-src-baseline.neon +++ b/devTools/phpstan-src-baseline.neon @@ -371,17 +371,12 @@ parameters: path: ../src/Mutator/MutatorResolver.php - - message: "#^Parameter &\\$mutators by\\-ref type of method Infection\\\\Mutator\\\\MutatorResolver\\:\\:registerFromClass\\(\\) expects array\\\\>, array\\\\|string\\>\\> given\\.$#" + message: "#^Parameter &\\$mutators by\\-ref type of method Infection\\\\Mutator\\\\MutatorResolver\\:\\:registerFromClass\\(\\) expects array\\\\>, array\\\\|string\\>\\> given\\.$#" count: 1 path: ../src/Mutator/MutatorResolver.php - - message: "#^Parameter &\\$mutators by\\-ref type of method Infection\\\\Mutator\\\\MutatorResolver\\:\\:registerFromClass\\(\\) expects array\\\\>, array\\ given\\.$#" - count: 1 - path: ../src/Mutator/MutatorResolver.php - - - - message: "#^Parameter &\\$mutators by\\-ref type of method Infection\\\\Mutator\\\\MutatorResolver\\:\\:registerFromName\\(\\) expects array\\\\>, array\\\\> given\\.$#" + message: "#^Parameter &\\$mutators by\\-ref type of method Infection\\\\Mutator\\\\MutatorResolver\\:\\:registerFromClass\\(\\) expects array\\\\>, array\\ given\\.$#" count: 1 path: ../src/Mutator/MutatorResolver.php diff --git a/devTools/phpstan-src.neon b/devTools/phpstan-src.neon index bf63e83cb..af3414d5a 100644 --- a/devTools/phpstan-src.neon +++ b/devTools/phpstan-src.neon @@ -53,11 +53,6 @@ parameters: count: 1 path: ../src/Logger/Html/StrykerHtmlReportBuilder.php - - - message: "#^PHPDoc tag @var with type Infection\\\\Mutator\\\\Mutator\\ 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\\, array\\ given\\.$#" count: 1 diff --git a/scoper.inc.php b/scoper.inc.php index b19709078..73a198274 100644 --- a/scoper.inc.php +++ b/scoper.inc.php @@ -35,6 +35,11 @@ return [ 'prefix' => 'Infected', + 'exclude-classes' => [ + 'Infection\Mutator\Definition', + 'Infection\Mutator\Mutator', + 'Infection\Mutator\MutatorCategory', + ], 'exclude-constants' => [ // Symfony global constants '/^SYMFONY\_[\p{L}_]+$/', diff --git a/src/Logger/Html/StrykerHtmlReportBuilder.php b/src/Logger/Html/StrykerHtmlReportBuilder.php index c1c871092..5f724aa4d 100644 --- a/src/Logger/Html/StrykerHtmlReportBuilder.php +++ b/src/Logger/Html/StrykerHtmlReportBuilder.php @@ -64,6 +64,7 @@ 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; diff --git a/src/Mutant/MutantExecutionResult.php b/src/Mutant/MutantExecutionResult.php index d2b54eef8..b2ab593da 100644 --- a/src/Mutant/MutantExecutionResult.php +++ b/src/Mutant/MutantExecutionResult.php @@ -52,7 +52,6 @@ class MutantExecutionResult { private readonly string $detectionStatus; private readonly string $mutatorClass; - private readonly string $mutatorName; /** * @param Deferred $mutantDiff @@ -67,7 +66,7 @@ public function __construct( private readonly Deferred $mutantDiff, private readonly string $mutantHash, string $mutatorClass, - string $mutatorName, + private readonly string $mutatorName, private readonly string $originalFilePath, private readonly int $originalStartingLine, private readonly int $originalEndingLine, @@ -82,7 +81,6 @@ public function __construct( $this->detectionStatus = $detectionStatus; $this->mutatorClass = $mutatorClass; - $this->mutatorName = $mutatorName; } public static function createFromNonCoveredMutant(Mutant $mutant): self diff --git a/src/Mutation/Mutation.php b/src/Mutation/Mutation.php index 9c36586de..cb516a9b3 100644 --- a/src/Mutation/Mutation.php +++ b/src/Mutation/Mutation.php @@ -44,6 +44,7 @@ use Infection\TestFramework\Coverage\JUnit\JUnitTestCaseTimeAdder; use function md5; use PhpParser\Node; +use function sprintf; use Webmozart\Assert\Assert; /** @@ -52,8 +53,7 @@ */ class Mutation { - private string $mutatorClass; - private readonly string $mutatorName; + private readonly string $mutatorClass; /** @var array */ private readonly array $attributes; private readonly bool $coveredByTests; @@ -70,7 +70,7 @@ public function __construct( private readonly string $originalFilePath, private readonly array $originalFileAst, string $mutatorClass, - string $mutatorName, + private readonly string $mutatorName, array $attributes, private readonly string $mutatedNodeClass, private readonly MutatedNode $mutatedNode, @@ -83,7 +83,6 @@ public function __construct( Assert::keyExists($attributes, $key); } $this->mutatorClass = $mutatorClass; - $this->mutatorName = $mutatorName; $this->attributes = array_intersect_key($attributes, array_flip(MutationAttributeKeys::ALL)); $this->coveredByTests = $tests !== []; } diff --git a/src/Mutator/Definition.php b/src/Mutator/Definition.php index ff5be03ea..8fee0e033 100644 --- a/src/Mutator/Definition.php +++ b/src/Mutator/Definition.php @@ -37,9 +37,6 @@ use Webmozart\Assert\Assert; -/** - * @internal - */ final class Definition { private readonly string $category; diff --git a/src/Mutator/Mutator.php b/src/Mutator/Mutator.php index f4c9ca97f..50206326c 100644 --- a/src/Mutator/Mutator.php +++ b/src/Mutator/Mutator.php @@ -38,7 +38,6 @@ use PhpParser\Node; /** - * @internal * @template TNode of Node */ interface Mutator diff --git a/src/Mutator/MutatorCategory.php b/src/Mutator/MutatorCategory.php index b9daa2dfb..49950393c 100644 --- a/src/Mutator/MutatorCategory.php +++ b/src/Mutator/MutatorCategory.php @@ -37,9 +37,6 @@ use Infection\CannotBeInstantiated; -/** - * @internal - */ final class MutatorCategory { use CannotBeInstantiated; diff --git a/src/Mutator/MutatorFactory.php b/src/Mutator/MutatorFactory.php index 9712885df..0290c84e2 100644 --- a/src/Mutator/MutatorFactory.php +++ b/src/Mutator/MutatorFactory.php @@ -35,7 +35,6 @@ namespace Infection\Mutator; -use function array_flip; use function end; use function explode; use function is_a; diff --git a/src/Mutator/MutatorResolver.php b/src/Mutator/MutatorResolver.php index f98958c40..39e221847 100644 --- a/src/Mutator/MutatorResolver.php +++ b/src/Mutator/MutatorResolver.php @@ -42,6 +42,7 @@ use function class_exists; use function in_array; use InvalidArgumentException; +use function is_subclass_of; use function sprintf; use stdClass; @@ -116,7 +117,7 @@ public function resolve(array $mutatorSettings): array self::registerFromClass( $mutatorOrProfile, $resolvedSettings, - $mutators + $mutators, ); continue; diff --git a/tests/add_new_e2e b/tests/add_new_e2e index 3bd164ea1..3bdd3c4d5 100755 --- a/tests/add_new_e2e +++ b/tests/add_new_e2e @@ -17,7 +17,7 @@ cp -r Example_Test/src "$dirname"/src cp -r Example_Test/tests $dirname/tests cp Example_Test/composer.json $dirname/composer.json cp Example_Test/expected-output.txt $dirname/expected-output.txt -cp Example_Test/infection.json $dirname/infection.json +cp Example_Test/infection.json5 $dirname/infection.json5 cp Example_Test/phpunit.xml $dirname/phpunit.xml cp Example_Test/README.md $dirname/README.md diff --git a/tests/e2e/Custom_Mutator/README.md b/tests/e2e/Custom_Mutator/README.md new file mode 100644 index 000000000..baf513e33 --- /dev/null +++ b/tests/e2e/Custom_Mutator/README.md @@ -0,0 +1,9 @@ +# Title + +* Link to github ticket if relevant + +## Summary +Short summary of the ticket + +## Full Ticket +Full github ticket \ No newline at end of file diff --git a/tests/e2e/Custom_Mutator/composer.json b/tests/e2e/Custom_Mutator/composer.json new file mode 100644 index 000000000..cfd19925a --- /dev/null +++ b/tests/e2e/Custom_Mutator/composer.json @@ -0,0 +1,15 @@ +{ + "require-dev": { + "phpunit/phpunit": "^9.5.5" + }, + "autoload": { + "psr-4": { + "Custom_Mutator\\": "src/" + } + }, + "autoload-dev": { + "psr-4": { + "Custom_Mutator\\Test\\": "tests/" + } + } +} diff --git a/tests/e2e/Custom_Mutator/expected-output.txt b/tests/e2e/Custom_Mutator/expected-output.txt new file mode 100644 index 000000000..e4dbc2085 --- /dev/null +++ b/tests/e2e/Custom_Mutator/expected-output.txt @@ -0,0 +1,10 @@ +Total: 1 + +Killed: 1 +Errored: 0 +Syntax Errors: 0 +Escaped: 0 +Timed Out: 0 +Skipped: 0 +Ignored: 0 +Not Covered: 0 diff --git a/tests/e2e/Custom_Mutator/infection.json5 b/tests/e2e/Custom_Mutator/infection.json5 new file mode 100644 index 000000000..b21ef6a1e --- /dev/null +++ b/tests/e2e/Custom_Mutator/infection.json5 @@ -0,0 +1,20 @@ +{ + "$schema": "../../../resources/schema.json", + "timeout": 25, + "source": { + "directories": [ + "src" + ], + "excludes": [ + "Mutator/CustomMutator.php" + ] + }, + "mutators": { + "@default": false, + "Custom_Mutator\\Mutator\\CustomMutator": true + }, + "logs": { + "summary": "infection.log" + }, + "tmpDir": "." +} diff --git a/tests/e2e/Custom_Mutator/phpunit.xml b/tests/e2e/Custom_Mutator/phpunit.xml new file mode 100644 index 000000000..c11ab317a --- /dev/null +++ b/tests/e2e/Custom_Mutator/phpunit.xml @@ -0,0 +1,18 @@ + + + + + ./tests/ + + + + + + ./src/ + + + diff --git a/tests/e2e/Custom_Mutator/src/Mutator/CustomMutator.php b/tests/e2e/Custom_Mutator/src/Mutator/CustomMutator.php new file mode 100644 index 000000000..39ed5668d --- /dev/null +++ b/tests/e2e/Custom_Mutator/src/Mutator/CustomMutator.php @@ -0,0 +1,95 @@ + + */ +final class CustomMutator implements Mutator +{ + public function getName(): string + { + $parts = explode('\\', self::class); + + return end($parts); + } + + public static function getDefinition(): ?Definition + { + return new Definition( + <<<'TXT' + Replaces an addition operator (`+`) with a subtraction operator (`-`). + TXT + , + MutatorCategory::ORTHOGONAL_REPLACEMENT, + null, + <<<'DIFF' + - $a = $b + $c; + + $a = $b - $c; + DIFF, + ); + } + + /** + * @psalm-mutation-free + * + * @return iterable + */ + public function mutate(Node $node): iterable + { + yield new Node\Expr\BinaryOp\Minus($node->left, $node->right, $node->getAttributes()); + } + + public function canMutate(Node $node): bool + { + if (!$node instanceof Node\Expr\BinaryOp\Plus) { + return false; + } + + if ($node->left instanceof Node\Expr\Array_ || $node->right instanceof Node\Expr\Array_) { + return false; + } + + return true; + } +} diff --git a/tests/e2e/Custom_Mutator/src/SourceClass.php b/tests/e2e/Custom_Mutator/src/SourceClass.php new file mode 100644 index 000000000..37259f0fc --- /dev/null +++ b/tests/e2e/Custom_Mutator/src/SourceClass.php @@ -0,0 +1,14 @@ +assertSame('hello', $sourceClass->hello()); + } +} diff --git a/tests/e2e/Example_Test/infection.json b/tests/e2e/Example_Test/infection.json5 similarity index 100% rename from tests/e2e/Example_Test/infection.json rename to tests/e2e/Example_Test/infection.json5 diff --git a/tests/phpunit/AutoReview/ProjectCode/ProjectCodeProvider.php b/tests/phpunit/AutoReview/ProjectCode/ProjectCodeProvider.php index d863e98cd..b3f56f59f 100644 --- a/tests/phpunit/AutoReview/ProjectCode/ProjectCodeProvider.php +++ b/tests/phpunit/AutoReview/ProjectCode/ProjectCodeProvider.php @@ -64,6 +64,9 @@ use Infection\Metrics\MetricsCalculator; use Infection\Mutant\DetectionStatus; use Infection\Mutation\MutationAttributeKeys; +use Infection\Mutator\Definition; +use Infection\Mutator\Mutator; +use Infection\Mutator\MutatorCategory; use Infection\Mutator\NodeMutationGenerator; use Infection\Process\Runner\IndexedProcessBearer; use Infection\Process\ShellCommandLineExecutor; @@ -141,6 +144,9 @@ final class ProjectCodeProvider SchemaConfigurationFactory::class, SchemaConfigurationFileLoader::class, SchemaValidator::class, + Mutator::class, + Definition::class, + MutatorCategory::class, ]; /** diff --git a/tests/phpunit/PhpParser/Visitor/MutatorVisitorTest.php b/tests/phpunit/PhpParser/Visitor/MutatorVisitorTest.php index dbbf7dccd..79cf009e1 100644 --- a/tests/phpunit/PhpParser/Visitor/MutatorVisitorTest.php +++ b/tests/phpunit/PhpParser/Visitor/MutatorVisitorTest.php @@ -109,9 +109,9 @@ public function hello(): string 'path/to/file', $nodes, PublicVisibility::class, - MutatorName::getName(PublicVisibility::class), - [ - 'startTokenPos' => 28, + MutatorName::getName(PublicVisibility::class), + [ + 'startTokenPos' => 28, 'endTokenPos' => 46, 'startLine' => -1, 'endLine' => -1, @@ -160,9 +160,9 @@ public function hello(): string 'path/to/file', $nodes, PublicVisibility::class, - MutatorName::getName(PublicVisibility::class), - [ - 'startTokenPos' => 28, + MutatorName::getName(PublicVisibility::class), + [ + 'startTokenPos' => 28, 'endTokenPos' => 46, 'startLine' => -1, 'endLine' => -1, @@ -213,19 +213,19 @@ public function bye(): string 'path/to/file', $nodes, PublicVisibility::class, - MutatorName::getName(PublicVisibility::class), - [ - 'startTokenPos' => 29, - 'endTokenPos' => 50, - 'startLine' => -1, - 'endLine' => -1, - 'startFilePos' => -1, - 'endFilePos' => -1, - ], - ClassMethod::class, - MutatedNode::wrap(new Nop()), - 0, - [], + MutatorName::getName(PublicVisibility::class), + [ + 'startTokenPos' => 29, + 'endTokenPos' => 50, + 'startLine' => -1, + 'endLine' => -1, + 'startFilePos' => -1, + 'endFilePos' => -1, + ], + ClassMethod::class, + MutatedNode::wrap(new Nop()), + 0, + [], ), ])();