Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions config/sets/phpunit90.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
declare(strict_types=1);

use Rector\Config\RectorConfig;
use Rector\PHPUnit\PHPUnit90\Rector\MethodCall\AssertRegExpRector;
use Rector\PHPUnit\PHPUnit100\Rector\StmtsAwareInterface\WithConsecutiveRector;
use Rector\PHPUnit\PHPUnit90\Rector\Class_\TestListenerToHooksRector;
use Rector\PHPUnit\PHPUnit90\Rector\MethodCall\AssertRegExpRector;
use Rector\PHPUnit\PHPUnit90\Rector\MethodCall\ExplicitPhpErrorApiRector;
use Rector\PHPUnit\PHPUnit90\Rector\MethodCall\SpecificAssertContainsWithoutIdentityRector;
use Rector\Renaming\Rector\MethodCall\RenameMethodRector;
Expand All @@ -28,13 +28,8 @@
'expectExceptionMessageMatches'
),


// @see https://github.com/sebastianbergmann/phpunit/issues/4086
new MethodCallRename(
'PHPUnit\Framework\TestCase',
'assertRegExp',
'assertMatchesRegularExpression'
),
new MethodCallRename('PHPUnit\Framework\TestCase', 'assertRegExp', 'assertMatchesRegularExpression'),

// @see https://github.com/sebastianbergmann/phpunit/issues/4089
new MethodCallRename(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

// skip: non-string argument (enum case) should not crash

namespace Rector\PHPUnit\Tests\PHPUnit120\Rector\Class_\AssertIsTypeMethodCallRector\Fixture;

use PHPUnit\Framework\TestCase;

final class SkipNonPHPUnitType extends TestCase
{
public function testMethod(\stdClass $else): void
{
$else->isType('string');
$else->isType('array');
$else->isType();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Rector\PHPUnit\CodeQuality\Rector\ClassMethod;

use function in_array;
use PhpParser\Comment\Doc;
use PhpParser\Node;
use PhpParser\Node\Stmt\ClassMethod;
Expand All @@ -15,7 +16,6 @@
use Rector\Util\NewLineSplitter;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
use function in_array;

/**
* @see \Rector\PHPUnit\Tests\CodeQuality\Rector\ClassMethod\ReplaceTestAnnotationWithPrefixedFunctionRector\ReplaceTestAnnotationWithPrefixedFunctionRectorTest
Expand Down Expand Up @@ -87,7 +87,7 @@ public function refactor(Node $node): ?Node
}

$hasAnnotation = false;
foreach(NewLineSplitter::split($docComment->getText()) as $row) {
foreach (NewLineSplitter::split($docComment->getText()) as $row) {
if (in_array(trim($row), ['*@test', '* @test'], true)) {
$hasAnnotation = true;
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
*/
final class AssertIsTypeMethodCallRector extends AbstractRector
{
/**
* @var array<string, string>
*/
private const array IS_TYPE_VALUE_TO_METHOD = [
'array' => 'isArray',
'bool' => 'isBool',
Expand Down
18 changes: 17 additions & 1 deletion src/NodeAnalyzer/TestsNodeAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use PhpParser\Node\Stmt\ClassMethod;
use PHPStan\Reflection\ClassReflection;
use PHPStan\Type\ObjectType;
use PHPStan\Type\StaticType;
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
use Rector\NodeNameResolver\NodeNameResolver;
use Rector\NodeTypeResolver\NodeTypeResolver;
Expand Down Expand Up @@ -101,7 +102,22 @@ public function isPHPUnitMethodCallNames(Node $node, array $names): bool
public function isPHPUnitTestCaseCall(Node $node): bool
{
if ($node instanceof MethodCall) {
return $this->isInTestClass($node);
$callerType = $this->nodeTypeResolver->getType($node->var);
if ($callerType instanceof StaticType) {
$callerType = $callerType->getStaticObjectType();
}

if ($callerType instanceof ObjectType) {
if ($callerType->isInstanceOf(PHPUnitClassName::TEST_CASE)->yes()) {
return true;
}

if ($callerType->isInstanceOf(PHPUnitClassName::ASSERT)->yes()) {
return true;
}
}

return false;
}

if ($node instanceof StaticCall) {
Expand Down
Loading