Updated Rector to commit b54c62993056f984ca68d75c654b98794f931582

b54c629930 Fix typo github worklfow (#2944)
This commit is contained in:
Tomas Votruba 2022-09-22 13:29:36 +00:00
parent cd097e556c
commit 34e47ea0dd
8 changed files with 216 additions and 18 deletions

2
vendor/autoload.php vendored
View File

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

View File

@ -2063,6 +2063,7 @@ return array(
'Rector\\PHPUnit\\NodeManipulator\\ParamAndArgFromArrayResolver' => $vendorDir . '/rector/rector-phpunit/src/NodeManipulator/ParamAndArgFromArrayResolver.php',
'Rector\\PHPUnit\\PhpDoc\\PhpDocValueToNodeMapper' => $vendorDir . '/rector/rector-phpunit/src/PhpDoc/PhpDocValueToNodeMapper.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\\ExceptionAnnotationRector' => $vendorDir . '/rector/rector-phpunit/src/Rector/ClassMethod/ExceptionAnnotationRector.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',

View File

@ -2,7 +2,7 @@
// autoload_real.php @generated by Composer
class ComposerAutoloaderInit2efded6cc227fa7428abf5633c9fc6c2
class ComposerAutoloaderInit85420e06c47b6b906ba6959bb45828f0
{
private static $loader;
@ -22,19 +22,19 @@ class ComposerAutoloaderInit2efded6cc227fa7428abf5633c9fc6c2
return self::$loader;
}
spl_autoload_register(array('ComposerAutoloaderInit2efded6cc227fa7428abf5633c9fc6c2', 'loadClassLoader'), true, true);
spl_autoload_register(array('ComposerAutoloaderInit85420e06c47b6b906ba6959bb45828f0', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
spl_autoload_unregister(array('ComposerAutoloaderInit2efded6cc227fa7428abf5633c9fc6c2', 'loadClassLoader'));
spl_autoload_unregister(array('ComposerAutoloaderInit85420e06c47b6b906ba6959bb45828f0', 'loadClassLoader'));
require __DIR__ . '/autoload_static.php';
call_user_func(\Composer\Autoload\ComposerStaticInit2efded6cc227fa7428abf5633c9fc6c2::getInitializer($loader));
call_user_func(\Composer\Autoload\ComposerStaticInit85420e06c47b6b906ba6959bb45828f0::getInitializer($loader));
$loader->setClassMapAuthoritative(true);
$loader->register(true);
$includeFiles = \Composer\Autoload\ComposerStaticInit2efded6cc227fa7428abf5633c9fc6c2::$files;
$includeFiles = \Composer\Autoload\ComposerStaticInit85420e06c47b6b906ba6959bb45828f0::$files;
foreach ($includeFiles as $fileIdentifier => $file) {
composerRequire2efded6cc227fa7428abf5633c9fc6c2($fileIdentifier, $file);
composerRequire85420e06c47b6b906ba6959bb45828f0($fileIdentifier, $file);
}
return $loader;
@ -46,7 +46,7 @@ class ComposerAutoloaderInit2efded6cc227fa7428abf5633c9fc6c2
* @param string $file
* @return void
*/
function composerRequire2efded6cc227fa7428abf5633c9fc6c2($fileIdentifier, $file)
function composerRequire85420e06c47b6b906ba6959bb45828f0($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 ComposerStaticInit2efded6cc227fa7428abf5633c9fc6c2
class ComposerStaticInit85420e06c47b6b906ba6959bb45828f0
{
public static $files = array (
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
@ -2323,6 +2323,7 @@ class ComposerStaticInit2efded6cc227fa7428abf5633c9fc6c2
'Rector\\PHPUnit\\NodeManipulator\\ParamAndArgFromArrayResolver' => __DIR__ . '/..' . '/rector/rector-phpunit/src/NodeManipulator/ParamAndArgFromArrayResolver.php',
'Rector\\PHPUnit\\PhpDoc\\PhpDocValueToNodeMapper' => __DIR__ . '/..' . '/rector/rector-phpunit/src/PhpDoc/PhpDocValueToNodeMapper.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\\ExceptionAnnotationRector' => __DIR__ . '/..' . '/rector/rector-phpunit/src/Rector/ClassMethod/ExceptionAnnotationRector.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',
@ -3106,9 +3107,9 @@ class ComposerStaticInit2efded6cc227fa7428abf5633c9fc6c2
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInit2efded6cc227fa7428abf5633c9fc6c2::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit2efded6cc227fa7428abf5633c9fc6c2::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit2efded6cc227fa7428abf5633c9fc6c2::$classMap;
$loader->prefixLengthsPsr4 = ComposerStaticInit85420e06c47b6b906ba6959bb45828f0::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit85420e06c47b6b906ba6959bb45828f0::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit85420e06c47b6b906ba6959bb45828f0::$classMap;
}, null, ClassLoader::class);
}

View File

@ -2195,12 +2195,12 @@
"source": {
"type": "git",
"url": "https:\/\/github.com\/rectorphp\/rector-phpunit.git",
"reference": "cf30315aeca41cc35fd736bb63c4bbbbe4d56fc6"
"reference": "963c24df5d7c459b4fb9b82f2e7c59644f66b306"
},
"dist": {
"type": "zip",
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-phpunit\/zipball\/cf30315aeca41cc35fd736bb63c4bbbbe4d56fc6",
"reference": "cf30315aeca41cc35fd736bb63c4bbbbe4d56fc6",
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-phpunit\/zipball\/963c24df5d7c459b4fb9b82f2e7c59644f66b306",
"reference": "963c24df5d7c459b4fb9b82f2e7c59644f66b306",
"shasum": ""
},
"require": {
@ -2226,7 +2226,7 @@
"symplify\/rule-doc-generator": "^11.1",
"symplify\/vendor-patches": "^11.1"
},
"time": "2022-09-13T12:51:48+00:00",
"time": "2022-09-21T17:56:12+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-cakephp' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-cakephp', 'relative_install_path' => '../../rector-cakephp', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main a489bf0'), '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 c56069f'), '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 d75c674'), 'rector/rector-laravel' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-laravel', 'relative_install_path' => '../../rector-laravel', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 2decdcf'), '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 8d6cbe9'), 'rector/rector-phpoffice' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-phpoffice', 'relative_install_path' => '../../rector-phpoffice', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 294de0c'), '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 cf30315'), '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 421857f'));
public const EXTENSIONS = array('rector/rector-cakephp' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-cakephp', 'relative_install_path' => '../../rector-cakephp', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main a489bf0'), '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 c56069f'), '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 d75c674'), 'rector/rector-laravel' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-laravel', 'relative_install_path' => '../../rector-laravel', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 2decdcf'), '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 8d6cbe9'), 'rector/rector-phpoffice' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-phpoffice', 'relative_install_path' => '../../rector-phpoffice', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 294de0c'), '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 963c24d'), '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 421857f'));
private function __construct()
{
}

