-
Notifications
You must be signed in to change notification settings - Fork 110
Setup mutation testing #686
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
base: 2.0.x
Are you sure you want to change the base?
Changes from all commits
8a4e7cd
65db2c8
d3a6e60
69b69ca
baab8a3
b44bb9c
d223186
843fbfe
7a2ece5
788a450
7517bac
0cf3164
811f79d
cf457bb
547569a
ba0c6b8
bcc667f
6075749
71c74c4
c180a99
ae2e5ff
e680440
1398077
d1637c4
80978eb
054bb5e
2ae9a03
fb3db22
c37fc3f
871cd46
7e0fd4a
946fc28
e509b9a
2eecbb9
704bce2
19706cb
2caea8d
9f9de8f
c4d823e
93d3d97
01a9197
58e765a
378e518
b3b8b99
67cf382
c0e5252
d954a45
13ad641
3bddff7
91d8b14
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"$schema": "vendor/infection/infection/resources/schema.json", | ||
"timeout": 30, | ||
"source": { | ||
"directories": [ | ||
"src" | ||
] | ||
}, | ||
"staticAnalysisTool": "phpstan", | ||
"logs": { | ||
"text": "tmp/infection.log" | ||
}, | ||
"mutators": { | ||
"@default": false, | ||
"PHPStan\\Infection\\TrinaryLogicMutator": true | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -69,6 +69,15 @@ | |
return []; | ||
} | ||
|
||
// testing stuff | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TODO: revert testing change |
||
$obj = (new ObjectType('Doctrine\ORM\QueryBuilder'))->isSuperTypeOf($calledOnType); | ||
if ($obj->yes()) { | ||
Check warning on line 74 in src/Rules/Doctrine/ORM/QueryBuilderDqlRule.php
|
||
$x = 1; | ||
} else { | ||
$x = 2; | ||
} | ||
|
||
|
||
try { | ||
$dqlType = $scope->getType(new MethodCall($node, new Node\Identifier('getDQL'), [])); | ||
} catch (Throwable $e) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace PHPStan\Infection; | ||
|
||
use Infection\Mutator\Definition; | ||
use Infection\Mutator\Mutator; | ||
use Infection\Mutator\MutatorCategory; | ||
use LogicException; | ||
use PhpParser\Node; | ||
use function in_array; | ||
|
||
/** | ||
* @implements Mutator<Node\Expr\MethodCall> | ||
*/ | ||
final class TrinaryLogicMutator implements Mutator | ||
{ | ||
|
||
public static function getDefinition(): Definition | ||
{ | ||
return new Definition( | ||
<<<'TXT' | ||
Replaces TrinaryLogic->yes() with !TrinaryLogic->no() and vice versa. | ||
TXT | ||
, | ||
MutatorCategory::ORTHOGONAL_REPLACEMENT, | ||
null, | ||
<<<'DIFF' | ||
- $type->isBoolean()->yes(); | ||
+ !$type->isBoolean()->no(); | ||
DIFF, | ||
); | ||
} | ||
|
||
public function getName(): string | ||
{ | ||
return 'TrinaryLogicMutator'; | ||
} | ||
|
||
public function canMutate(Node $node): bool | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. atm this class replaces any call to a method named There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
{ | ||
if (!$node instanceof Node\Expr\MethodCall) { | ||
return false; | ||
} | ||
|
||
if (!$node->name instanceof Node\Identifier) { | ||
return false; | ||
} | ||
|
||
if (!in_array($node->name->name, ['yes', 'no'], true)) { | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
public function mutate(Node $node): iterable | ||
{ | ||
if (!$node->name instanceof Node\Identifier) { | ||
throw new LogicException(); | ||
} | ||
|
||
if ($node->name->name === 'yes') { | ||
yield new Node\Expr\BooleanNot(new Node\Expr\MethodCall($node->var, 'no')); | ||
} else { | ||
yield new Node\Expr\BooleanNot(new Node\Expr\MethodCall($node->var, 'yes')); | ||
} | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Phpunit killer requires a green test run
Phpstan killer requires a green phpstan run