Updated Rector to commit 75d1dca2ef328d91cff2b642e79f1c442696d0a1

75d1dca2ef Don't get type from PropertyFetch for not natively typed properties (#3327)
This commit is contained in:
Tomas Votruba 2023-02-06 18:49:21 +00:00
parent ab40a52407
commit fc81ed9173
15 changed files with 251 additions and 57 deletions

2
vendor/autoload.php vendored
View File

@ -22,4 +22,4 @@ if (PHP_VERSION_ID < 50600) {
require_once __DIR__ . '/composer/autoload_real.php';
return ComposerAutoloaderInit6ed8c1e889d5a966c6689f7b3517e8f3::getLoader();
return ComposerAutoloaderInit8e924aa00232f07a8c77540879f7b1b1::getLoader();

View File

@ -2048,6 +2048,7 @@ return array(
'Rector\\PHPUnit\\NodeManipulator\\ParamAndArgFromArrayResolver' => $vendorDir . '/rector/rector-phpunit/src/NodeManipulator/ParamAndArgFromArrayResolver.php',
'Rector\\PHPUnit\\PhpDoc\\DataProviderMethodRenamer' => $vendorDir . '/rector/rector-phpunit/src/PhpDoc/DataProviderMethodRenamer.php',
'Rector\\PHPUnit\\PhpDoc\\PhpDocValueToNodeMapper' => $vendorDir . '/rector/rector-phpunit/src/PhpDoc/PhpDocValueToNodeMapper.php',
'Rector\\PHPUnit\\Rector\\ClassLike\\RemoveTestSuffixFromAbstractTestClassesRector' => $vendorDir . '/rector/rector-phpunit/src/Rector/ClassLike/RemoveTestSuffixFromAbstractTestClassesRector.php',
'Rector\\PHPUnit\\Rector\\ClassMethod\\AddDoesNotPerformAssertionToNonAssertingTestRector' => $vendorDir . '/rector/rector-phpunit/src/Rector/ClassMethod/AddDoesNotPerformAssertionToNonAssertingTestRector.php',
'Rector\\PHPUnit\\Rector\\ClassMethod\\CreateMockToAnonymousClassRector' => $vendorDir . '/rector/rector-phpunit/src/Rector/ClassMethod/CreateMockToAnonymousClassRector.php',
'Rector\\PHPUnit\\Rector\\ClassMethod\\DataProviderAnnotationToAttributeRector' => $vendorDir . '/rector/rector-phpunit/src/Rector/ClassMethod/DataProviderAnnotationToAttributeRector.php',

View File

@ -2,7 +2,7 @@
// autoload_real.php @generated by Composer
class ComposerAutoloaderInit6ed8c1e889d5a966c6689f7b3517e8f3
class ComposerAutoloaderInit8e924aa00232f07a8c77540879f7b1b1
{
private static $loader;
@ -22,17 +22,17 @@ class ComposerAutoloaderInit6ed8c1e889d5a966c6689f7b3517e8f3
return self::$loader;
}
spl_autoload_register(array('ComposerAutoloaderInit6ed8c1e889d5a966c6689f7b3517e8f3', 'loadClassLoader'), true, true);
spl_autoload_register(array('ComposerAutoloaderInit8e924aa00232f07a8c77540879f7b1b1', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
spl_autoload_unregister(array('ComposerAutoloaderInit6ed8c1e889d5a966c6689f7b3517e8f3', 'loadClassLoader'));
spl_autoload_unregister(array('ComposerAutoloaderInit8e924aa00232f07a8c77540879f7b1b1', 'loadClassLoader'));
require __DIR__ . '/autoload_static.php';
call_user_func(\Composer\Autoload\ComposerStaticInit6ed8c1e889d5a966c6689f7b3517e8f3::getInitializer($loader));
call_user_func(\Composer\Autoload\ComposerStaticInit8e924aa00232f07a8c77540879f7b1b1::getInitializer($loader));
$loader->setClassMapAuthoritative(true);
$loader->register(true);
$filesToLoad = \Composer\Autoload\ComposerStaticInit6ed8c1e889d5a966c6689f7b3517e8f3::$files;
$filesToLoad = \Composer\Autoload\ComposerStaticInit8e924aa00232f07a8c77540879f7b1b1::$files;
$requireFile = \Closure::bind(static function ($fileIdentifier, $file) {
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;

View File

@ -4,7 +4,7 @@
namespace Composer\Autoload;
class ComposerStaticInit6ed8c1e889d5a966c6689f7b3517e8f3
class ComposerStaticInit8e924aa00232f07a8c77540879f7b1b1
{
public static $files = array (
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
@ -2293,6 +2293,7 @@ class ComposerStaticInit6ed8c1e889d5a966c6689f7b3517e8f3
'Rector\\PHPUnit\\NodeManipulator\\ParamAndArgFromArrayResolver' => __DIR__ . '/..' . '/rector/rector-phpunit/src/NodeManipulator/ParamAndArgFromArrayResolver.php',
'Rector\\PHPUnit\\PhpDoc\\DataProviderMethodRenamer' => __DIR__ . '/..' . '/rector/rector-phpunit/src/PhpDoc/DataProviderMethodRenamer.php',
'Rector\\PHPUnit\\PhpDoc\\PhpDocValueToNodeMapper' => __DIR__ . '/..' . '/rector/rector-phpunit/src/PhpDoc/PhpDocValueToNodeMapper.php',
'Rector\\PHPUnit\\Rector\\ClassLike\\RemoveTestSuffixFromAbstractTestClassesRector' => __DIR__ . '/..' . '/rector/rector-phpunit/src/Rector/ClassLike/RemoveTestSuffixFromAbstractTestClassesRector.php',
'Rector\\PHPUnit\\Rector\\ClassMethod\\AddDoesNotPerformAssertionToNonAssertingTestRector' => __DIR__ . '/..' . '/rector/rector-phpunit/src/Rector/ClassMethod/AddDoesNotPerformAssertionToNonAssertingTestRector.php',
'Rector\\PHPUnit\\Rector\\ClassMethod\\CreateMockToAnonymousClassRector' => __DIR__ . '/..' . '/rector/rector-phpunit/src/Rector/ClassMethod/CreateMockToAnonymousClassRector.php',
'Rector\\PHPUnit\\Rector\\ClassMethod\\DataProviderAnnotationToAttributeRector' => __DIR__ . '/..' . '/rector/rector-phpunit/src/Rector/ClassMethod/DataProviderAnnotationToAttributeRector.php',
@ -3087,9 +3088,9 @@ class ComposerStaticInit6ed8c1e889d5a966c6689f7b3517e8f3
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInit6ed8c1e889d5a966c6689f7b3517e8f3::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit6ed8c1e889d5a966c6689f7b3517e8f3::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit6ed8c1e889d5a966c6689f7b3517e8f3::$classMap;
$loader->prefixLengthsPsr4 = ComposerStaticInit8e924aa00232f07a8c77540879f7b1b1::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit8e924aa00232f07a8c77540879f7b1b1::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit8e924aa00232f07a8c77540879f7b1b1::$classMap;
}, null, ClassLoader::class);
}

View File

@ -2059,12 +2059,12 @@
"source": {
"type": "git",
"url": "https:\/\/github.com\/rectorphp\/rector-phpunit.git",
"reference": "008ad4d517f1c62aa7a56124fbe3b59d3c568e5f"
"reference": "dcfdf20afde70255c8621828d915747b65575949"
},
"dist": {
"type": "zip",
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-phpunit\/zipball\/008ad4d517f1c62aa7a56124fbe3b59d3c568e5f",
"reference": "008ad4d517f1c62aa7a56124fbe3b59d3c568e5f",
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-phpunit\/zipball\/dcfdf20afde70255c8621828d915747b65575949",
"reference": "dcfdf20afde70255c8621828d915747b65575949",
"shasum": ""
},
"require": {
@ -2079,7 +2079,7 @@
"phpstan\/phpstan-strict-rules": "^1.4.5",
"phpstan\/phpstan-webmozart-assert": "^1.2.2",
"phpunit\/phpunit": "^10.0",
"rector\/phpstan-rules": "^0.6.5",
"rector\/phpstan-rules": "^0.6",
"rector\/rector-debugging": "dev-main",
"rector\/rector-generator": "^0.6.14",
"rector\/rector-src": "dev-main",
@ -2088,9 +2088,12 @@
"symplify\/phpstan-extensions": "^11.1",
"symplify\/phpstan-rules": "^11.2.3",
"symplify\/rule-doc-generator": "^11.2",
"symplify\/vendor-patches": "^11.2.0"
"symplify\/vendor-patches": "^11.2.0",
"tomasvotruba\/cognitive-complexity": "^0.0.5",
"tomasvotruba\/type-coverage": "^0.0.9",
"tomasvotruba\/unused-public": "^0.0.34"
},
"time": "2023-02-06T16:07:10+00:00",
"time": "2023-02-06T18:30:45+00:00",
"default-branch": true,
"type": "rector-extension",
"extra": {

File diff suppressed because one or more lines are too long

View File

@ -9,7 +9,7 @@ namespace Rector\RectorInstaller;
*/
final class GeneratedConfig
{
public const EXTENSIONS = array('rector/rector-doctrine' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-doctrine', 'relative_install_path' => '../../rector-doctrine', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main ea9cf46'), 'rector/rector-downgrade-php' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-downgrade-php', 'relative_install_path' => '../../rector-downgrade-php', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 46346e2'), 'rector/rector-php-parser' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-php-parser', 'relative_install_path' => '../../rector-php-parser', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 9639ef9'), 'rector/rector-phpunit' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-phpunit', 'relative_install_path' => '../../rector-phpunit', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 008ad4d'), 'rector/rector-symfony' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-symfony', 'relative_install_path' => '../../rector-symfony', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main cd25b6a'));
public const EXTENSIONS = array('rector/rector-doctrine' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-doctrine', 'relative_install_path' => '../../rector-doctrine', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main ea9cf46'), 'rector/rector-downgrade-php' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-downgrade-php', 'relative_install_path' => '../../rector-downgrade-php', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 46346e2'), 'rector/rector-php-parser' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-php-parser', 'relative_install_path' => '../../rector-php-parser', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 9639ef9'), 'rector/rector-phpunit' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-phpunit', 'relative_install_path' => '../../rector-phpunit', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main dcfdf20'), 'rector/rector-symfony' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-symfony', 'relative_install_path' => '../../rector-symfony', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main cd25b6a'));
private function __construct()
{
}

