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
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace Rector\PHPUnit\Tests\CodeQuality\Rector\Class_\ConstructClassMethodToSetUpTestCaseRector\Fixture;

use PHPUnit\Framework\TestCase;

final class SkipNonTestButHelper extends TestCase
{
private $someValue;

public function __construct()
{
$this->someValue = 1000;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,12 @@ public function refactor(Node $node): ?Node
return null;
}

$constructClassMethod = $node->getMethod(MethodName::CONSTRUCT);
if (! $constructClassMethod instanceof ClassMethod) {
if ($this->shouldSkipClass($node)) {
return null;
}

if ($this->classAnalyzer->isAnonymousClass($node)) {
$constructClassMethod = $node->getMethod(MethodName::CONSTRUCT);
if (! $constructClassMethod instanceof ClassMethod) {
return null;
}

Expand Down Expand Up @@ -218,4 +218,16 @@ private function isParentCallNamed(Node $node, string $desiredMethodName): bool

return $this->nodeNameResolver->isName($node->name, $desiredMethodName);
}

private function shouldSkipClass(Class_ $class): bool
{
$className = $this->getName($class);

// probably helper class with access to protected methods like createMock()
if (! str_ends_with((string) $className, 'Test') && ! str_ends_with((string) $className, 'TestCase')) {
return true;
}

return $this->classAnalyzer->isAnonymousClass($class);
}
}