Updated Rector to commit a10ddea5d14f8fbdf21366dbfd20defef01f64db

a10ddea5d1 let phpunit handle its own empty method rule
This commit is contained in:
Tomas Votruba 2023-07-13 11:09:22 +00:00
parent 98ae4430e1
commit 77dec4163c
19 changed files with 35 additions and 913 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 ComposerAutoloaderInit23ef1dd03a9ef5d16ccce68534cb806c::getLoader();
return ComposerAutoloaderInit775f16242119db9c5b26170463e99e69::getLoader();

View File

@ -2094,6 +2094,8 @@ return array(
'Rector\\PHPUnit\\AnnotationsToAttributes\\Rector\\ClassMethod\\TestWithAnnotationToAttributeRector' => $vendorDir . '/rector/rector-phpunit/rules/AnnotationsToAttributes/Rector/ClassMethod/TestWithAnnotationToAttributeRector.php',
'Rector\\PHPUnit\\AnnotationsToAttributes\\Rector\\Class_\\AnnotationWithValueToAttributeRector' => $vendorDir . '/rector/rector-phpunit/rules/AnnotationsToAttributes/Rector/Class_/AnnotationWithValueToAttributeRector.php',
'Rector\\PHPUnit\\AnnotationsToAttributes\\Rector\\Class_\\CoversAnnotationWithValueToAttributeRector' => $vendorDir . '/rector/rector-phpunit/rules/AnnotationsToAttributes/Rector/Class_/CoversAnnotationWithValueToAttributeRector.php',
'Rector\\PHPUnit\\CodeQuality\\Rector\\ClassMethod\\RemoveEmptyTestMethodRector' => $vendorDir . '/rector/rector-phpunit/rules/CodeQuality/Rector/ClassMethod/RemoveEmptyTestMethodRector.php',
'Rector\\PHPUnit\\CodeQuality\\Rector\\ClassMethod\\ReplaceTestAnnotationWithPrefixedFunctionRector' => $vendorDir . '/rector/rector-phpunit/rules/CodeQuality/Rector/ClassMethod/ReplaceTestAnnotationWithPrefixedFunctionRector.php',
'Rector\\PHPUnit\\CodeQuality\\Rector\\Class_\\AddSeeTestAnnotationRector' => $vendorDir . '/rector/rector-phpunit/rules/CodeQuality/Rector/Class_/AddSeeTestAnnotationRector.php',
'Rector\\PHPUnit\\CodeQuality\\Rector\\Class_\\ConstructClassMethodToSetUpTestCaseRector' => $vendorDir . '/rector/rector-phpunit/rules/CodeQuality/Rector/Class_/ConstructClassMethodToSetUpTestCaseRector.php',
'Rector\\PHPUnit\\CodeQuality\\Rector\\Class_\\PreferPHPUnitThisCallRector' => $vendorDir . '/rector/rector-phpunit/rules/CodeQuality/Rector/Class_/PreferPHPUnitThisCallRector.php',
@ -2120,11 +2122,9 @@ return array(
'Rector\\PHPUnit\\NodeAnalyzer\\AssertCallAnalyzer' => $vendorDir . '/rector/rector-phpunit/src/NodeAnalyzer/AssertCallAnalyzer.php',
'Rector\\PHPUnit\\NodeAnalyzer\\IdentifierManipulator' => $vendorDir . '/rector/rector-phpunit/src/NodeAnalyzer/IdentifierManipulator.php',
'Rector\\PHPUnit\\NodeAnalyzer\\MockedVariableAnalyzer' => $vendorDir . '/rector/rector-phpunit/src/NodeAnalyzer/MockedVariableAnalyzer.php',
'Rector\\PHPUnit\\NodeAnalyzer\\ParamAndArgFromArrayResolver' => $vendorDir . '/rector/rector-phpunit/src/NodeAnalyzer/ParamAndArgFromArrayResolver.php',
'Rector\\PHPUnit\\NodeAnalyzer\\SetUpMethodDecorator' => $vendorDir . '/rector/rector-phpunit/src/NodeAnalyzer/SetUpMethodDecorator.php',
'Rector\\PHPUnit\\NodeAnalyzer\\TestsNodeAnalyzer' => $vendorDir . '/rector/rector-phpunit/src/NodeAnalyzer/TestsNodeAnalyzer.php',
'Rector\\PHPUnit\\NodeFactory\\AssertCallFactory' => $vendorDir . '/rector/rector-phpunit/src/NodeFactory/AssertCallFactory.php',
'Rector\\PHPUnit\\NodeFactory\\DataProviderClassMethodFactory' => $vendorDir . '/rector/rector-phpunit/src/NodeFactory/DataProviderClassMethodFactory.php',
'Rector\\PHPUnit\\NodeFactory\\ExpectExceptionMethodCallFactory' => $vendorDir . '/rector/rector-phpunit/src/NodeFactory/ExpectExceptionMethodCallFactory.php',
'Rector\\PHPUnit\\NodeFinder\\DataProviderClassMethodFinder' => $vendorDir . '/rector/rector-phpunit/src/NodeFinder/DataProviderClassMethodFinder.php',
'Rector\\PHPUnit\\PHPUnit100\\Rector\\Class_\\AddProphecyTraitRector' => $vendorDir . '/rector/rector-phpunit/rules/PHPUnit100/Rector/Class_/AddProphecyTraitRector.php',
@ -2145,21 +2145,13 @@ return array(
'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\\ClassMethod\\CreateMockToAnonymousClassRector' => $vendorDir . '/rector/rector-phpunit/src/Rector/ClassMethod/CreateMockToAnonymousClassRector.php',
'Rector\\PHPUnit\\Rector\\ClassMethod\\RemoveEmptyTestMethodRector' => $vendorDir . '/rector/rector-phpunit/src/Rector/ClassMethod/RemoveEmptyTestMethodRector.php',
'Rector\\PHPUnit\\Rector\\ClassMethod\\ReplaceTestAnnotationWithPrefixedFunctionRector' => $vendorDir . '/rector/rector-phpunit/src/Rector/ClassMethod/ReplaceTestAnnotationWithPrefixedFunctionRector.php',
'Rector\\PHPUnit\\Rector\\Class_\\ArrayArgumentToDataProviderRector' => $vendorDir . '/rector/rector-phpunit/src/Rector/Class_/ArrayArgumentToDataProviderRector.php',
'Rector\\PHPUnit\\Rector\\Class_\\PreferPHPUnitSelfCallRector' => $vendorDir . '/rector/rector-phpunit/src/Rector/Class_/PreferPHPUnitSelfCallRector.php',
'Rector\\PHPUnit\\Rector\\Class_\\ProphecyPHPDocRector' => $vendorDir . '/rector/rector-phpunit/src/Rector/Class_/ProphecyPHPDocRector.php',
'Rector\\PHPUnit\\Rector\\MethodCall\\AssertResourceToClosedResourceRector' => $vendorDir . '/rector/rector-phpunit/src/Rector/MethodCall/AssertResourceToClosedResourceRector.php',
'Rector\\PHPUnit\\Set\\PHPUnitLevelSetList' => $vendorDir . '/rector/rector-phpunit/src/Set/PHPUnitLevelSetList.php',
'Rector\\PHPUnit\\Set\\PHPUnitSetList' => $vendorDir . '/rector/rector-phpunit/src/Set/PHPUnitSetList.php',
'Rector\\PHPUnit\\ValueObject\\AnnotationWithValueToAttribute' => $vendorDir . '/rector/rector-phpunit/src/ValueObject/AnnotationWithValueToAttribute.php',
'Rector\\PHPUnit\\ValueObject\\ArrayArgumentToDataProvider' => $vendorDir . '/rector/rector-phpunit/src/ValueObject/ArrayArgumentToDataProvider.php',
'Rector\\PHPUnit\\ValueObject\\BinaryOpWithAssertMethod' => $vendorDir . '/rector/rector-phpunit/src/ValueObject/BinaryOpWithAssertMethod.php',
'Rector\\PHPUnit\\ValueObject\\ConstantWithAssertMethods' => $vendorDir . '/rector/rector-phpunit/src/ValueObject/ConstantWithAssertMethods.php',
'Rector\\PHPUnit\\ValueObject\\DataProviderClassMethodRecipe' => $vendorDir . '/rector/rector-phpunit/src/ValueObject/DataProviderClassMethodRecipe.php',
'Rector\\PHPUnit\\ValueObject\\FunctionNameWithAssertMethods' => $vendorDir . '/rector/rector-phpunit/src/ValueObject/FunctionNameWithAssertMethods.php',
'Rector\\PHPUnit\\ValueObject\\ParamAndArg' => $vendorDir . '/rector/rector-phpunit/src/ValueObject/ParamAndArg.php',
'Rector\\Parallel\\Application\\ParallelFileProcessor' => $baseDir . '/packages/Parallel/Application/ParallelFileProcessor.php',
'Rector\\Parallel\\Command\\WorkerCommandLineFactory' => $baseDir . '/packages/Parallel/Command/WorkerCommandLineFactory.php',
'Rector\\Parallel\\ValueObject\\Bridge' => $baseDir . '/packages/Parallel/ValueObject/Bridge.php',

View File

@ -2,7 +2,7 @@
// autoload_real.php @generated by Composer
class ComposerAutoloaderInit23ef1dd03a9ef5d16ccce68534cb806c
class ComposerAutoloaderInit775f16242119db9c5b26170463e99e69
{
private static $loader;
@ -22,17 +22,17 @@ class ComposerAutoloaderInit23ef1dd03a9ef5d16ccce68534cb806c
return self::$loader;
}
spl_autoload_register(array('ComposerAutoloaderInit23ef1dd03a9ef5d16ccce68534cb806c', 'loadClassLoader'), true, true);
spl_autoload_register(array('ComposerAutoloaderInit775f16242119db9c5b26170463e99e69', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
spl_autoload_unregister(array('ComposerAutoloaderInit23ef1dd03a9ef5d16ccce68534cb806c', 'loadClassLoader'));
spl_autoload_unregister(array('ComposerAutoloaderInit775f16242119db9c5b26170463e99e69', 'loadClassLoader'));
require __DIR__ . '/autoload_static.php';
call_user_func(\Composer\Autoload\ComposerStaticInit23ef1dd03a9ef5d16ccce68534cb806c::getInitializer($loader));
call_user_func(\Composer\Autoload\ComposerStaticInit775f16242119db9c5b26170463e99e69::getInitializer($loader));
$loader->setClassMapAuthoritative(true);
$loader->register(true);
$filesToLoad = \Composer\Autoload\ComposerStaticInit23ef1dd03a9ef5d16ccce68534cb806c::$files;
$filesToLoad = \Composer\Autoload\ComposerStaticInit775f16242119db9c5b26170463e99e69::$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 ComposerStaticInit23ef1dd03a9ef5d16ccce68534cb806c
class ComposerStaticInit775f16242119db9c5b26170463e99e69
{
public static $files = array (
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
@ -2347,6 +2347,8 @@ class ComposerStaticInit23ef1dd03a9ef5d16ccce68534cb806c
'Rector\\PHPUnit\\AnnotationsToAttributes\\Rector\\ClassMethod\\TestWithAnnotationToAttributeRector' => __DIR__ . '/..' . '/rector/rector-phpunit/rules/AnnotationsToAttributes/Rector/ClassMethod/TestWithAnnotationToAttributeRector.php',
'Rector\\PHPUnit\\AnnotationsToAttributes\\Rector\\Class_\\AnnotationWithValueToAttributeRector' => __DIR__ . '/..' . '/rector/rector-phpunit/rules/AnnotationsToAttributes/Rector/Class_/AnnotationWithValueToAttributeRector.php',
'Rector\\PHPUnit\\AnnotationsToAttributes\\Rector\\Class_\\CoversAnnotationWithValueToAttributeRector' => __DIR__ . '/..' . '/rector/rector-phpunit/rules/AnnotationsToAttributes/Rector/Class_/CoversAnnotationWithValueToAttributeRector.php',
'Rector\\PHPUnit\\CodeQuality\\Rector\\ClassMethod\\RemoveEmptyTestMethodRector' => __DIR__ . '/..' . '/rector/rector-phpunit/rules/CodeQuality/Rector/ClassMethod/RemoveEmptyTestMethodRector.php',
'Rector\\PHPUnit\\CodeQuality\\Rector\\ClassMethod\\ReplaceTestAnnotationWithPrefixedFunctionRector' => __DIR__ . '/..' . '/rector/rector-phpunit/rules/CodeQuality/Rector/ClassMethod/ReplaceTestAnnotationWithPrefixedFunctionRector.php',
'Rector\\PHPUnit\\CodeQuality\\Rector\\Class_\\AddSeeTestAnnotationRector' => __DIR__ . '/..' . '/rector/rector-phpunit/rules/CodeQuality/Rector/Class_/AddSeeTestAnnotationRector.php',
'Rector\\PHPUnit\\CodeQuality\\Rector\\Class_\\ConstructClassMethodToSetUpTestCaseRector' => __DIR__ . '/..' . '/rector/rector-phpunit/rules/CodeQuality/Rector/Class_/ConstructClassMethodToSetUpTestCaseRector.php',
'Rector\\PHPUnit\\CodeQuality\\Rector\\Class_\\PreferPHPUnitThisCallRector' => __DIR__ . '/..' . '/rector/rector-phpunit/rules/CodeQuality/Rector/Class_/PreferPHPUnitThisCallRector.php',
@ -2373,11 +2375,9 @@ class ComposerStaticInit23ef1dd03a9ef5d16ccce68534cb806c
'Rector\\PHPUnit\\NodeAnalyzer\\AssertCallAnalyzer' => __DIR__ . '/..' . '/rector/rector-phpunit/src/NodeAnalyzer/AssertCallAnalyzer.php',
'Rector\\PHPUnit\\NodeAnalyzer\\IdentifierManipulator' => __DIR__ . '/..' . '/rector/rector-phpunit/src/NodeAnalyzer/IdentifierManipulator.php',
'Rector\\PHPUnit\\NodeAnalyzer\\MockedVariableAnalyzer' => __DIR__ . '/..' . '/rector/rector-phpunit/src/NodeAnalyzer/MockedVariableAnalyzer.php',
'Rector\\PHPUnit\\NodeAnalyzer\\ParamAndArgFromArrayResolver' => __DIR__ . '/..' . '/rector/rector-phpunit/src/NodeAnalyzer/ParamAndArgFromArrayResolver.php',
'Rector\\PHPUnit\\NodeAnalyzer\\SetUpMethodDecorator' => __DIR__ . '/..' . '/rector/rector-phpunit/src/NodeAnalyzer/SetUpMethodDecorator.php',
'Rector\\PHPUnit\\NodeAnalyzer\\TestsNodeAnalyzer' => __DIR__ . '/..' . '/rector/rector-phpunit/src/NodeAnalyzer/TestsNodeAnalyzer.php',
'Rector\\PHPUnit\\NodeFactory\\AssertCallFactory' => __DIR__ . '/..' . '/rector/rector-phpunit/src/NodeFactory/AssertCallFactory.php',
'Rector\\PHPUnit\\NodeFactory\\DataProviderClassMethodFactory' => __DIR__ . '/..' . '/rector/rector-phpunit/src/NodeFactory/DataProviderClassMethodFactory.php',
'Rector\\PHPUnit\\NodeFactory\\ExpectExceptionMethodCallFactory' => __DIR__ . '/..' . '/rector/rector-phpunit/src/NodeFactory/ExpectExceptionMethodCallFactory.php',
'Rector\\PHPUnit\\NodeFinder\\DataProviderClassMethodFinder' => __DIR__ . '/..' . '/rector/rector-phpunit/src/NodeFinder/DataProviderClassMethodFinder.php',
'Rector\\PHPUnit\\PHPUnit100\\Rector\\Class_\\AddProphecyTraitRector' => __DIR__ . '/..' . '/rector/rector-phpunit/rules/PHPUnit100/Rector/Class_/AddProphecyTraitRector.php',
@ -2398,21 +2398,13 @@ class ComposerStaticInit23ef1dd03a9ef5d16ccce68534cb806c
'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\\ClassMethod\\CreateMockToAnonymousClassRector' => __DIR__ . '/..' . '/rector/rector-phpunit/src/Rector/ClassMethod/CreateMockToAnonymousClassRector.php',
'Rector\\PHPUnit\\Rector\\ClassMethod\\RemoveEmptyTestMethodRector' => __DIR__ . '/..' . '/rector/rector-phpunit/src/Rector/ClassMethod/RemoveEmptyTestMethodRector.php',
'Rector\\PHPUnit\\Rector\\ClassMethod\\ReplaceTestAnnotationWithPrefixedFunctionRector' => __DIR__ . '/..' . '/rector/rector-phpunit/src/Rector/ClassMethod/ReplaceTestAnnotationWithPrefixedFunctionRector.php',
'Rector\\PHPUnit\\Rector\\Class_\\ArrayArgumentToDataProviderRector' => __DIR__ . '/..' . '/rector/rector-phpunit/src/Rector/Class_/ArrayArgumentToDataProviderRector.php',
'Rector\\PHPUnit\\Rector\\Class_\\PreferPHPUnitSelfCallRector' => __DIR__ . '/..' . '/rector/rector-phpunit/src/Rector/Class_/PreferPHPUnitSelfCallRector.php',
'Rector\\PHPUnit\\Rector\\Class_\\ProphecyPHPDocRector' => __DIR__ . '/..' . '/rector/rector-phpunit/src/Rector/Class_/ProphecyPHPDocRector.php',
'Rector\\PHPUnit\\Rector\\MethodCall\\AssertResourceToClosedResourceRector' => __DIR__ . '/..' . '/rector/rector-phpunit/src/Rector/MethodCall/AssertResourceToClosedResourceRector.php',
'Rector\\PHPUnit\\Set\\PHPUnitLevelSetList' => __DIR__ . '/..' . '/rector/rector-phpunit/src/Set/PHPUnitLevelSetList.php',
'Rector\\PHPUnit\\Set\\PHPUnitSetList' => __DIR__ . '/..' . '/rector/rector-phpunit/src/Set/PHPUnitSetList.php',
'Rector\\PHPUnit\\ValueObject\\AnnotationWithValueToAttribute' => __DIR__ . '/..' . '/rector/rector-phpunit/src/ValueObject/AnnotationWithValueToAttribute.php',
'Rector\\PHPUnit\\ValueObject\\ArrayArgumentToDataProvider' => __DIR__ . '/..' . '/rector/rector-phpunit/src/ValueObject/ArrayArgumentToDataProvider.php',
'Rector\\PHPUnit\\ValueObject\\BinaryOpWithAssertMethod' => __DIR__ . '/..' . '/rector/rector-phpunit/src/ValueObject/BinaryOpWithAssertMethod.php',
'Rector\\PHPUnit\\ValueObject\\ConstantWithAssertMethods' => __DIR__ . '/..' . '/rector/rector-phpunit/src/ValueObject/ConstantWithAssertMethods.php',
'Rector\\PHPUnit\\ValueObject\\DataProviderClassMethodRecipe' => __DIR__ . '/..' . '/rector/rector-phpunit/src/ValueObject/DataProviderClassMethodRecipe.php',
'Rector\\PHPUnit\\ValueObject\\FunctionNameWithAssertMethods' => __DIR__ . '/..' . '/rector/rector-phpunit/src/ValueObject/FunctionNameWithAssertMethods.php',
'Rector\\PHPUnit\\ValueObject\\ParamAndArg' => __DIR__ . '/..' . '/rector/rector-phpunit/src/ValueObject/ParamAndArg.php',
'Rector\\Parallel\\Application\\ParallelFileProcessor' => __DIR__ . '/../..' . '/packages/Parallel/Application/ParallelFileProcessor.php',
'Rector\\Parallel\\Command\\WorkerCommandLineFactory' => __DIR__ . '/../..' . '/packages/Parallel/Command/WorkerCommandLineFactory.php',
'Rector\\Parallel\\ValueObject\\Bridge' => __DIR__ . '/../..' . '/packages/Parallel/ValueObject/Bridge.php',
@ -3060,9 +3052,9 @@ class ComposerStaticInit23ef1dd03a9ef5d16ccce68534cb806c
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInit23ef1dd03a9ef5d16ccce68534cb806c::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit23ef1dd03a9ef5d16ccce68534cb806c::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit23ef1dd03a9ef5d16ccce68534cb806c::$classMap;
$loader->prefixLengthsPsr4 = ComposerStaticInit775f16242119db9c5b26170463e99e69::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit775f16242119db9c5b26170463e99e69::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit775f16242119db9c5b26170463e99e69::$classMap;
}, null, ClassLoader::class);
}

View File

@ -2049,12 +2049,12 @@
"source": {
"type": "git",
"url": "https:\/\/github.com\/rectorphp\/rector-phpunit.git",
"reference": "290e3d1653738162fdb2a50396d2c5d729829ff3"
"reference": "59b84b71616420ef56d8f125437e6db0c1ebc94b"
},
"dist": {
"type": "zip",
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-phpunit\/zipball\/290e3d1653738162fdb2a50396d2c5d729829ff3",
"reference": "290e3d1653738162fdb2a50396d2c5d729829ff3",
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-phpunit\/zipball\/59b84b71616420ef56d8f125437e6db0c1ebc94b",
"reference": "59b84b71616420ef56d8f125437e6db0c1ebc94b",
"shasum": ""
},
"require": {
@ -2082,7 +2082,7 @@
"tomasvotruba\/type-coverage": "^0.1",
"tomasvotruba\/unused-public": "^0.1"
},
"time": "2023-07-13T10:41:58+00:00",
"time": "2023-07-13T11:04:54+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 3482059'), '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 734960f'), '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 290e3d1'), '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 e788554'));
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 3482059'), '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 734960f'), '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 59b84b7'), '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 e788554'));
private function __construct()
{
}

View File

@ -8,6 +8,8 @@ use Rector\PHPUnit\CodeQuality\Rector\Class_\AddSeeTestAnnotationRector;
use Rector\PHPUnit\CodeQuality\Rector\Class_\ConstructClassMethodToSetUpTestCaseRector;
use Rector\PHPUnit\CodeQuality\Rector\Class_\PreferPHPUnitThisCallRector;
use Rector\PHPUnit\CodeQuality\Rector\Class_\YieldDataProviderRector;
use Rector\PHPUnit\CodeQuality\Rector\ClassMethod\RemoveEmptyTestMethodRector;
use Rector\PHPUnit\CodeQuality\Rector\ClassMethod\ReplaceTestAnnotationWithPrefixedFunctionRector;
use Rector\PHPUnit\CodeQuality\Rector\Foreach_\SimplifyForeachInstanceOfRector;
use Rector\PHPUnit\CodeQuality\Rector\MethodCall\AssertCompareToSpecificMethodRector;
use Rector\PHPUnit\CodeQuality\Rector\MethodCall\AssertComparisonToSpecificMethodRector;
@ -33,6 +35,8 @@ return static function (RectorConfig $rectorConfig) : void {
AssertEqualsToSameRector::class,
PreferPHPUnitThisCallRector::class,
YieldDataProviderRector::class,
RemoveEmptyTestMethodRector::class,
ReplaceTestAnnotationWithPrefixedFunctionRector::class,
// sepcific asserts
AssertCompareToSpecificMethodRector::class,
AssertComparisonToSpecificMethodRector::class,

View File

@ -1,4 +1,4 @@
# 48 Rules Overview
# 45 Rules Overview
## AddDoesNotPerformAssertionToNonAssertingTestRector
@ -75,7 +75,7 @@ Change annotations with value to attribute
:wrench: **configure it!**
- class: [`Rector\PHPUnit\Rector\Class_\AnnotationWithValueToAttributeRector`](../src/Rector/Class_/AnnotationWithValueToAttributeRector.php)
- class: [`Rector\PHPUnit\AnnotationsToAttributes\Rector\Class_\AnnotationWithValueToAttributeRector`](../rules/AnnotationsToAttributes/Rector/Class_/AnnotationWithValueToAttributeRector.php)
```php
<?php
@ -83,7 +83,7 @@ Change annotations with value to attribute
declare(strict_types=1);
use Rector\Config\RectorConfig;
use Rector\PHPUnit\Rector\Class_\AnnotationWithValueToAttributeRector;
use Rector\PHPUnit\AnnotationsToAttributes\Rector\Class_\AnnotationWithValueToAttributeRector;
use Rector\PHPUnit\ValueObject\AnnotationWithValueToAttribute;
return static function (RectorConfig $rectorConfig): void {
@ -113,60 +113,6 @@ return static function (RectorConfig $rectorConfig): void {
<br>
## ArrayArgumentToDataProviderRector
Move array argument from tests into data provider [configurable]
:wrench: **configure it!**
- class: [`Rector\PHPUnit\Rector\Class_\ArrayArgumentToDataProviderRector`](../src/Rector/Class_/ArrayArgumentToDataProviderRector.php)
```php
<?php
declare(strict_types=1);
use Rector\Config\RectorConfig;
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'),
],
]);
};
```
```diff
use PHPUnit\Framework\TestCase;
class SomeServiceTest extends TestCase
{
- public function test()
+ /**
+ * @dataProvider provideData()
+ */
+ public function test(int $number)
{
- $this->doTestMultiple([1, 2, 3]);
+ $this->doTestSingle($number);
+ }
+
+ public function provideData(): \Iterator
+ {
+ yield [1];
+ yield [2];
+ yield [3];
}
}
```
<br>
## AssertCompareToSpecificMethodRector
Turns vague php-only method in PHPUnit TestCase to more specific
@ -357,19 +303,6 @@ Turns `preg_match` comparisons to their method name alternatives in PHPUnit Test
<br>
## AssertResourceToClosedResourceRector
Turns `assertIsNotResource()` into stricter `assertIsClosedResource()` for resource values in PHPUnit TestCase
- class: [`Rector\PHPUnit\Rector\MethodCall\AssertResourceToClosedResourceRector`](../src/Rector/MethodCall/AssertResourceToClosedResourceRector.php)
```diff
-$this->assertIsNotResource($aResource, "message");
+$this->assertIsClosedResource($aResource, "message");
```
<br>
## AssertSameBoolNullToSpecificMethodRector
Turns same bool and null comparisons to their method name alternatives in PHPUnit TestCase
@ -559,7 +492,7 @@ Takes `setExpectedException()` 2nd and next arguments to own methods in PHPUnit.
Change depends annotations with value to attribute
- class: [`Rector\PHPUnit\Rector\ClassMethod\DependsAnnotationWithValueToAttributeRector`](../src/Rector/ClassMethod/DependsAnnotationWithValueToAttributeRector.php)
- class: [`Rector\PHPUnit\AnnotationsToAttributes\Rector\ClassMethod\DependsAnnotationWithValueToAttributeRector`](../rules/AnnotationsToAttributes/Rector/ClassMethod/DependsAnnotationWithValueToAttributeRector.php)
```diff
use PHPUnit\Framework\TestCase;
@ -729,30 +662,6 @@ Turns PHPUnit TestCase assertObjectHasAttribute into `property_exists` compariso
<br>
## ProphecyPHPDocRector
Add correct `@var` to ObjectProphecy instances based on `$this->prophesize()` call.
- class: [`Rector\PHPUnit\Rector\Class_\ProphecyPHPDocRector`](../src/Rector/Class_/ProphecyPHPDocRector.php)
```diff
class HelloTest extends TestCase
{
/**
- * @var SomeClass
+ * @var ObjectProphecy<SomeClass>
*/
private $propesizedObject;
protected function setUp(): void
{
$this->propesizedObject = $this->prophesize(SomeClass::class);
}
}
```
<br>
## RemoveDataProviderTestPrefixRector
Data provider methods cannot start with "test" prefix
@ -785,7 +694,7 @@ Data provider methods cannot start with "test" prefix
Remove empty test methods
- class: [`Rector\PHPUnit\Rector\ClassMethod\RemoveEmptyTestMethodRector`](../src/Rector/ClassMethod/RemoveEmptyTestMethodRector.php)
- class: [`Rector\PHPUnit\CodeQuality\Rector\ClassMethod\RemoveEmptyTestMethodRector`](../rules/CodeQuality/Rector/ClassMethod/RemoveEmptyTestMethodRector.php)
```diff
class SomeTest extends \PHPUnit\Framework\TestCase
@ -853,7 +762,7 @@ Remove `"setMethods()"` method as never used
Replace `@test` with prefixed function
- class: [`Rector\PHPUnit\Rector\ClassMethod\ReplaceTestAnnotationWithPrefixedFunctionRector`](../src/Rector/ClassMethod/ReplaceTestAnnotationWithPrefixedFunctionRector.php)
- class: [`Rector\PHPUnit\CodeQuality\Rector\ClassMethod\ReplaceTestAnnotationWithPrefixedFunctionRector`](../rules/CodeQuality/Rector/ClassMethod/ReplaceTestAnnotationWithPrefixedFunctionRector.php)
```diff
class SomeTest extends \PHPUnit\Framework\TestCase
@ -875,7 +784,7 @@ Replace `@test` with prefixed function
Simplify unnecessary foreach check of instances
- class: [`Rector\PHPUnit\CodeQuality\Rector\Foreach_\SimplifyForeachInstanceOfRector`](../src/CodeQuality/Rector/Foreach_/SimplifyForeachInstanceOfRector.php)
- class: [`Rector\PHPUnit\CodeQuality\Rector\Foreach_\SimplifyForeachInstanceOfRector`](../rules/CodeQuality/Rector/Foreach_/SimplifyForeachInstanceOfRector.php)
```diff
-foreach ($foos as $foo) {

View File

@ -1,7 +1,7 @@
<?php
declare (strict_types=1);
namespace Rector\PHPUnit\Rector\ClassMethod;
namespace Rector\PHPUnit\CodeQuality\Rector\ClassMethod;
use PhpParser\Node;
use PhpParser\Node\Stmt\ClassMethod;
@ -11,7 +11,7 @@ use Rector\PHPUnit\NodeAnalyzer\TestsNodeAnalyzer;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
/**
* @see \Rector\PHPUnit\Tests\Rector\ClassMethod\RemoveEmptyTestMethodRector\RemoveEmptyTestMethodRectorTest
* @see \Rector\PHPUnit\Tests\CodeQuality\Rector\ClassMethod\RemoveEmptyTestMethodRector\RemoveEmptyTestMethodRectorTest
*/
final class RemoveEmptyTestMethodRector extends AbstractRector
{

View File

@ -1,7 +1,7 @@
<?php
declare (strict_types=1);
namespace Rector\PHPUnit\Rector\ClassMethod;
namespace Rector\PHPUnit\CodeQuality\Rector\ClassMethod;
use PhpParser\Comment\Doc;
use PhpParser\Node;
@ -12,7 +12,7 @@ use Rector\PHPUnit\NodeAnalyzer\TestsNodeAnalyzer;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
/**
* @see \Rector\PHPUnit\Tests\Rector\ClassMethod\ReplaceTestAnnotationWithPrefixedFunctionRector\ReplaceTestAnnotationWithPrefixedFunctionRectorTest
* @see \Rector\PHPUnit\Tests\CodeQuality\Rector\ClassMethod\ReplaceTestAnnotationWithPrefixedFunctionRector\ReplaceTestAnnotationWithPrefixedFunctionRectorTest
*/
final class ReplaceTestAnnotationWithPrefixedFunctionRector extends AbstractRector
{

View File

@ -1,114 +0,0 @@
<?php
declare (strict_types=1);
namespace Rector\PHPUnit\NodeAnalyzer;
use PhpParser\Node\Expr\Array_;
use PhpParser\Node\Expr\ArrayItem;
use PhpParser\Node\Expr\Variable;
use PHPStan\Type\Type;
use Rector\NodeTypeResolver\NodeTypeResolver;
use Rector\NodeTypeResolver\PHPStan\Type\TypeFactory;
use Rector\PHPUnit\ValueObject\ParamAndArg;
final class ParamAndArgFromArrayResolver
{
/**
* @readonly
* @var \Rector\NodeTypeResolver\NodeTypeResolver
*/
private $nodeTypeResolver;
/**
* @readonly
* @var \Rector\NodeTypeResolver\PHPStan\Type\TypeFactory
*/
private $typeFactory;
public function __construct(NodeTypeResolver $nodeTypeResolver, TypeFactory $typeFactory)
{
$this->nodeTypeResolver = $nodeTypeResolver;
$this->typeFactory = $typeFactory;
}
/**
* @return ParamAndArg[]
*/
public function resolve(Array_ $array, string $variableName) : array
{
$isNestedArray = $this->isNestedArray($array);
if ($isNestedArray) {
return $this->collectParamAndArgsFromNestedArray($array, $variableName);
}
$itemsStaticType = $this->resolveItemStaticType($array, $isNestedArray);
return $this->collectParamAndArgsFromNonNestedArray($array, $variableName, $itemsStaticType);
}
private function isNestedArray(Array_ $array) : bool
{
foreach ($array->items as $arrayItem) {
if (!$arrayItem instanceof ArrayItem) {
continue;
}
if ($arrayItem->value instanceof Array_) {
return \true;
}
}
return \false;
}
/**
* @return ParamAndArg[]
*/
private function collectParamAndArgsFromNestedArray(Array_ $array, string $variableName) : array
{
$paramAndArgs = [];
$i = 1;
foreach ($array->items as $arrayItem) {
if (!$arrayItem instanceof ArrayItem) {
continue;
}
$nestedArray = $arrayItem->value;
if (!$nestedArray instanceof Array_) {
continue;
}
foreach ($nestedArray->items as $nestedArrayItem) {
if (!$nestedArrayItem instanceof ArrayItem) {
continue;
}
$variable = new Variable($variableName . ($i === 1 ? '' : $i));
$itemsStaticType = $this->nodeTypeResolver->getType($nestedArrayItem->value);
$paramAndArgs[] = new ParamAndArg($variable, $itemsStaticType);
++$i;
}
}
return $paramAndArgs;
}
private function resolveItemStaticType(Array_ $array, bool $isNestedArray) : Type
{
$staticTypes = [];
if (!$isNestedArray) {
foreach ($array->items as $arrayItem) {
if (!$arrayItem instanceof ArrayItem) {
continue;
}
$staticTypes[] = $this->nodeTypeResolver->getType($arrayItem->value);
}
}
return $this->typeFactory->createMixedPassedOrUnionType($staticTypes);
}
/**
* @return ParamAndArg[]
*/
private function collectParamAndArgsFromNonNestedArray(Array_ $array, string $variableName, Type $itemsStaticType) : array
{
$i = 1;
$paramAndArgs = [];
foreach ($array->items as $arrayItem) {
if (!$arrayItem instanceof ArrayItem) {
continue;
}
$variable = new Variable($variableName . ($i === 1 ? '' : $i));
$paramAndArgs[] = new ParamAndArg($variable, $itemsStaticType);
++$i;
if (!$arrayItem->value instanceof Array_) {
break;
}
}
return $paramAndArgs;
}
}

View File

@ -1,41 +0,0 @@
<?php
declare (strict_types=1);
namespace Rector\PHPUnit\NodeFactory;
use PhpParser\Builder\Method;
use PhpParser\Node\Expr\Array_;
use PhpParser\Node\Expr\ArrayItem;
use PhpParser\Node\Expr\Yield_;
use PhpParser\Node\Name\FullyQualified;
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\Expression;
use Rector\PHPUnit\ValueObject\DataProviderClassMethodRecipe;
final class DataProviderClassMethodFactory
{
public function createFromRecipe(DataProviderClassMethodRecipe $dataProviderClassMethodRecipe) : ClassMethod
{
$method = new Method($dataProviderClassMethodRecipe->getMethodName());
$method->makePublic();
$classMethod = $method->getNode();
foreach ($dataProviderClassMethodRecipe->getArgs() as $arg) {
$value = $arg->value;
if (!$value instanceof Array_) {
continue;
}
foreach ($value->items as $arrayItem) {
if (!$arrayItem instanceof ArrayItem) {
continue;
}
$returnStatement = new Yield_(new Array_([new ArrayItem($arrayItem->value)]));
$classMethod->stmts[] = new Expression($returnStatement);
}
}
$this->decorateClassMethodWithReturnTypeAndTag($classMethod);
return $classMethod;
}
private function decorateClassMethodWithReturnTypeAndTag(ClassMethod $classMethod) : void
{
$classMethod->returnType = new FullyQualified('Iterator');
}
}

View File

@ -1,273 +0,0 @@
<?php
declare (strict_types=1);
namespace Rector\PHPUnit\Rector\Class_;
use PhpParser\Node;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr\Array_;
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Identifier;
use PhpParser\Node\Param;
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\ClassMethod;
use PHPStan\PhpDocParser\Ast\PhpDoc\GenericTagValueNode;
use PHPStan\PhpDocParser\Ast\PhpDoc\ParamTagValueNode;
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode;
use PHPStan\PhpDocParser\Ast\Type\TypeNode;
use PHPStan\Type\Type;
use PHPStan\Type\UnionType;
use PHPUnit\Framework\TestCase;
use Rector\Core\Contract\Rector\ConfigurableRectorInterface;
use Rector\Core\Exception\ShouldNotHappenException;
use Rector\Core\Rector\AbstractRector;
use Rector\PHPStanStaticTypeMapper\Enum\TypeKind;
use Rector\PHPUnit\NodeAnalyzer\ParamAndArgFromArrayResolver;
use Rector\PHPUnit\NodeAnalyzer\TestsNodeAnalyzer;
use Rector\PHPUnit\NodeFactory\DataProviderClassMethodFactory;
use Rector\PHPUnit\ValueObject\ArrayArgumentToDataProvider;
use Rector\PHPUnit\ValueObject\DataProviderClassMethodRecipe;
use Rector\PHPUnit\ValueObject\ParamAndArg;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
use RectorPrefix202307\Webmozart\Assert\Assert;
/**
* @see \Rector\PHPUnit\Tests\Rector\Class_\ArrayArgumentToDataProviderRector\ArrayArgumentToDataProviderRectorTest
*
* @see why https://blog.martinhujer.cz/how-to-use-data-providers-in-phpunit/
*/
final class ArrayArgumentToDataProviderRector extends AbstractRector implements ConfigurableRectorInterface
{
/**
* @readonly
* @var \Rector\PHPUnit\NodeFactory\DataProviderClassMethodFactory
*/
private $dataProviderClassMethodFactory;
/**
* @readonly
* @var \Rector\PHPUnit\NodeAnalyzer\ParamAndArgFromArrayResolver
*/
private $paramAndArgFromArrayResolver;
/**
* @readonly
* @var \Rector\PHPUnit\NodeAnalyzer\TestsNodeAnalyzer
*/
private $testsNodeAnalyzer;
/**
* @api
* @var string
*/
public const ARRAY_ARGUMENTS_TO_DATA_PROVIDERS = 'array_arguments_to_data_providers';
/**
* @var ArrayArgumentToDataProvider[]
*/
private $arrayArgumentsToDataProviders = [];
/**
* @var DataProviderClassMethodRecipe[]
*/
private $dataProviderClassMethodRecipes = [];
public function __construct(DataProviderClassMethodFactory $dataProviderClassMethodFactory, ParamAndArgFromArrayResolver $paramAndArgFromArrayResolver, TestsNodeAnalyzer $testsNodeAnalyzer)
{
$this->dataProviderClassMethodFactory = $dataProviderClassMethodFactory;
$this->paramAndArgFromArrayResolver = $paramAndArgFromArrayResolver;
$this->testsNodeAnalyzer = $testsNodeAnalyzer;
}
public function getRuleDefinition() : RuleDefinition
{
return new RuleDefinition('Move array argument from tests into data provider [configurable]', [new ConfiguredCodeSample(<<<'CODE_SAMPLE'
use PHPUnit\Framework\TestCase;
class SomeServiceTest extends TestCase
{
public function test()
{
$this->doTestMultiple([1, 2, 3]);
}
}
CODE_SAMPLE
, <<<'CODE_SAMPLE'
use PHPUnit\Framework\TestCase;
class SomeServiceTest extends TestCase
{
/**
* @dataProvider provideData()
*/
public function test(int $number)
{
$this->doTestSingle($number);
}
public function provideData(): \Iterator
{
yield [1];
yield [2];
yield [3];
}
}
CODE_SAMPLE
, [self::ARRAY_ARGUMENTS_TO_DATA_PROVIDERS => [new ArrayArgumentToDataProvider(TestCase::class, 'doTestMultiple', 'doTestSingle', 'number')]])]);
}
/**
* @return array<class-string<Node>>
*/
public function getNodeTypes() : array
{
return [Class_::class];
}
/**
* @param Class_ $node
*/
public function refactor(Node $node) : ?Node
{
if (!$this->testsNodeAnalyzer->isInTestClass($node)) {
return null;
}
$this->dataProviderClassMethodRecipes = [];
$classMethod = null;
$this->traverseNodesWithCallable($node->getMethods(), function (Node $node) use(&$classMethod) {
if ($node instanceof ClassMethod) {
$classMethod = $node;
return null;
}
if (!$node instanceof MethodCall) {
return null;
}
foreach ($this->arrayArgumentsToDataProviders as $arrayArgumentToDataProvider) {
$this->refactorMethodCallWithConfiguration($node, $arrayArgumentToDataProvider, $classMethod);
}
return null;
});
if ($this->dataProviderClassMethodRecipes === []) {
return null;
}
$dataProviderClassMethods = $this->createDataProviderClassMethodsFromRecipes();
$node->stmts = \array_merge($node->stmts, $dataProviderClassMethods);
return $node;
}
/**
* @param mixed[] $configuration
*/
public function configure(array $configuration) : void
{
$arrayArgumentsToDataProviders = $configuration[self::ARRAY_ARGUMENTS_TO_DATA_PROVIDERS] ?? $configuration;
Assert::isArray($arrayArgumentsToDataProviders);
Assert::allIsAOf($arrayArgumentsToDataProviders, ArrayArgumentToDataProvider::class);
$this->arrayArgumentsToDataProviders = $arrayArgumentsToDataProviders;
}
private function refactorMethodCallWithConfiguration(MethodCall $methodCall, ArrayArgumentToDataProvider $arrayArgumentToDataProvider, ?ClassMethod $classMethod) : void
{
if (!$classMethod instanceof ClassMethod) {
return;
}
if (!$this->isMethodCallMatch($methodCall, $arrayArgumentToDataProvider)) {
return;
}
if ($methodCall->isFirstClassCallable()) {
return;
}
if (\count($methodCall->getArgs()) !== 1) {
throw new ShouldNotHappenException();
}
// resolve value types
$firstArgumentValue = $methodCall->getArgs()[0]->value;
if (!$firstArgumentValue instanceof Array_) {
// nothing we can do
return;
}
// rename method to new one handling non-array input
$methodCall->name = new Identifier($arrayArgumentToDataProvider->getNewMethod());
$dataProviderMethodName = $this->createDataProviderMethodName($classMethod);
$this->dataProviderClassMethodRecipes[] = new DataProviderClassMethodRecipe($dataProviderMethodName, $methodCall->getArgs());
$methodCall->args = [];
$paramAndArgs = $this->paramAndArgFromArrayResolver->resolve($firstArgumentValue, $arrayArgumentToDataProvider->getVariableName());
foreach ($paramAndArgs as $paramAndArg) {
$methodCall->args[] = new Arg($paramAndArg->getVariable());
}
$this->refactorTestClassMethodParams($classMethod, $paramAndArgs);
// add data provider annotation
$phpDocTagNode = $this->createDataProviderTagNode($dataProviderMethodName);
$phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($classMethod);
$phpDocInfo->addPhpDocTagNode($phpDocTagNode);
$phpDocInfo->makeMultiLined();
}
/**
* @return ClassMethod[]
*/
private function createDataProviderClassMethodsFromRecipes() : array
{
$dataProviderClassMethods = [];
foreach ($this->dataProviderClassMethodRecipes as $dataProviderClassMethodRecipe) {
$dataProviderClassMethods[] = $this->dataProviderClassMethodFactory->createFromRecipe($dataProviderClassMethodRecipe);
}
return $dataProviderClassMethods;
}
private function isMethodCallMatch(MethodCall $methodCall, ArrayArgumentToDataProvider $arrayArgumentToDataProvider) : bool
{
if (!$this->isObjectType($methodCall->var, $arrayArgumentToDataProvider->getObjectType())) {
return \false;
}
return $this->isName($methodCall->name, $arrayArgumentToDataProvider->getOldMethod());
}
private function createDataProviderMethodName(ClassMethod $classMethod) : string
{
$classMethodName = $this->getName($classMethod);
return 'provideDataFor' . \ucfirst($classMethodName);
}
/**
* @param ParamAndArg[] $paramAndArgs
*/
private function refactorTestClassMethodParams(ClassMethod $classMethod, array $paramAndArgs) : void
{
$classMethod->params = $this->createParams($paramAndArgs);
$phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($classMethod);
foreach ($paramAndArgs as $paramAndArg) {
$staticType = $paramAndArg->getType();
if (!$staticType instanceof UnionType) {
continue;
}
/** @var string $paramName */
$paramName = $this->getName($paramAndArg->getVariable());
$staticTypeNode = $this->staticTypeMapper->mapPHPStanTypeToPHPStanPhpDocTypeNode($staticType);
$paramTagValueNode = $this->createParamTagNode($paramName, $staticTypeNode);
$phpDocInfo->addTagValueNode($paramTagValueNode);
}
}
private function createDataProviderTagNode(string $dataProviderMethodName) : PhpDocTagNode
{
return new PhpDocTagNode('@dataProvider', new GenericTagValueNode($dataProviderMethodName . '()'));
}
/**
* @param ParamAndArg[] $paramAndArgs
* @return Param[]
*/
private function createParams(array $paramAndArgs) : array
{
$params = [];
foreach ($paramAndArgs as $paramAndArg) {
$param = new Param($paramAndArg->getVariable());
$this->setTypeIfNotNull($paramAndArg, $param);
$params[] = $param;
}
return $params;
}
private function createParamTagNode(string $name, TypeNode $typeNode) : ParamTagValueNode
{
return new ParamTagValueNode($typeNode, \false, '$' . $name, '');
}
private function setTypeIfNotNull(ParamAndArg $paramAndArg, Param $param) : void
{
$staticType = $paramAndArg->getType();
if (!$staticType instanceof Type) {
return;
}
if ($staticType instanceof UnionType) {
return;
}
$phpNodeType = $this->staticTypeMapper->mapPHPStanTypeToPhpParserNode($staticType, TypeKind::PARAM);
if ($phpNodeType === null) {
return;
}
$param->type = $phpNodeType;
}
}

View File

@ -1,150 +0,0 @@
<?php
declare (strict_types=1);
namespace Rector\PHPUnit\Rector\Class_;
use PhpParser\Node;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\Property;
use PHPStan\PhpDocParser\Ast\PhpDoc\VarTagValueNode;
use PHPStan\PhpDocParser\Ast\Type\GenericTypeNode;
use Rector\BetterPhpDocParser\ValueObject\Type\FullyQualifiedIdentifierTypeNode;
use Rector\Core\NodeManipulator\ClassMethodPropertyFetchManipulator;
use Rector\Core\Rector\AbstractRector;
use Rector\PHPUnit\NodeAnalyzer\TestsNodeAnalyzer;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
/**
* @see \Rector\PHPUnit\Tests\Rector\Class_\ProphecyPHPDocRector\ProphecyPHPDocRectorTest
*/
final class ProphecyPHPDocRector extends AbstractRector
{
/**
* @readonly
* @var \Rector\PHPUnit\NodeAnalyzer\TestsNodeAnalyzer
*/
private $testsNodeAnalyzer;
/**
* @readonly
* @var \Rector\Core\NodeManipulator\ClassMethodPropertyFetchManipulator
*/
private $classMethodPropertyFetchManipulator;
public function __construct(TestsNodeAnalyzer $testsNodeAnalyzer, ClassMethodPropertyFetchManipulator $classMethodPropertyFetchManipulator)
{
$this->testsNodeAnalyzer = $testsNodeAnalyzer;
$this->classMethodPropertyFetchManipulator = $classMethodPropertyFetchManipulator;
}
public function getRuleDefinition() : RuleDefinition
{
return new RuleDefinition('Add correct @var to ObjectProphecy instances based on $this->prophesize() call.', [new CodeSample(<<<'CODE_SAMPLE'
class HelloTest extends TestCase
{
/**
* @var SomeClass
*/
private $propesizedObject;
protected function setUp(): void
{
$this->propesizedObject = $this->prophesize(SomeClass::class);
}
}
CODE_SAMPLE
, <<<'CODE_SAMPLE'
class HelloTest extends TestCase
{
/**
* @var ObjectProphecy<SomeClass>
*/
private $propesizedObject;
protected function setUp(): void
{
$this->propesizedObject = $this->prophesize(SomeClass::class);
}
}
CODE_SAMPLE
)]);
}
/**
* @return array<class-string<Node>>
*/
public function getNodeTypes() : array
{
return [Class_::class];
}
/**
* @param Class_ $node
*/
public function refactor(Node $node) : ?\PhpParser\Node\Stmt\Class_
{
if (!$this->testsNodeAnalyzer->isInTestClass($node)) {
return null;
}
$hasChanged = \false;
foreach ($node->getProperties() as $property) {
$propertyName = $this->getName($property);
$toPropertyAssignExprs = $this->findAssignToPropertyName($node, $propertyName);
foreach ($toPropertyAssignExprs as $toPropertyAssignExpr) {
$prophesizedObjectArg = $this->matchThisProphesizeMethodCallFirstArg($toPropertyAssignExpr);
if (!$prophesizedObjectArg instanceof Arg) {
continue;
}
$prophesizedClass = $this->valueResolver->getValue($prophesizedObjectArg->value);
if (!\is_string($prophesizedClass)) {
return null;
}
$this->changePropertyDoc($property, $prophesizedClass);
$hasChanged = \true;
break;
}
}
if ($hasChanged) {
return $node;
}
return null;
}
private function matchThisProphesizeMethodCallFirstArg(Expr $expr) : ?Arg
{
if (!$expr instanceof MethodCall) {
return null;
}
$var = $expr->var;
if (!$var instanceof Variable) {
return null;
}
if (!$this->isName($var, 'this')) {
return null;
}
if (!$this->isName($expr->name, 'prophesize')) {
return null;
}
if ($expr->isFirstClassCallable()) {
return null;
}
return $expr->getArgs()[0];
}
/**
* @return Expr[]
*/
private function findAssignToPropertyName(Class_ $class, string $propertyName) : array
{
$assignExprs = [];
foreach ($class->getMethods() as $classMethod) {
$currentAssignExprs = $this->classMethodPropertyFetchManipulator->findAssignsToPropertyName($classMethod, $propertyName);
$assignExprs = \array_merge($assignExprs, $currentAssignExprs);
}
return $assignExprs;
}
private function changePropertyDoc(Property $property, string $prophesizedClass) : void
{
$propertyPhpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($property);
// replace old one
$propertyPhpDocInfo->removeByType(VarTagValueNode::class);
$propertyPhpDocInfo->addTagValueNode(new VarTagValueNode(new GenericTypeNode(new FullyQualifiedIdentifierTypeNode('Prophecy\\Prophecy\\ObjectProphecy'), [new FullyQualifiedIdentifierTypeNode($prophesizedClass)]), '', ''));
}
}

View File

@ -1,72 +0,0 @@
<?php
declare (strict_types=1);
namespace Rector\PHPUnit\Rector\MethodCall;
use PhpParser\Node;
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Expr\StaticCall;
use Rector\Core\Rector\AbstractRector;
use Rector\PHPUnit\NodeAnalyzer\IdentifierManipulator;
use Rector\PHPUnit\NodeAnalyzer\TestsNodeAnalyzer;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
/**
* @source https://github.com/sebastianbergmann/phpunit/pull/4365
*
* @see \Rector\PHPUnit\Tests\Rector\MethodCall\AssertResourceToClosedResourceRector\AssertResourceToClosedResourceRectorTest
*/
final class AssertResourceToClosedResourceRector extends AbstractRector
{
/**
* @readonly
* @var \Rector\PHPUnit\NodeAnalyzer\IdentifierManipulator
*/
private $identifierManipulator;
/**
* @readonly
* @var \Rector\PHPUnit\NodeAnalyzer\TestsNodeAnalyzer
*/
private $testsNodeAnalyzer;
/**
* @var array<string, string>
*/
private const RENAME_METHODS_MAP = ['assertIsNotResource' => 'assertIsClosedResource'];
public function __construct(IdentifierManipulator $identifierManipulator, TestsNodeAnalyzer $testsNodeAnalyzer)
{
$this->identifierManipulator = $identifierManipulator;
$this->testsNodeAnalyzer = $testsNodeAnalyzer;
}
public function getRuleDefinition() : RuleDefinition
{
return new RuleDefinition('Turns `assertIsNotResource()` into stricter `assertIsClosedResource()` for resource values in PHPUnit TestCase', [new CodeSample('$this->assertIsNotResource($aResource, "message");', '$this->assertIsClosedResource($aResource, "message");')]);
}
/**
* @return array<class-string<Node>>
*/
public function getNodeTypes() : array
{
return [MethodCall::class, StaticCall::class];
}
/**
* @param MethodCall|StaticCall $node
*/
public function refactor(Node $node) : ?Node
{
if (!$this->testsNodeAnalyzer->isInTestClass($node)) {
return null;
}
$methodNames = \array_keys(self::RENAME_METHODS_MAP);
if (!$this->isNames($node->name, $methodNames)) {
return null;
}
if ($node->isFirstClassCallable()) {
return null;
}
if (!isset($node->getArgs()[0])) {
return null;
}
$this->identifierManipulator->renameNodeWithMap($node, self::RENAME_METHODS_MAP);
return $node;
}
}

View File

@ -1,52 +0,0 @@
<?php
declare (strict_types=1);
namespace Rector\PHPUnit\ValueObject;
use PHPStan\Type\ObjectType;
final class ArrayArgumentToDataProvider
{
/**
* @readonly
* @var string
*/
private $class;
/**
* @readonly
* @var string
*/
private $oldMethod;
/**
* @readonly
* @var string
*/
private $newMethod;
/**
* @readonly
* @var string
*/
private $variableName;
public function __construct(string $class, string $oldMethod, string $newMethod, string $variableName)
{
$this->class = $class;
$this->oldMethod = $oldMethod;
$this->newMethod = $newMethod;
$this->variableName = $variableName;
}
public function getObjectType() : ObjectType
{
return new ObjectType($this->class);
}
public function getOldMethod() : string
{
return $this->oldMethod;
}
public function getNewMethod() : string
{
return $this->newMethod;
}
public function getVariableName() : string
{
return $this->variableName;
}
}

View File

@ -1,40 +0,0 @@
<?php
declare (strict_types=1);
namespace Rector\PHPUnit\ValueObject;
use PhpParser\Node\Arg;
use RectorPrefix202307\Webmozart\Assert\Assert;
final class DataProviderClassMethodRecipe
{
/**
* @readonly
* @var string
*/
private $methodName;
/**
* @var Arg[]
* @readonly
*/
private $args;
/**
* @param Arg[] $args
*/
public function __construct(string $methodName, array $args)
{
$this->methodName = $methodName;
$this->args = $args;
Assert::allIsInstanceOf($args, Arg::class);
}
public function getMethodName() : string
{
return $this->methodName;
}
/**
* @return Arg[]
*/
public function getArgs() : array
{
return $this->args;
}
}

View File

@ -1,33 +0,0 @@
<?php
declare (strict_types=1);
namespace Rector\PHPUnit\ValueObject;
use PhpParser\Node\Expr\Variable;
use PHPStan\Type\Type;
final class ParamAndArg
{
/**
* @readonly
* @var \PhpParser\Node\Expr\Variable
*/
private $variable;
/**
* @readonly
* @var \PHPStan\Type\Type|null
*/
private $type;
public function __construct(Variable $variable, ?Type $type)
{
$this->variable = $variable;
$this->type = $type;
}
public function getVariable() : Variable
{
return $this->variable;
}
public function getType() : ?Type
{
return $this->type;
}
}