View File

@ -14,14 +14,17 @@
"symplify\/phpstan-extensions": "^11.1",
"symplify\/easy-coding-standard": "^11.2",
"symplify\/rule-doc-generator": "^11.2",
"rector\/phpstan-rules": "^0.6.5",
"rector\/phpstan-rules": "^0.6",
"phpstan\/extension-installer": "^1.2",
"phpstan\/phpstan-strict-rules": "^1.4.5",
"phpstan\/phpstan-webmozart-assert": "^1.2.2",
"symplify\/vendor-patches": "^11.2.0",
"symplify\/easy-ci": "^11.2.0",
"rector\/rector-generator": "^0.6.14",
"rector\/rector-debugging": "dev-main"
"rector\/rector-debugging": "dev-main",
"tomasvotruba\/type-coverage": "^0.0.9",
"tomasvotruba\/unused-public": "^0.0.34",
"tomasvotruba\/cognitive-complexity": "^0.0.5"
},
"autoload": {
"psr-4": {

View File

@ -5,7 +5,8 @@ namespace RectorPrefix202302;
use Rector\Config\RectorConfig;
use Rector\PHPUnit\Rector\Class_\StaticDataProviderClassMethodRector;
use Rector\PHPUnit\Rector\ClassLike\RemoveTestSuffixFromAbstractTestClassesRector;
return static function (RectorConfig $rectorConfig) : void {
$rectorConfig->import(__DIR__ . '/annotations-to-attributes.php');
$rectorConfig->rules([StaticDataProviderClassMethodRector::class]);
$rectorConfig->rules([StaticDataProviderClassMethodRector::class, RemoveTestSuffixFromAbstractTestClassesRector::class]);
};

View File

@ -1,4 +1,4 @@
# 46 Rules Overview
# 48 Rules Overview
## AddDoesNotPerformAssertionToNonAssertingTestRector
@ -87,7 +87,12 @@ use Rector\PHPUnit\Rector\Class_\AnnotationWithValueToAttributeRector;
use Rector\PHPUnit\ValueObject\AnnotationWithValueToAttribute;
return static function (RectorConfig $rectorConfig): void {
$rectorConfig->ruleWithConfiguration(AnnotationWithValueToAttributeRector::class, [new AnnotationWithValueToAttribute('backupGlobals', 'PHPUnit\Framework\Attributes\BackupGlobals', [true, false])]);
$rectorConfig->ruleWithConfiguration(AnnotationWithValueToAttributeRector::class, [
new AnnotationWithValueToAttribute('backupGlobals', 'PHPUnit\Framework\Attributes\BackupGlobals', [
true,
false,
]),
]);
};
```
@ -126,7 +131,11 @@ use Rector\PHPUnit\Rector\Class_\ArrayArgumentToDataProviderRector;
use Rector\PHPUnit\ValueObject\ArrayArgumentToDataProvider;
return static function (RectorConfig $rectorConfig): void {
$rectorConfig->ruleWithConfiguration(ArrayArgumentToDataProviderRector::class, [ArrayArgumentToDataProviderRector::ARRAY_ARGUMENTS_TO_DATA_PROVIDERS => [new ArrayArgumentToDataProvider('PHPUnit\Framework\TestCase', 'doTestMultiple', 'doTestSingle', 'number')]]);
$rectorConfig->ruleWithConfiguration(ArrayArgumentToDataProviderRector::class, [
ArrayArgumentToDataProviderRector::ARRAY_ARGUMENTS_TO_DATA_PROVIDERS => [
new ArrayArgumentToDataProvider('PHPUnit\Framework\TestCase', 'doTestMultiple', 'doTestSingle', 'number'),
],
]);
};
```
@ -551,6 +560,29 @@ Replaces `createMock()` with `createStub()` when relevant
<br>
## DataProviderAnnotationToAttributeRector
Change dataProvider annotations to attribute
- class: [`Rector\PHPUnit\Rector\ClassMethod\DataProviderAnnotationToAttributeRector`](../src/Rector/ClassMethod/DataProviderAnnotationToAttributeRector.php)
```diff
use PHPUnit\Framework\TestCase;
final class SomeTest extends TestCase
{
- /**
- * @dataProvider someMethod()
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('test')]
public function test(): void
{
}
}
```
<br>
## DelegateExceptionArgumentsRector
Takes `setExpectedException()` 2nd and next arguments to own methods in PHPUnit.
@ -803,6 +835,25 @@ Remove `"setMethods()"` method as never used
<br>
## RemoveTestSuffixFromAbstractTestClassesRector
Rename abstract test class suffix from "*Test" to "*TestCase"
- class: [`Rector\PHPUnit\Rector\ClassLike\RemoveTestSuffixFromAbstractTestClassesRector`](../src/Rector/ClassLike/RemoveTestSuffixFromAbstractTestClassesRector.php)
```diff
-// tests/AbstractTest.php
+// tests/AbstractTestCase.php
use PHPUnit\Framework\TestCase;
-abstract class AbstractTest extends TestCase
+abstract class AbstractTestCase extends TestCase
{
}
```
<br>
## ReplaceAssertArraySubsetWithDmsPolyfillRector
Change `assertArraySubset()` to static call of DMS\PHPUnitExtensions\ArraySubset\Assert

View File

@ -5,6 +5,7 @@ namespace RectorPrefix202302;
use Rector\Config\RectorConfig;
use Rector\Php55\Rector\String_\StringClassNameToClassConstantRector;
use Rector\PHPUnit\Set\PHPUnitSetList;
use Rector\Set\ValueObject\LevelSetList;
use Rector\Set\ValueObject\SetList;
return static function (RectorConfig $rectorConfig) : void {
@ -14,6 +15,7 @@ return static function (RectorConfig $rectorConfig) : void {
// for tests
'*/Source/*',
'*/Fixture/*',
'*/Expected/*',
// object types
StringClassNameToClassConstantRector::class => [__DIR__ . '/src/Rector/MethodCall/UseSpecificWillMethodRector.php', __DIR__ . '/src/Rector/Class_/TestListenerToHooksRector.php', __DIR__ . '/src/NodeFactory/ConsecutiveAssertionFactory.php', __DIR__ . '/src/NodeAnalyzer/TestsNodeAnalyzer.php', __DIR__ . '/src/NodeFactory/DataProviderClassMethodFactory.php', __DIR__ . '/config'],
]);
@ -22,7 +24,7 @@ return static function (RectorConfig $rectorConfig) : void {
__DIR__ . '/config/config.php',
LevelSetList::UP_TO_PHP_81,
SetList::DEAD_CODE,
\Rector\PHPUnit\Set\PHPUnitSetList::PHPUNIT_100,
PHPUnitSetList::PHPUNIT_100,
SetList::CODE_QUALITY,
SetList::CODING_STYLE,
SetList::EARLY_RETURN,

View File

@ -0,0 +1,107 @@
<?php
declare (strict_types=1);
namespace Rector\PHPUnit\Rector\ClassLike;
use PhpParser\Node;
use PhpParser\Node\Identifier;
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\Namespace_;
use Rector\Core\Configuration\RenamedClassesDataCollector;
use Rector\Core\Exception\ShouldNotHappenException;
use Rector\Core\Rector\AbstractRector;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Rector\PHPUnit\NodeAnalyzer\TestsNodeAnalyzer;
use Rector\Symfony\Printer\NeighbourClassLikePrinter;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
/**
* @see \Rector\PHPUnit\Tests\Rector\ClassLike\RemoveTestSuffixFromAbstractTestClassesRector\RemoveTestSuffixFromAbstractTestClassesRectorTest
*/
final class RemoveTestSuffixFromAbstractTestClassesRector extends AbstractRector
{
/**
* @readonly
* @var \Rector\Symfony\Printer\NeighbourClassLikePrinter
*/
private $neighbourClassLikePrinter;
/**
* @readonly
* @var \Rector\PHPUnit\NodeAnalyzer\TestsNodeAnalyzer
*/
private $testsNodeAnalyzer;
/**
* @readonly
* @var \Rector\Core\Configuration\RenamedClassesDataCollector
*/
private $renamedClassesDataCollector;
public function __construct(NeighbourClassLikePrinter $neighbourClassLikePrinter, TestsNodeAnalyzer $testsNodeAnalyzer, RenamedClassesDataCollector $renamedClassesDataCollector)
{
$this->neighbourClassLikePrinter = $neighbourClassLikePrinter;
$this->testsNodeAnalyzer = $testsNodeAnalyzer;
$this->renamedClassesDataCollector = $renamedClassesDataCollector;
}
public function getRuleDefinition() : RuleDefinition
{
return new RuleDefinition('Rename abstract test class suffix from "*Test" to "*TestCase"', [new CodeSample(<<<'CODE_SAMPLE'
// tests/AbstractTest.php
use PHPUnit\Framework\TestCase;
abstract class AbstractTest extends TestCase
{
}
CODE_SAMPLE
, <<<'CODE_SAMPLE'
// tests/AbstractTestCase.php
use PHPUnit\Framework\TestCase;
abstract class AbstractTestCase extends TestCase
{
}
CODE_SAMPLE
)]);
}
/**
* @return array<class-string<Node>>
*/
public function getNodeTypes() : array
{
return [Class_::class];
}
/**
* @param Class_ $node
*/
public function refactor(Node $node) : ?Node
{
if (!$node->isAbstract()) {
return null;
}
if (!$this->testsNodeAnalyzer->isInTestClass($node)) {
return null;
}
if (!$node->name instanceof Identifier) {
return null;
}
if (!$this->isName($node->name, '*Test')) {
return null;
}
/** @var string $oldClassName */
$oldClassName = $this->getName($node);
// rename class
$testCaseClassName = $node->name->toString() . 'Case';
$node->name = new Identifier($testCaseClassName);
$this->printNewNodes($node);
// to rename all other references
$this->renamedClassesDataCollector->addOldToNewClass($oldClassName, $oldClassName . 'Case');
return $node;
}
private function printNewNodes(Class_ $class) : void
{
$filePath = $this->file->getFilePath();
$parentNode = $class->getAttribute(AttributeKey::PARENT_NODE);
if (!$parentNode instanceof Namespace_) {
throw new ShouldNotHappenException();
}
$this->neighbourClassLikePrinter->printClassLike($class, $parentNode, $filePath, $this->file);
}
}

View File

@ -96,38 +96,9 @@ CODE_SAMPLE
if (!$this->testsNodeAnalyzer->isInTestClass($node)) {
return null;
}
// resolve covers class first
$classPhpDocInfo = $this->phpDocInfoFactory->createFromNode($node);
$attributeGroups = [];
if ($classPhpDocInfo instanceof PhpDocInfo) {
/** @var PhpDocTagNode[] $desiredTagValueNodes */
$desiredTagValueNodes = $classPhpDocInfo->getTagsByName('covers');
foreach ($desiredTagValueNodes as $desiredTagValueNode) {
if (!$desiredTagValueNode->value instanceof GenericTagValueNode) {
continue;
}
$attributeGroups[] = $this->createAttributeGroup($desiredTagValueNode->value->value);
// cleanup
$this->phpDocTagRemover->removeTagValueFromNode($classPhpDocInfo, $desiredTagValueNode);
}
}
// resolve covers function
foreach ($node->getMethods() as $classMethod) {
$classMethodPhpDocInfo = $this->phpDocInfoFactory->createFromNode($classMethod);
if (!$classMethodPhpDocInfo instanceof PhpDocInfo) {
continue;
}
/** @var PhpDocTagNode[] $desiredTagValueNodes */
$desiredTagValueNodes = $classMethodPhpDocInfo->getTagsByName('covers');
foreach ($desiredTagValueNodes as $desiredTagValueNode) {
if (!$desiredTagValueNode->value instanceof GenericTagValueNode) {
continue;
}
$attributeGroups[] = $this->createAttributeGroup($desiredTagValueNode->value->value);
// cleanup
$this->phpDocTagRemover->removeTagValueFromNode($classMethodPhpDocInfo, $desiredTagValueNode);
}
}
$coversClassAttributeGroups = $this->resolveCoversClassAttributeGroups($node);
$coversFunctionsAttributeGroups = $this->resolveCoversFunctionAttributeGroups($node);
$attributeGroups = \array_merge($coversClassAttributeGroups, $coversFunctionsAttributeGroups);
if ($attributeGroups === []) {
return null;
}
@ -145,4 +116,52 @@ CODE_SAMPLE
}
return $this->phpAttributeGroupFactory->createFromClassWithItems($attributeClass, [$attributeValue]);
}
/**
* @return AttributeGroup[]
*/
private function resolveCoversClassAttributeGroups(Class_ $class) : array
{
// resolve covers class first
$classPhpDocInfo = $this->phpDocInfoFactory->createFromNode($class);
if (!$classPhpDocInfo instanceof PhpDocInfo) {
return [];
}
$attributeGroups = [];
/** @var PhpDocTagNode[] $desiredTagValueNodes */
$desiredTagValueNodes = $classPhpDocInfo->getTagsByName('covers');
foreach ($desiredTagValueNodes as $desiredTagValueNode) {
if (!$desiredTagValueNode->value instanceof GenericTagValueNode) {
continue;
}
$attributeGroups[] = $this->createAttributeGroup($desiredTagValueNode->value->value);
// cleanup
$this->phpDocTagRemover->removeTagValueFromNode($classPhpDocInfo, $desiredTagValueNode);
}
return $attributeGroups;
}
/**
* @return AttributeGroup[]
*/
private function resolveCoversFunctionAttributeGroups(Class_ $class) : array
{
$attributeGroups = [];
// resolve covers function
foreach ($class->getMethods() as $classMethod) {
$classMethodPhpDocInfo = $this->phpDocInfoFactory->createFromNode($classMethod);
if (!$classMethodPhpDocInfo instanceof PhpDocInfo) {
continue;
}
/** @var PhpDocTagNode[] $desiredTagValueNodes */
$desiredTagValueNodes = $classMethodPhpDocInfo->getTagsByName('covers');
foreach ($desiredTagValueNodes as $desiredTagValueNode) {
if (!$desiredTagValueNode->value instanceof GenericTagValueNode) {
continue;
}
$attributeGroups[] = $this->createAttributeGroup($desiredTagValueNode->value->value);
// cleanup
$this->phpDocTagRemover->removeTagValueFromNode($classMethodPhpDocInfo, $desiredTagValueNode);
}
}
return $attributeGroups;
}
}

View File

@ -4,6 +4,9 @@ declare (strict_types=1);
namespace Rector\PHPUnit\Set;
use Rector\Set\Contract\SetListInterface;
/**
* @api
*/
final class PHPUnitLevelSetList implements SetListInterface
{
/**

View File

@ -4,6 +4,9 @@ declare (strict_types=1);
namespace Rector\PHPUnit\Set;
use Rector\Set\Contract\SetListInterface;
/**
* @api
*/
final class PHPUnitSetList implements SetListInterface
{
/**