View File

@ -0,0 +1,196 @@
<?php
declare (strict_types=1);
namespace Rector\PHPUnit\Rector\ClassMethod;
use PhpParser\Node;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\Array_;
use PhpParser\Node\Expr\Assign;
use PhpParser\Node\Expr\ClassConstFetch;
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Expr\New_;
use PhpParser\Node\Scalar;
use PhpParser\Node\Scalar\String_;
use PhpParser\Node\Stmt;
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\Expression;
use PhpParser\Node\Stmt\Return_;
use Rector\Core\Exception\NotImplementedYetException;
use Rector\Core\Exception\ShouldNotHappenException;
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\ClassMethod\CreateMockToAnonymousClassRector\CreateMockToAnonymousClassRectorTest
*/
final class CreateMockToAnonymousClassRector extends AbstractRector
{
/**
* @readonly
* @var \Rector\PHPUnit\NodeAnalyzer\TestsNodeAnalyzer
*/
private $testsNodeAnalyzer;
public function __construct(TestsNodeAnalyzer $testsNodeAnalyzer)
{
$this->testsNodeAnalyzer = $testsNodeAnalyzer;
}
public function getRuleDefinition() : RuleDefinition
{
return new RuleDefinition('Change $this->createMock() with methods to direct anonymous class', [new CodeSample(<<<'CODE_SAMPLE'
use PHPUnit\Framework\TestCase;
final class SomeTest extends TestCase
{
public function test()
{
$someMockObject = $this->createMock(SomeClass::class);
$someMockObject->method('someMethod')
->willReturn(100);
}
}
CODE_SAMPLE
, <<<'CODE_SAMPLE'
use PHPUnit\Framework\TestCase;
final class SomeTest extends TestCase
{
public function test()
{
$someMockObject = new class extends SomeClass {
public function someMethod()
{
return 100;
}
};
}
}
CODE_SAMPLE
)]);
}
/**
* @return array<class-string<Node>>
*/
public function getNodeTypes() : array
{
return [ClassMethod::class];
}
/**
* @param ClassMethod $node
*/
public function refactor(Node $node) : ?Node
{
if (!$this->testsNodeAnalyzer->isInTestClass($node)) {
return null;
}
if ($node->stmts === []) {
return null;
}
$anonymousClassPosition = null;
$anonymousClass = null;
$mockExpr = null;
$hasDynamicReturnExprs = \false;
$anonymousClassMethods = [];
$createMockMethodCallAssign = null;
foreach ((array) $node->stmts as $key => $classMethodStmt) {
if ($mockExpr instanceof Expr) {
// possible call on mock expr
if ($classMethodStmt instanceof Expression && $classMethodStmt->expr instanceof MethodCall) {
$methodCall = $classMethodStmt->expr;
$rootMethodCall = $methodCall;
while ($rootMethodCall->var instanceof MethodCall) {
$rootMethodCall = $rootMethodCall->var;
}
if (!$this->nodeComparator->areNodesEqual($rootMethodCall->var, $mockExpr)) {
continue;
}
if (!$this->isName($rootMethodCall->name, 'method')) {
continue;
}
// has dynamic return?
if ($hasDynamicReturnExprs === \false) {
$returnedExpr = $methodCall->getArgs()[0]->value;
$hasDynamicReturnExprs = !$returnedExpr instanceof Scalar && !$returnedExpr instanceof Array_;
}
$anonymousClassMethods[$key] = $this->createMockedClassMethod($rootMethodCall, $methodCall);
}
continue;
}
$createMockMethodCallAssign = $this->matchCreateMockAssign($classMethodStmt);
if (!$createMockMethodCallAssign instanceof Assign) {
continue;
}
// change to anonymous class
/** @var MethodCall $methodCall */
$methodCall = $createMockMethodCallAssign->expr;
$firstArg = $methodCall->getArgs()[0];
$mockExpr = $createMockMethodCallAssign->var;
$anonymousClass = $this->createAnonymousClass($firstArg);
$anonymousClassPosition = $key;
}
if ($anonymousClassPosition === null) {
return null;
}
if (!$anonymousClass instanceof Class_) {
return null;
}
if ($hasDynamicReturnExprs) {
return null;
}
foreach ($anonymousClassMethods as $keyToRemove => $anonymousClassMethod) {
unset($node->stmts[$keyToRemove]);
$anonymousClass->stmts[] = $anonymousClassMethod;
}
if (!$createMockMethodCallAssign instanceof Assign) {
throw new ShouldNotHappenException();
}
$new = new New_($anonymousClass);
$newAnonymousClassAssign = new Assign($createMockMethodCallAssign->var, $new);
$node->stmts[$anonymousClassPosition] = new Expression($newAnonymousClassAssign);
return $node;
}
private function createAnonymousClass(Arg $firstArg) : Class_
{
if ($firstArg->value instanceof ClassConstFetch) {
$className = $firstArg->value->class;
} else {
throw new NotImplementedYetException();
}
// must respect PHPStan anonymous internal naming \Rector\NodeTypeResolver\PHPStan\Scope\PHPStanNodeScopeResolver::ANONYMOUS_CLASS_START_REGEX
return new Class_('AnonymousClass1234', ['extends' => $className]);
}
private function matchCreateMockAssign(Stmt $stmt) : ?Assign
{
if (!$stmt instanceof Expression) {
return null;
}
if (!$stmt->expr instanceof Assign) {
return null;
}
// assign method call to variable
$assign = $stmt->expr;
if (!$assign->expr instanceof MethodCall) {
return null;
}
if (!$this->isName($assign->expr->name, 'createMock')) {
return null;
}
return $assign;
}
private function createMockedClassMethod(MethodCall $rootMethodCall, MethodCall $methodCall) : ClassMethod
{
$rootMethodCallFirstArg = $rootMethodCall->getArgs()[0];
$methodNameExpr = $rootMethodCallFirstArg->value;
if ($methodNameExpr instanceof String_) {
$methodName = $methodNameExpr->value;
} else {
throw new NotImplementedYetException();
}
$returnedExpr = $methodCall->getArgs()[0]->value;
return new ClassMethod($methodName, ['flags' => Class_::MODIFIER_PUBLIC, 'stmts' => [new Return_($returnedExpr)]]);
}
}