Updated Rector to commit 22915933d05f2a3e38355cd150ec67401a0fe3b9

22915933d0 [automated] Apply Coding Standard (#6627)
This commit is contained in:
Tomas Votruba 2024-12-23 23:45:34 +00:00
parent 99d5371f01
commit 0aa5d110fd
6 changed files with 41 additions and 14 deletions

View File

@ -1808,12 +1808,12 @@
"source": {
"type": "git",
"url": "https:\/\/github.com\/rectorphp\/rector-phpunit.git",
"reference": "c7ac374a0eba8440cd11fde384654704c27df130"
"reference": "bd24ae11a0cf94b05b78fb0adbb1cae05f4e2e3d"
},
"dist": {
"type": "zip",
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-phpunit\/zipball\/c7ac374a0eba8440cd11fde384654704c27df130",
"reference": "c7ac374a0eba8440cd11fde384654704c27df130",
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-phpunit\/zipball\/bd24ae11a0cf94b05b78fb0adbb1cae05f4e2e3d",
"reference": "bd24ae11a0cf94b05b78fb0adbb1cae05f4e2e3d",
"shasum": ""
},
"require": {
@ -1834,7 +1834,7 @@
"tomasvotruba\/class-leak": "^1.2",
"tracy\/tracy": "^2.10"
},
"time": "2024-12-23T09:51:21+00:00",
"time": "2024-12-23T14:02:30+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/rector-build/vendor/rector/rector-doctrine', 'relative_install_path' => '../../rector-doctrine', 'extra' => NULL, 'version' => 'dev-main 1523ce5'), 'rector/rector-downgrade-php' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-downgrade-php', 'relative_install_path' => '../../rector-downgrade-php', 'extra' => NULL, 'version' => 'dev-main 183795c'), 'rector/rector-phpunit' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-phpunit', 'relative_install_path' => '../../rector-phpunit', 'extra' => NULL, 'version' => 'dev-main c7ac374'), 'rector/rector-symfony' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-symfony', 'relative_install_path' => '../../rector-symfony', 'extra' => NULL, 'version' => 'dev-main 29a1abf'));
public const EXTENSIONS = array('rector/rector-doctrine' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-doctrine', 'relative_install_path' => '../../rector-doctrine', 'extra' => NULL, 'version' => 'dev-main 1523ce5'), 'rector/rector-downgrade-php' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-downgrade-php', 'relative_install_path' => '../../rector-downgrade-php', 'extra' => NULL, 'version' => 'dev-main 183795c'), 'rector/rector-phpunit' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-phpunit', 'relative_install_path' => '../../rector-phpunit', 'extra' => NULL, 'version' => 'dev-main bd24ae1'), 'rector/rector-symfony' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-symfony', 'relative_install_path' => '../../rector-symfony', 'extra' => NULL, 'version' => 'dev-main 29a1abf'));
private function __construct()
{
}

View File

