mirror of
https://github.com/rectorphp/rector.git
synced 2025-03-14 04:19:44 +01:00
fix PHPUnit Rectors
This commit is contained in:
parent
12c3909ea3
commit
0bed1c2711
@ -59,11 +59,11 @@ CODE_SAMPLE
|
||||
|
||||
public function isCandidate(Node $node): bool
|
||||
{
|
||||
if (! $this->isInTestClass($node)) {
|
||||
if (! $node instanceof ClassMethod) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (! $node instanceof ClassMethod) {
|
||||
if (! $this->isInTestClass($node)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -57,6 +57,10 @@ CODE_SAMPLE
|
||||
|
||||
public function isCandidate(Node $node): bool
|
||||
{
|
||||
if (! $node instanceof MethodCall) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (! $this->isInTestClass($node)) {
|
||||
return false;
|
||||
}
|
||||
|
@ -75,11 +75,11 @@ CODE_SAMPLE
|
||||
|
||||
public function isCandidate(Node $node): bool
|
||||
{
|
||||
if (! $this->isInTestClass($node)) {
|
||||
if (! $node instanceof ClassMethod) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (! $node instanceof ClassMethod) {
|
||||
if (! $this->isInTestClass($node)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -41,6 +41,10 @@ final class GetMockRector extends AbstractPHPUnitRector
|
||||
|
||||
public function isCandidate(Node $node): bool
|
||||
{
|
||||
if (! $node instanceof MethodCall) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (! $this->isInTestClass($node)) {
|
||||
return false;
|
||||
}
|
||||
|
@ -75,6 +75,10 @@ final class AssertCompareToSpecificMethodRector extends AbstractPHPUnitRector
|
||||
|
||||
public function isCandidate(Node $node): bool
|
||||
{
|
||||
if (! $node instanceof MethodCall) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (! $this->isInTestClass($node)) {
|
||||
return false;
|
||||
}
|
||||
|
@ -73,6 +73,10 @@ final class AssertComparisonToSpecificMethodRector extends AbstractPHPUnitRector
|
||||
|
||||
public function isCandidate(Node $node): bool
|
||||
{
|
||||
if (! $node instanceof MethodCall) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (! $this->isInTestClass($node)) {
|
||||
return false;
|
||||
}
|
||||
|
@ -59,6 +59,10 @@ final class AssertFalseStrposToContainsRector extends AbstractPHPUnitRector
|
||||
|
||||
public function isCandidate(Node $node): bool
|
||||
{
|
||||
if (! $node instanceof MethodCall) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (! $this->isInTestClass($node)) {
|
||||
return false;
|
||||
}
|
||||
|
@ -67,6 +67,10 @@ final class AssertInstanceOfComparisonRector extends AbstractPHPUnitRector
|
||||
|
||||
public function isCandidate(Node $node): bool
|
||||
{
|
||||
if (! $node instanceof MethodCall) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (! $this->isInTestClass($node)) {
|
||||
return false;
|
||||
}
|
||||
|
@ -57,6 +57,10 @@ final class AssertIssetToSpecificMethodRector extends AbstractPHPUnitRector
|
||||
|
||||
public function isCandidate(Node $node): bool
|
||||
{
|
||||
if (! $node instanceof MethodCall) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (! $this->isInTestClass($node)) {
|
||||
return false;
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ use PhpParser\Node;
|
||||
use PhpParser\Node\Arg;
|
||||
use PhpParser\Node\Expr\BooleanNot;
|
||||
use PhpParser\Node\Expr\MethodCall;
|
||||
use PhpParser\Node\Expr\StaticCall;
|
||||
use Rector\Builder\IdentifierRenamer;
|
||||
use Rector\NodeAnalyzer\MethodCallAnalyzer;
|
||||
use Rector\NodeAnalyzer\StaticMethodCallAnalyzer;
|
||||
@ -61,6 +62,10 @@ final class AssertNotOperatorRector extends AbstractPHPUnitRector
|
||||
|
||||
public function isCandidate(Node $node): bool
|
||||
{
|
||||
if (! $node instanceof MethodCall && ! $node instanceof StaticCall) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (! $this->isInTestClass($node)) {
|
||||
return false;
|
||||
}
|
||||
|
@ -78,6 +78,10 @@ final class AssertPropertyExistsRector extends AbstractPHPUnitRector
|
||||
|
||||
public function isCandidate(Node $node): bool
|
||||
{
|
||||
if (! $node instanceof MethodCall) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (! $this->isInTestClass($node)) {
|
||||
return false;
|
||||
}
|
||||
|
@ -53,6 +53,10 @@ final class AssertRegExpRector extends AbstractPHPUnitRector
|
||||
|
||||
public function isCandidate(Node $node): bool
|
||||
{
|
||||
if (! $node instanceof MethodCall) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (! $this->isInTestClass($node)) {
|
||||
return false;
|
||||
}
|
||||
|
@ -57,6 +57,10 @@ final class AssertSameBoolNullToSpecificMethodRector extends AbstractPHPUnitRect
|
||||
|
||||
public function isCandidate(Node $node): bool
|
||||
{
|
||||
if (! $node instanceof MethodCall) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (! $this->isInTestClass($node)) {
|
||||
return false;
|
||||
}
|
||||
|
@ -89,6 +89,10 @@ final class AssertTrueFalseInternalTypeToSpecificMethodRector extends AbstractPH
|
||||
|
||||
public function isCandidate(Node $node): bool
|
||||
{
|
||||
if (! $node instanceof MethodCall) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (! $this->isInTestClass($node)) {
|
||||
return false;
|
||||
}
|
||||
|
@ -90,6 +90,10 @@ final class AssertTrueFalseToSpecificMethodRector extends AbstractPHPUnitRector
|
||||
|
||||
public function isCandidate(Node $node): bool
|
||||
{
|
||||
if (! $node instanceof MethodCall) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (! $this->isInTestClass($node)) {
|
||||
return false;
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Tests\AssertTrueFalseToSpecificMethodRector;
|
||||
|
||||
abstract class Testing extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Tests\AssertTrueFalseToSpecificMethodRector;
|
||||
|
||||
abstract class Testing extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
}
|
||||
|
@ -3,6 +3,9 @@
|
||||
namespace Rector\Rector;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Stmt\Class_;
|
||||
use Rector\Exception\ShouldNotHappenException;
|
||||
use Rector\Node\Attribute;
|
||||
use Rector\NodeTypeResolver\NodeTypeResolver;
|
||||
|
||||
abstract class AbstractPHPUnitRector extends AbstractRector
|
||||
@ -24,8 +27,19 @@ abstract class AbstractPHPUnitRector extends AbstractRector
|
||||
|
||||
protected function isInTestClass(Node $node): bool
|
||||
{
|
||||
$nodeResolved = $this->nodeTypeResolver->resolve($node);
|
||||
/** @var Class_|null $classNode */
|
||||
$classNode = $node->getAttribute(Attribute::CLASS_NODE);
|
||||
|
||||
return ! array_intersect(['PHPUnit\Framework\TestCase', 'PHPUnit_Framework_TestCase'], $nodeResolved);
|
||||
if ($classNode === null) {
|
||||
throw new ShouldNotHappenException(sprintf(
|
||||
'"%s" should be set in "%s"',
|
||||
Attribute::CLASS_NODE,
|
||||
__METHOD__
|
||||
));
|
||||
}
|
||||
|
||||
$nodeTypes = $this->nodeTypeResolver->resolve($classNode);
|
||||
|
||||
return (bool) array_intersect(['PHPUnit\Framework\TestCase', 'PHPUnit_Framework_TestCase'], $nodeTypes);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user