mirror of
https://github.com/rectorphp/rector.git
synced 2024-06-04 18:30:50 +00:00
Updated Rector to commit 6d8074534f3b568a0cecd373e584ea6c8d06580b
6d8074534f
Rectify (#5226)
This commit is contained in:
parent
2cdabcba36
commit
8e33333b8d
1
vendor/composer/autoload_classmap.php
vendored
1
vendor/composer/autoload_classmap.php
vendored
|
@ -1683,6 +1683,7 @@ return array(
|
|||
'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\\AnnotationsToAttributes\\Rector\\Class_\\TicketAnnotationToAttributeRector' => $vendorDir . '/rector/rector-phpunit/rules/AnnotationsToAttributes/Rector/Class_/TicketAnnotationToAttributeRector.php',
|
||||
'Rector\\PHPUnit\\CodeQuality\\Rector\\ClassMethod\\DataProviderArrayItemsNewLinedRector' => $vendorDir . '/rector/rector-phpunit/rules/CodeQuality/Rector/ClassMethod/DataProviderArrayItemsNewLinedRector.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',
|
||||
|
|
1
vendor/composer/autoload_static.php
vendored
1
vendor/composer/autoload_static.php
vendored
|
@ -1901,6 +1901,7 @@ class ComposerStaticInit18ad0e678efbbb500e116f7c54cccdd4
|
|||
'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\\AnnotationsToAttributes\\Rector\\Class_\\TicketAnnotationToAttributeRector' => __DIR__ . '/..' . '/rector/rector-phpunit/rules/AnnotationsToAttributes/Rector/Class_/TicketAnnotationToAttributeRector.php',
|
||||
'Rector\\PHPUnit\\CodeQuality\\Rector\\ClassMethod\\DataProviderArrayItemsNewLinedRector' => __DIR__ . '/..' . '/rector/rector-phpunit/rules/CodeQuality/Rector/ClassMethod/DataProviderArrayItemsNewLinedRector.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',
|
||||
|
|
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": "5b701c1aaa284e8276694876dc998f7194f7477c"
|
||||
"reference": "79785959255d68ad21b5d6e2a010d4435f0f8165"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-phpunit\/zipball\/5b701c1aaa284e8276694876dc998f7194f7477c",
|
||||
"reference": "5b701c1aaa284e8276694876dc998f7194f7477c",
|
||||
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-phpunit\/zipball\/79785959255d68ad21b5d6e2a010d4435f0f8165",
|
||||
"reference": "79785959255d68ad21b5d6e2a010d4435f0f8165",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
@ -1843,7 +1843,7 @@
|
|||
"tomasvotruba\/unused-public": "^0.3",
|
||||
"tracy\/tracy": "^2.10"
|
||||
},
|
||||
"time": "2023-11-06T15:42:49+00:00",
|
||||
"time": "2023-11-07T11:02:59+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 9de7d58'), '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 4056166'), '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 5b701c1'), '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 38014d4'));
|
||||
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 9de7d58'), '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 4056166'), '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 7978595'), '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 38014d4'));
|
||||
private function __construct()
|
||||
{
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ use Rector\PHPUnit\CodeQuality\Rector\Class_\ConstructClassMethodToSetUpTestCase
|
|||
use Rector\PHPUnit\CodeQuality\Rector\Class_\PreferPHPUnitThisCallRector;
|
||||
use Rector\PHPUnit\CodeQuality\Rector\Class_\TestWithToDataProviderRector;
|
||||
use Rector\PHPUnit\CodeQuality\Rector\Class_\YieldDataProviderRector;
|
||||
use Rector\PHPUnit\CodeQuality\Rector\ClassMethod\DataProviderArrayItemsNewLinedRector;
|
||||
use Rector\PHPUnit\CodeQuality\Rector\ClassMethod\RemoveEmptyTestMethodRector;
|
||||
use Rector\PHPUnit\CodeQuality\Rector\ClassMethod\ReplaceTestAnnotationWithPrefixedFunctionRector;
|
||||
use Rector\PHPUnit\CodeQuality\Rector\Foreach_\SimplifyForeachInstanceOfRector;
|
||||
|
@ -42,6 +43,7 @@ return static function (RectorConfig $rectorConfig) : void {
|
|||
ReplaceTestAnnotationWithPrefixedFunctionRector::class,
|
||||
TestWithToDataProviderRector::class,
|
||||
AssertEqualsOrAssertSameFloatParameterToSpecificMethodsTypeRector::class,
|
||||
DataProviderArrayItemsNewlinedRector::class,
|
||||
// specific asserts
|
||||
AssertCompareToSpecificMethodRector::class,
|
||||
AssertComparisonToSpecificMethodRector::class,
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# 49 Rules Overview
|
||||
# 51 Rules Overview
|
||||
|
||||
## AddDoesNotPerformAssertionToNonAssertingTestRector
|
||||
|
||||
|
@ -159,7 +159,7 @@ Change `assertNotEmpty()` on an object to more clear `assertInstanceof()`
|
|||
|
||||
Change `assertEquals()/assertSame()` method using float on expected argument to new specific alternatives.
|
||||
|
||||
- class: [`Rector\PHPUnit\Transform\AssertEqualsOrAssertSameFloatParameterToSpecificMethodsTypeRector`](../rules/CodeQuality/Rector/MethodCall/AssertEqualsOrAssertSameFloatParameterToSpecificMethodsTypeRector.php)
|
||||
- class: [`Rector\PHPUnit\CodeQuality\Rector\MethodCall\AssertEqualsOrAssertSameFloatParameterToSpecificMethodsTypeRector`](../rules/CodeQuality/Rector/MethodCall/AssertEqualsOrAssertSameFloatParameterToSpecificMethodsTypeRector.php)
|
||||
|
||||
```diff
|
||||
-$this->assertSame(10.20, $value);
|
||||
|
@ -485,6 +485,38 @@ Change dataProvider annotations to attribute
|
|||
|
||||
<br>
|
||||
|
||||
## DataProviderArrayItemsNewLinedRector
|
||||
|
||||
Change data provider in PHPUnit test case to newline per item
|
||||
|
||||
- class: [`Rector\PHPUnit\CodeQuality\Rector\ClassMethod\DataProviderArrayItemsNewLinedRector`](../rules/CodeQuality/Rector/ClassMethod/DataProviderArrayItemsNewLinedRector.php)
|
||||
|
||||
```diff
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
final class ImageBinaryTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider provideData()
|
||||
*/
|
||||
public function testGetBytesSize(string $content, int $number): void
|
||||
{
|
||||
// ...
|
||||
}
|
||||
|
||||
public static function provideData(): array
|
||||
{
|
||||
- return [['content', 8], ['content123', 11]];
|
||||
+ return [
|
||||
+ ['content', 8],
|
||||
+ ['content123', 11]
|
||||
+ ];
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
<br>
|
||||
|
||||
## DelegateExceptionArgumentsRector
|
||||
|
||||
Takes `setExpectedException()` 2nd and next arguments to own methods in PHPUnit.
|
||||
|
@ -995,6 +1027,39 @@ Change `@testWith()` annotation to #[TestWith] attribute
|
|||
|
||||
<br>
|
||||
|
||||
## TestWithToDataProviderRector
|
||||
|
||||
Replace testWith annotation to data provider.
|
||||
|
||||
- class: [`Rector\PHPUnit\CodeQuality\Rector\Class_\TestWithToDataProviderRector`](../rules/CodeQuality/Rector/Class_/TestWithToDataProviderRector.php)
|
||||
|
||||
```diff
|
||||
+public function dataProviderSum()
|
||||
+{
|
||||
+ return [
|
||||
+ [0, 0, 0],
|
||||
+ [0, 1, 1],
|
||||
+ [1, 0, 1],
|
||||
+ [1, 1, 3]
|
||||
+ ];
|
||||
+}
|
||||
+
|
||||
/**
|
||||
- * @testWith [0, 0, 0]
|
||||
- * @testWith [0, 1, 1]
|
||||
- * @testWith [1, 0, 1]
|
||||
- * @testWith [1, 1, 3]
|
||||
+ * @dataProvider dataProviderSum
|
||||
*/
|
||||
-public function testSum(int $a, int $b, int $expected)
|
||||
+public function test(int $a, int $b, int $expected)
|
||||
{
|
||||
$this->assertSame($expected, $a + $b);
|
||||
}
|
||||
```
|
||||
|
||||
<br>
|
||||
|
||||
## TicketAnnotationToAttributeRector
|
||||
|
||||
Change annotations with value to attribute
|
||||
|
|
|
@ -15,7 +15,7 @@ use Rector\BetterPhpDocParser\PhpDocManipulator\PhpDocTagRemover;
|
|||
use Rector\Comments\NodeDocBlock\DocBlockUpdater;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\Core\Reflection\ReflectionResolver;
|
||||
use Rector\Core\ValueObject\PhpVersionFeature;
|
||||
use Rector\Core\ValueObject\PhpVersion;
|
||||
use Rector\PhpAttribute\NodeFactory\PhpAttributeGroupFactory;
|
||||
use Rector\PHPUnit\NodeAnalyzer\TestsNodeAnalyzer;
|
||||
use Rector\VersionBonding\Contract\MinPhpVersionInterface;
|
||||
|
@ -102,7 +102,13 @@ CODE_SAMPLE
|
|||
}
|
||||
public function provideMinPhpVersion() : int
|
||||
{
|
||||
return PhpVersionFeature::ATTRIBUTES;
|
||||
/**
|
||||
* This rule just work for phpunit 10,
|
||||
* And as php 8.1 is the min version supported by phpunit 10, then we decided to let this version as minimum.
|
||||
*
|
||||
* You can see more detail in this issue: https://github.com/rectorphp/rector-phpunit/issues/272
|
||||
*/
|
||||
return PhpVersion::PHP_81;
|
||||
}
|
||||
/**
|
||||
* @param ClassMethod $node
|
||||
|
|
|
@ -0,0 +1,132 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace Rector\PHPUnit\CodeQuality\Rector\ClassMethod;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr\Array_;
|
||||
use PhpParser\Node\Stmt\ClassMethod;
|
||||
use PhpParser\Node\Stmt\Return_;
|
||||
use Rector\Core\PhpParser\Node\BetterNodeFinder;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
use Rector\PHPUnit\NodeAnalyzer\TestsNodeAnalyzer;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
/**
|
||||
* @see \Rector\PHPUnit\Tests\CodeQuality\Rector\ClassMethod\DataProviderArrayItemsNewLinedRector\DataProviderArrayItemsNewLinedRectorTest
|
||||
*/
|
||||
final class DataProviderArrayItemsNewLinedRector extends AbstractRector
|
||||
{
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\PHPUnit\NodeAnalyzer\TestsNodeAnalyzer
|
||||
*/
|
||||
private $testsNodeAnalyzer;
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\Core\PhpParser\Node\BetterNodeFinder
|
||||
*/
|
||||
private $betterNodeFinder;
|
||||
public function __construct(TestsNodeAnalyzer $testsNodeAnalyzer, BetterNodeFinder $betterNodeFinder)
|
||||
{
|
||||
/**
|
||||
* @readonly
|
||||
*/
|
||||
$this->testsNodeAnalyzer = $testsNodeAnalyzer;
|
||||
/**
|
||||
* @readonly
|
||||
*/
|
||||
$this->betterNodeFinder = $betterNodeFinder;
|
||||
}
|
||||
public function getRuleDefinition() : RuleDefinition
|
||||
{
|
||||
return new RuleDefinition('Change data provider in PHPUnit test case to newline per item', [new CodeSample(<<<'CODE_SAMPLE'
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
final class ImageBinaryTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider provideData()
|
||||
*/
|
||||
public function testGetBytesSize(string $content, int $number): void
|
||||
{
|
||||
// ...
|
||||
}
|
||||
|
||||
public static function provideData(): array
|
||||
{
|
||||
return [['content', 8], ['content123', 11]];
|
||||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
, <<<'CODE_SAMPLE'
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
final class ImageBinaryTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider provideData()
|
||||
*/
|
||||
public function testGetBytesSize(string $content, int $number): void
|
||||
{
|
||||
// ...
|
||||
}
|
||||
|
||||
public static function provideData(): array
|
||||
{
|
||||
return [
|
||||
['content', 8],
|
||||
['content123', 11]
|
||||
];
|
||||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
)]);
|
||||
}
|
||||
/**
|
||||
* @return array<class-string<Node>>
|
||||
*/
|
||||
public function getNodeTypes() : array
|
||||
{
|
||||
return [ClassMethod::class];
|
||||
}
|
||||
/**
|
||||
* @param ClassMethod $node
|
||||
*/
|
||||
public function refactor(Node $node) : ?Node
|
||||
{
|
||||
if (!$node->isPublic()) {
|
||||
return null;
|
||||
}
|
||||
if (!$this->testsNodeAnalyzer->isInTestClass($node)) {
|
||||
return null;
|
||||
}
|
||||
// skip test methods
|
||||
if (\strncmp($node->name->toString(), 'test', \strlen('test')) === 0) {
|
||||
return null;
|
||||
}
|
||||
// find array in data provider - must contain a return node
|
||||
/** @var Return_[] $returns */
|
||||
$returns = $this->betterNodeFinder->findInstanceOf((array) $node->stmts, Return_::class);
|
||||
$hasChanged = \false;
|
||||
foreach ($returns as $return) {
|
||||
if (!$return->expr instanceof Array_) {
|
||||
continue;
|
||||
}
|
||||
$array = $return->expr;
|
||||
if ($array->items === []) {
|
||||
continue;
|
||||
}
|
||||
// ensure newlined printed
|
||||
$array->setAttribute(AttributeKey::NEWLINED_ARRAY_PRINT, \true);
|
||||
// invoke reprint
|
||||
$array->setAttribute(AttributeKey::ORIGINAL_NODE, null);
|
||||
$hasChanged = \true;
|
||||
}
|
||||
if ($hasChanged) {
|
||||
return $node;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -21,7 +21,7 @@ use PhpParser\Node\Stmt\Return_;
|
|||
use PhpParser\NodeTraverser;
|
||||
use Rector\Core\PhpParser\Node\BetterNodeFinder;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\Core\ValueObject\PhpVersionFeature;
|
||||
use Rector\Core\ValueObject\PhpVersion;
|
||||
use Rector\PhpDocParser\NodeTraverser\SimpleCallableNodeTraverser;
|
||||
use Rector\PHPUnit\NodeAnalyzer\TestsNodeAnalyzer;
|
||||
use Rector\VersionBonding\Contract\MinPhpVersionInterface;
|
||||
|
@ -124,7 +124,13 @@ CODE_SAMPLE
|
|||
}
|
||||
public function provideMinPhpVersion() : int
|
||||
{
|
||||
return PhpVersionFeature::MATCH_EXPRESSION;
|
||||
/**
|
||||
* This rule just work for phpunit 10,
|
||||
* And as php 8.1 is the min version supported by phpunit 10, then we decided to let this version as minimum.
|
||||
*
|
||||
* You can see more detail in this issue: https://github.com/rectorphp/rector-phpunit/issues/272
|
||||
*/
|
||||
return PhpVersion::PHP_81;
|
||||
}
|
||||
/**
|
||||
* @template T of Node
|
||||
|
|
Loading…
Reference in New Issue
Block a user