-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8b6dabb
commit 9908744
Showing
10 changed files
with
198 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Pest\Mutate\Mutators\Removal; | ||
|
||
use Pest\Mutate\Mutators\Abstract\AbstractMutator; | ||
use PhpParser\Node; | ||
use PhpParser\Node\Expr\FuncCall; | ||
use PhpParser\Node\Stmt\Expression; | ||
use PhpParser\Node\Stmt\Nop; | ||
|
||
class RemoveFunctionCall extends AbstractMutator | ||
{ | ||
public const SET = 'Removal'; | ||
|
||
public const DESCRIPTION = 'Removes a function call'; | ||
|
||
public const DIFF = <<<'DIFF' | ||
foo(); // [tl! remove] | ||
DIFF; | ||
|
||
public static function nodesToHandle(): array | ||
{ | ||
return [Expression::class]; | ||
} | ||
|
||
public static function can(Node $node): bool | ||
{ | ||
if (! $node instanceof Expression) { | ||
return false; | ||
} | ||
|
||
return $node->expr instanceof FuncCall; | ||
} | ||
|
||
public static function mutate(Node $node): Node | ||
{ | ||
return new Nop(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Pest\Mutate\Mutators\Removal; | ||
|
||
use Pest\Mutate\Mutators\Abstract\AbstractMutator; | ||
use PhpParser\Node; | ||
use PhpParser\Node\Expr\MethodCall; | ||
use PhpParser\Node\Expr\StaticCall; | ||
use PhpParser\Node\Stmt\Expression; | ||
use PhpParser\Node\Stmt\Nop; | ||
|
||
class RemoveMethodCall extends AbstractMutator | ||
{ | ||
public const SET = 'Removal'; | ||
|
||
public const DESCRIPTION = 'Removes a method call'; | ||
|
||
public const DIFF = <<<'DIFF' | ||
$this->foo(); // [tl! remove] | ||
DIFF; | ||
|
||
public static function nodesToHandle(): array | ||
{ | ||
return [Expression::class]; | ||
} | ||
|
||
public static function can(Node $node): bool | ||
{ | ||
if (! $node instanceof Expression) { | ||
return false; | ||
} | ||
|
||
if ($node->expr instanceof MethodCall) { | ||
return true; | ||
} | ||
|
||
return $node->expr instanceof StaticCall; | ||
} | ||
|
||
public static function mutate(Node $node): Node | ||
{ | ||
return new Nop(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Pest\Mutate\Mutators\Sets; | ||
|
||
use Pest\Mutate\Contracts\MutatorSet; | ||
use Pest\Mutate\Mutators\Concerns\HasName; | ||
use Pest\Mutate\Mutators\Removal\RemoveFunctionCall; | ||
use Pest\Mutate\Mutators\Removal\RemoveMethodCall; | ||
|
||
class RemovalSet implements MutatorSet | ||
{ | ||
use HasName; | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public static function mutators(): array | ||
{ | ||
return [ | ||
RemoveFunctionCall::class, | ||
RemoveMethodCall::class, | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Pest\Mutate\Mutators\Removal\RemoveFunctionCall; | ||
|
||
it('removes a function call', function (): void { | ||
expect(mutateCode(RemoveFunctionCall::class, <<<'CODE' | ||
<?php | ||
foo(); | ||
CODE))->toBe(<<<'CODE' | ||
<?php | ||
|
||
|
||
CODE); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Pest\Mutate\Mutators\Removal\RemoveMethodCall; | ||
|
||
it('removes a method call', function (): void { | ||
expect(mutateCode(RemoveMethodCall::class, <<<'CODE' | ||
<?php | ||
class Foo | ||
{ | ||
function foo() | ||
{ | ||
$this->bar(); | ||
} | ||
} | ||
CODE))->toBe(<<<'CODE' | ||
<?php | ||
class Foo | ||
{ | ||
function foo() | ||
{ | ||
} | ||
} | ||
CODE); | ||
}); | ||
|
||
it('removes a static method call', function (): void { | ||
expect(mutateCode(RemoveMethodCall::class, <<<'CODE' | ||
<?php | ||
class Foo | ||
{ | ||
function foo() | ||
{ | ||
self::bar(); | ||
} | ||
} | ||
CODE))->toBe(<<<'CODE' | ||
<?php | ||
class Foo | ||
{ | ||
function foo() | ||
{ | ||
} | ||
} | ||
CODE); | ||
}); |