@ -15,7 +15,6 @@ 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\AssertCompareOnCountableWithMethodToAssertCountRector;
use Rector\PHPUnit\CodeQuality\Rector\MethodCall\AssertCompareToSpecificMethodRector;
use Rector\PHPUnit\CodeQuality\Rector\MethodCall\AssertComparisonToSpecificMethodRector;
use Rector\PHPUnit\CodeQuality\Rector\MethodCall\AssertEmptyNullableObjectToAssertInstanceofRector;
use Rector\PHPUnit\CodeQuality\Rector\MethodCall\AssertEqualsOrAssertSameFloatParameterToSpecificMethodsTypeRector;
@ -56,7 +55,6 @@ return static function (RectorConfig $rectorConfig) : void {
NarrowUnusedSetUpDefinedPropertyRector::class,
// specific asserts
AssertCompareOnCountableWithMethodToAssertCountRector::class,
AssertCompareToSpecificMethodRector::class,
AssertComparisonToSpecificMethodRector::class,
AssertNotOperatorRector::class,
AssertTrueFalseToSpecificMethodRector::class,

View File

@ -9,15 +9,17 @@ use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Expr\StaticCall;
use PhpParser\Node\Identifier;
use Rector\Configuration\Deprecation\Contract\DeprecatedInterface;
use Rector\PHPUnit\NodeAnalyzer\TestsNodeAnalyzer;
use Rector\PHPUnit\ValueObject\FunctionNameWithAssertMethods;
use Rector\Rector\AbstractRector;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
/**
* @see \Rector\PHPUnit\Tests\CodeQuality\Rector\MethodCall\AssertCompareToSpecificMethodRector\AssertCompareToSpecificMethodRectorTest
* @deprecated This rule is deprecated, as its logic is handled better
* by other smaller rules in phpunit-code-quality set
*/
final class AssertCompareToSpecificMethodRector extends AbstractRector
final class AssertCompareToSpecificMethodRector extends AbstractRector implements DeprecatedInterface
{
/**
* @readonly

View File

@ -5,10 +5,12 @@ namespace Rector\PHPUnit\CodeQuality\Rector\MethodCall;
use PhpParser\Node;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Expr\Instanceof_;
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Expr\StaticCall;
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Identifier;
use Rector\Exception\ShouldNotHappenException;
use Rector\PHPUnit\NodeAnalyzer\IdentifierManipulator;
use Rector\PHPUnit\NodeAnalyzer\TestsNodeAnalyzer;
@ -39,7 +41,7 @@ final class AssertInstanceOfComparisonRector extends AbstractRector
}
public function getRuleDefinition() : RuleDefinition
{
return new RuleDefinition('Turns instanceof comparisons to their method name alternatives in PHPUnit TestCase', [new CodeSample('$this->assertTrue($foo instanceof Foo, "message");', '$this->assertInstanceOf("Foo", $foo, "message");'), new CodeSample('$this->assertFalse($foo instanceof Foo, "message");', '$this->assertNotInstanceOf("Foo", $foo, "message");')]);
return new RuleDefinition('Turns instanceof comparisons to their method name alternatives in PHPUnit TestCase', [new CodeSample('$this->assertTrue($foo instanceof Foo, "message");', '$this->assertInstanceOf("Foo", $foo, "message");'), new CodeSample('$this->assertFalse($foo instanceof Foo, "message");', '$this->assertNotInstanceOf("Foo", $foo, "message");'), new CodeSample('$this->assertNotEquals(SomeInstance::class, get_class($value));', '$this->assertNotInstanceOf(SomeInstance::class, $value);')]);
}
/**
* @return array<class-string<Node>>
@ -53,11 +55,14 @@ final class AssertInstanceOfComparisonRector extends AbstractRector
*/
public function refactor(Node $node) : ?Node
{
$oldMethodNames = \array_keys(self::RENAME_METHODS_MAP);
if (!$this->testsNodeAnalyzer->isPHPUnitMethodCallNames($node, $oldMethodNames)) {
if ($node->isFirstClassCallable()) {
return null;
}
if ($node->isFirstClassCallable()) {
if ($this->testsNodeAnalyzer->isPHPUnitMethodCallNames($node, ['assertSame', 'assertNotSame', 'assertEquals', 'assertNotEquals'])) {
return $this->refactorGetClass($node);
}
$oldMethodNames = \array_keys(self::RENAME_METHODS_MAP);
if (!$this->testsNodeAnalyzer->isPHPUnitMethodCallNames($node, $oldMethodNames)) {
return null;
}
$firstArgumentValue = $node->getArgs()[0]->value;
@ -68,6 +73,28 @@ final class AssertInstanceOfComparisonRector extends AbstractRector
$this->changeArgumentsOrder($node);
return $node;
}
/**
* @param MethodCall|StaticCall $node
*/
private function refactorGetClass(Node $node) : ?Node
{
// we need 2 args
if (!isset($node->args[1])) {
return null;
}
$secondArgument = $node->getArgs()[1];
$secondArgumentValue = $secondArgument->value;
if ($secondArgumentValue instanceof FuncCall && $this->isName($secondArgumentValue->name, 'get_class')) {
$node->args[1] = $secondArgumentValue->getArgs()[0];
if ($this->isNames($node->name, ['assertSame', 'assertEquals'])) {
$node->name = new Identifier('assertInstanceOf');
} elseif ($this->isNames($node->name, ['assertNotSame', 'assertNotEquals'])) {
$node->name = new Identifier('assertNotInstanceOf');
}
return $node;
}
return null;
}
/**
* @param \PhpParser\Node\Expr\MethodCall|\PhpParser\Node\Expr\StaticCall $node
*/