mirror of
https://github.com/rectorphp/rector.git
synced 2024-06-01 08:50:50 +00:00
Updated Rector to commit 4795d003614d98b04c3fce209e855f18ac48ed09
4795d00361
[Renaming] Skip pointless names in RenameForeachValueVariableToMatchMethodCallReturnTypeRector (#5188)
This commit is contained in:
parent
af933fd21f
commit
ac6d3dea06
1
vendor/composer/autoload_classmap.php
vendored
1
vendor/composer/autoload_classmap.php
vendored
|
@ -1688,6 +1688,7 @@ return array(
|
|||
'Rector\\PHPUnit\\CodeQuality\\Rector\\Foreach_\\SimplifyForeachInstanceOfRector' => $vendorDir . '/rector/rector-phpunit/rules/CodeQuality/Rector/Foreach_/SimplifyForeachInstanceOfRector.php',
|
||||
'Rector\\PHPUnit\\CodeQuality\\Rector\\MethodCall\\AssertCompareToSpecificMethodRector' => $vendorDir . '/rector/rector-phpunit/rules/CodeQuality/Rector/MethodCall/AssertCompareToSpecificMethodRector.php',
|
||||
'Rector\\PHPUnit\\CodeQuality\\Rector\\MethodCall\\AssertComparisonToSpecificMethodRector' => $vendorDir . '/rector/rector-phpunit/rules/CodeQuality/Rector/MethodCall/AssertComparisonToSpecificMethodRector.php',
|
||||
'Rector\\PHPUnit\\CodeQuality\\Rector\\MethodCall\\AssertEmptyNullableObjectToAssertInstanceofRector' => $vendorDir . '/rector/rector-phpunit/rules/CodeQuality/Rector/MethodCall/AssertEmptyNullableObjectToAssertInstanceofRector.php',
|
||||
'Rector\\PHPUnit\\CodeQuality\\Rector\\MethodCall\\AssertEqualsToSameRector' => $vendorDir . '/rector/rector-phpunit/rules/CodeQuality/Rector/MethodCall/AssertEqualsToSameRector.php',
|
||||
'Rector\\PHPUnit\\CodeQuality\\Rector\\MethodCall\\AssertFalseStrposToContainsRector' => $vendorDir . '/rector/rector-phpunit/rules/CodeQuality/Rector/MethodCall/AssertFalseStrposToContainsRector.php',
|
||||
'Rector\\PHPUnit\\CodeQuality\\Rector\\MethodCall\\AssertInstanceOfComparisonRector' => $vendorDir . '/rector/rector-phpunit/rules/CodeQuality/Rector/MethodCall/AssertInstanceOfComparisonRector.php',
|
||||
|
|
1
vendor/composer/autoload_static.php
vendored
1
vendor/composer/autoload_static.php
vendored
|
@ -1906,6 +1906,7 @@ class ComposerStaticInit46a0b0ac2ea1371bb06be09a20f71c2b
|
|||
'Rector\\PHPUnit\\CodeQuality\\Rector\\Foreach_\\SimplifyForeachInstanceOfRector' => __DIR__ . '/..' . '/rector/rector-phpunit/rules/CodeQuality/Rector/Foreach_/SimplifyForeachInstanceOfRector.php',
|
||||
'Rector\\PHPUnit\\CodeQuality\\Rector\\MethodCall\\AssertCompareToSpecificMethodRector' => __DIR__ . '/..' . '/rector/rector-phpunit/rules/CodeQuality/Rector/MethodCall/AssertCompareToSpecificMethodRector.php',
|
||||
'Rector\\PHPUnit\\CodeQuality\\Rector\\MethodCall\\AssertComparisonToSpecificMethodRector' => __DIR__ . '/..' . '/rector/rector-phpunit/rules/CodeQuality/Rector/MethodCall/AssertComparisonToSpecificMethodRector.php',
|
||||
'Rector\\PHPUnit\\CodeQuality\\Rector\\MethodCall\\AssertEmptyNullableObjectToAssertInstanceofRector' => __DIR__ . '/..' . '/rector/rector-phpunit/rules/CodeQuality/Rector/MethodCall/AssertEmptyNullableObjectToAssertInstanceofRector.php',
|
||||
'Rector\\PHPUnit\\CodeQuality\\Rector\\MethodCall\\AssertEqualsToSameRector' => __DIR__ . '/..' . '/rector/rector-phpunit/rules/CodeQuality/Rector/MethodCall/AssertEqualsToSameRector.php',
|
||||
'Rector\\PHPUnit\\CodeQuality\\Rector\\MethodCall\\AssertFalseStrposToContainsRector' => __DIR__ . '/..' . '/rector/rector-phpunit/rules/CodeQuality/Rector/MethodCall/AssertFalseStrposToContainsRector.php',
|
||||
'Rector\\PHPUnit\\CodeQuality\\Rector\\MethodCall\\AssertInstanceOfComparisonRector' => __DIR__ . '/..' . '/rector/rector-phpunit/rules/CodeQuality/Rector/MethodCall/AssertInstanceOfComparisonRector.php',
|
||||
|
|
8
vendor/composer/installed.json
vendored
8
vendor/composer/installed.json
vendored
|
@ -1808,12 +1808,12 @@
|
|||
"source": {
|
||||
"type": "git",
|
||||
"url": "https:\/\/github.com\/rectorphp\/rector-phpunit.git",
|
||||
"reference": "9baa15ab8d6c83a8df902cf7cb6209df9e76a530"
|
||||
"reference": "1b32010dbc083f51baa5e28d6a510083215a5be5"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-phpunit\/zipball\/9baa15ab8d6c83a8df902cf7cb6209df9e76a530",
|
||||
"reference": "9baa15ab8d6c83a8df902cf7cb6209df9e76a530",
|
||||
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-phpunit\/zipball\/1b32010dbc083f51baa5e28d6a510083215a5be5",
|
||||
"reference": "1b32010dbc083f51baa5e28d6a510083215a5be5",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
@ -1843,7 +1843,7 @@
|
|||
"tomasvotruba\/unused-public": "^0.3",
|
||||
"tracy\/tracy": "^2.10"
|
||||
},
|
||||
"time": "2023-10-11T09:26:32+00:00",
|
||||
"time": "2023-10-18T13:57:21+00:00",
|
||||
"default-branch": true,
|
||||
"type": "rector-extension",
|
||||
"extra": {
|
||||
|
|
2
vendor/composer/installed.php
vendored
2
vendor/composer/installed.php
vendored
File diff suppressed because one or more lines are too long
|
@ -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 a846e7f'), '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 850b492'), '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 9baa15a'), '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 873458c'));
|
||||
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 a846e7f'), '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 850b492'), '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 1b32010'), '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 873458c'));
|
||||
private function __construct()
|
||||
{
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ use Rector\PHPUnit\CodeQuality\Rector\ClassMethod\ReplaceTestAnnotationWithPrefi
|
|||
use Rector\PHPUnit\CodeQuality\Rector\Foreach_\SimplifyForeachInstanceOfRector;
|
||||
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\AssertEqualsToSameRector;
|
||||
use Rector\PHPUnit\CodeQuality\Rector\MethodCall\AssertFalseStrposToContainsRector;
|
||||
use Rector\PHPUnit\CodeQuality\Rector\MethodCall\AssertInstanceOfComparisonRector;
|
||||
|
@ -37,7 +38,7 @@ return static function (RectorConfig $rectorConfig) : void {
|
|||
YieldDataProviderRector::class,
|
||||
RemoveEmptyTestMethodRector::class,
|
||||
ReplaceTestAnnotationWithPrefixedFunctionRector::class,
|
||||
// sepcific asserts
|
||||
// specific asserts
|
||||
AssertCompareToSpecificMethodRector::class,
|
||||
AssertComparisonToSpecificMethodRector::class,
|
||||
AssertNotOperatorRector::class,
|
||||
|
@ -51,6 +52,7 @@ return static function (RectorConfig $rectorConfig) : void {
|
|||
SimplifyForeachInstanceOfRector::class,
|
||||
UseSpecificWillMethodRector::class,
|
||||
UseSpecificWithMethodRector::class,
|
||||
AssertEmptyNullableObjectToAssertInstanceofRector::class,
|
||||
/**
|
||||
* Improve direct testing of your code, without mock creep. Make it simple, clear and easy to maintain:
|
||||
*
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# 47 Rules Overview
|
||||
# 49 Rules Overview
|
||||
|
||||
## AddDoesNotPerformAssertionToNonAssertingTestRector
|
||||
|
||||
|
@ -132,6 +132,47 @@ Turns comparison operations to their method name alternatives in PHPUnit TestCas
|
|||
|
||||
<br>
|
||||
|
||||
## AssertEmptyNullableObjectToAssertInstanceofRector
|
||||
|
||||
Change `assertNotEmpty()` on an object to more clear `assertInstanceof()`
|
||||
|
||||
- class: [`Rector\PHPUnit\CodeQuality\Rector\MethodCall\AssertEmptyNullableObjectToAssertInstanceofRector`](../rules/CodeQuality/Rector/MethodCall/AssertEmptyNullableObjectToAssertInstanceofRector.php)
|
||||
|
||||
```diff
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class SomeClass extends TestCase
|
||||
{
|
||||
public function test()
|
||||
{
|
||||
$someObject = new stdClass();
|
||||
|
||||
- $this->assertNotEmpty($someObject);
|
||||
+ $this->assertInstanceof(stdClass::class, $someObject);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
<br>
|
||||
|
||||
## AssertEqualsOrAssertSameFloatParameterToSpecificMethodsTypeRector
|
||||
|
||||
Change `assertEquals()/assertSame()` method using float on expected argument to new specific alternatives.
|
||||
|
||||
- class: [`Rector\PHPUnit\Transform\AssertEqualsOrAssertSameFloatParameterToSpecificMethodsTypeRector`](../src/Transform/AssertEqualsOrAssertSameFloatParameterToSpecificMethodsTypeRector.php)
|
||||
|
||||
```diff
|
||||
-$this->assertSame(10.20, $value);
|
||||
-$this->assertEquals(10.20, $value);
|
||||
-$this->assertEquals(10.200, $value);
|
||||
+$this->assertEqualsWithDelta(10.20, $value, PHP_FLOAT_EPSILON);
|
||||
+$this->assertEqualsWithDelta(10.20, $value, PHP_FLOAT_EPSILON);
|
||||
+$this->assertEqualsWithDelta(10.200, $value, PHP_FLOAT_EPSILON);
|
||||
$this->assertSame(10, $value);
|
||||
```
|
||||
|
||||
<br>
|
||||
|
||||
## AssertEqualsParameterToSpecificMethodsTypeRector
|
||||
|
||||
Change `assertEquals()/assertNotEquals()` method parameters to new specific alternatives
|
||||
|
@ -1022,7 +1063,7 @@ Changes `->with()` to more specific method
|
|||
|
||||
## WithConsecutiveRector
|
||||
|
||||
Refactor `"withConsecutive()"` to
|
||||
Refactor deprecated `withConsecutive()` to `willReturnCallback()` structure
|
||||
|
||||
- class: [`Rector\PHPUnit\Rector\StmtsAwareInterface\WithConsecutiveRector`](../src/Rector/StmtsAwareInterface/WithConsecutiveRector.php)
|
||||
|
||||
|
|
|
@ -0,0 +1,96 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace Rector\PHPUnit\CodeQuality\Rector\MethodCall;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Arg;
|
||||
use PhpParser\Node\Expr\ClassConstFetch;
|
||||
use PhpParser\Node\Expr\MethodCall;
|
||||
use PhpParser\Node\Identifier;
|
||||
use PhpParser\Node\Name\FullyQualified;
|
||||
use PHPStan\Type\ObjectType;
|
||||
use PHPStan\Type\TypeCombinator;
|
||||
use PHPStan\Type\UnionType;
|
||||
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\CodeQuality\Rector\MethodCall\AssertEmptyNullableObjectToAssertInstanceofRector\AssertEmptyNullableObjectToAssertInstanceofRectorTest
|
||||
*/
|
||||
final class AssertEmptyNullableObjectToAssertInstanceofRector 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 assertNotEmpty() on an object to more clear assertInstanceof()', [new CodeSample(<<<'CODE_SAMPLE'
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class SomeClass extends TestCase
|
||||
{
|
||||
public function test()
|
||||
{
|
||||
$someObject = new stdClass();
|
||||
|
||||
$this->assertNotEmpty($someObject);
|
||||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
, <<<'CODE_SAMPLE'
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class SomeClass extends TestCase
|
||||
{
|
||||
public function test()
|
||||
{
|
||||
$someObject = new stdClass();
|
||||
|
||||
$this->assertInstanceof(stdClass::class, $someObject);
|
||||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
)]);
|
||||
}
|
||||
/**
|
||||
* @return array<class-string<Node>>
|
||||
*/
|
||||
public function getNodeTypes() : array
|
||||
{
|
||||
return [MethodCall::class];
|
||||
}
|
||||
/**
|
||||
* @param MethodCall $node
|
||||
*/
|
||||
public function refactor(Node $node) : ?Node
|
||||
{
|
||||
if (!$this->testsNodeAnalyzer->isInTestClass($node)) {
|
||||
return null;
|
||||
}
|
||||
if (!$this->isName($node->name, 'assertNotEmpty')) {
|
||||
return null;
|
||||
}
|
||||
$firstArg = $node->getArgs()[0];
|
||||
$firstArgType = $this->getType($firstArg->value);
|
||||
if (!$firstArgType instanceof UnionType) {
|
||||
return null;
|
||||
}
|
||||
$pureType = TypeCombinator::removeNull($firstArgType);
|
||||
if (!$pureType instanceof ObjectType) {
|
||||
return null;
|
||||
}
|
||||
$node->name = new Identifier('assertInstanceOf');
|
||||
$fullyQualified = new FullyQualified($pureType->getClassName());
|
||||
$node->args[0] = new Arg(new ClassConstFetch($fullyQualified, 'class'));
|
||||
$node->args[1] = $firstArg;
|
||||
return $node;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user