Skip to content

Commit ca9ebb8

Browse files
committed
Rector 2.3.6
1 parent 3a115e8 commit ca9ebb8

File tree

12 files changed

+158
-17
lines changed

12 files changed

+158
-17
lines changed

src/Application/VersionResolver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ final class VersionResolver
1919
* @api
2020
* @var string
2121
*/
22-
public const PACKAGE_VERSION = 'e65ac6923329b7488e0b204470e3026cc1dcd289';
22+
public const PACKAGE_VERSION = '2.3.6';
2323
/**
2424
* @api
2525
* @var string

vendor/composer/autoload_classmap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2053,6 +2053,7 @@
20532053
'Rector\\PHPUnit\\PHPUnit100\\Rector\\StmtsAwareInterface\\ExpectsMethodCallDecorator' => $vendorDir . '/rector/rector-phpunit/rules/PHPUnit100/Rector/StmtsAwareInterface/ExpectsMethodCallDecorator.php',
20542054
'Rector\\PHPUnit\\PHPUnit100\\Rector\\StmtsAwareInterface\\WithConsecutiveRector' => $vendorDir . '/rector/rector-phpunit/rules/PHPUnit100/Rector/StmtsAwareInterface/WithConsecutiveRector.php',
20552055
'Rector\\PHPUnit\\PHPUnit110\\Rector\\Class_\\NamedArgumentForDataProviderRector' => $vendorDir . '/rector/rector-phpunit/rules/PHPUnit110/Rector/Class_/NamedArgumentForDataProviderRector.php',
2056+
'Rector\\PHPUnit\\PHPUnit120\\Rector\\CallLike\\CreateStubInCoalesceArgRector' => $vendorDir . '/rector/rector-phpunit/rules/PHPUnit120/Rector/CallLike/CreateStubInCoalesceArgRector.php',
20562057
'Rector\\PHPUnit\\PHPUnit120\\Rector\\CallLike\\CreateStubOverCreateMockArgRector' => $vendorDir . '/rector/rector-phpunit/rules/PHPUnit120/Rector/CallLike/CreateStubOverCreateMockArgRector.php',
20572058
'Rector\\PHPUnit\\PHPUnit120\\Rector\\ClassMethod\\ExpressionCreateMockToCreateStubRector' => $vendorDir . '/rector/rector-phpunit/rules/PHPUnit120/Rector/ClassMethod/ExpressionCreateMockToCreateStubRector.php',
20582059
'Rector\\PHPUnit\\PHPUnit120\\Rector\\Class_\\AllowMockObjectsForDataProviderRector' => $vendorDir . '/rector/rector-phpunit/rules/PHPUnit120/Rector/Class_/AllowMockObjectsForDataProviderRector.php',

vendor/composer/autoload_static.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2313,6 +2313,7 @@ class ComposerStaticInit6374fd21a3f525a40760d79e3596b56b
23132313
'Rector\\PHPUnit\\PHPUnit100\\Rector\\StmtsAwareInterface\\ExpectsMethodCallDecorator' => __DIR__ . '/..' . '/rector/rector-phpunit/rules/PHPUnit100/Rector/StmtsAwareInterface/ExpectsMethodCallDecorator.php',
23142314
'Rector\\PHPUnit\\PHPUnit100\\Rector\\StmtsAwareInterface\\WithConsecutiveRector' => __DIR__ . '/..' . '/rector/rector-phpunit/rules/PHPUnit100/Rector/StmtsAwareInterface/WithConsecutiveRector.php',
23152315
'Rector\\PHPUnit\\PHPUnit110\\Rector\\Class_\\NamedArgumentForDataProviderRector' => __DIR__ . '/..' . '/rector/rector-phpunit/rules/PHPUnit110/Rector/Class_/NamedArgumentForDataProviderRector.php',
2316+
'Rector\\PHPUnit\\PHPUnit120\\Rector\\CallLike\\CreateStubInCoalesceArgRector' => __DIR__ . '/..' . '/rector/rector-phpunit/rules/PHPUnit120/Rector/CallLike/CreateStubInCoalesceArgRector.php',
23162317
'Rector\\PHPUnit\\PHPUnit120\\Rector\\CallLike\\CreateStubOverCreateMockArgRector' => __DIR__ . '/..' . '/rector/rector-phpunit/rules/PHPUnit120/Rector/CallLike/CreateStubOverCreateMockArgRector.php',
23172318
'Rector\\PHPUnit\\PHPUnit120\\Rector\\ClassMethod\\ExpressionCreateMockToCreateStubRector' => __DIR__ . '/..' . '/rector/rector-phpunit/rules/PHPUnit120/Rector/ClassMethod/ExpressionCreateMockToCreateStubRector.php',
23182319
'Rector\\PHPUnit\\PHPUnit120\\Rector\\Class_\\AllowMockObjectsForDataProviderRector' => __DIR__ . '/..' . '/rector/rector-phpunit/rules/PHPUnit120/Rector/Class_/AllowMockObjectsForDataProviderRector.php',

vendor/composer/installed.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1818,12 +1818,12 @@
18181818
"source": {
18191819
"type": "git",
18201820
"url": "https:\/\/github.com\/rectorphp\/rector-phpunit.git",
1821-
"reference": "a791fc9b0f653b5bb79d4f5f1df40eebecaad556"
1821+
"reference": "7a914ca53f0576bcfbda803421701ebf850a4dfe"
18221822
},
18231823
"dist": {
18241824
"type": "zip",
1825-
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-phpunit\/zipball\/a791fc9b0f653b5bb79d4f5f1df40eebecaad556",
1826-
"reference": "a791fc9b0f653b5bb79d4f5f1df40eebecaad556",
1825+
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-phpunit\/zipball\/7a914ca53f0576bcfbda803421701ebf850a4dfe",
1826+
"reference": "7a914ca53f0576bcfbda803421701ebf850a4dfe",
18271827
"shasum": ""
18281828
},
18291829
"require": {
@@ -1850,7 +1850,7 @@
18501850
"tomasvotruba\/unused-public": "^2.2",
18511851
"tracy\/tracy": "^2.11"
18521852
},
1853-
"time": "2026-02-04T23:04:08+00:00",
1853+
"time": "2026-02-06T14:19:09+00:00",
18541854
"default-branch": true,
18551855
"type": "rector-extension",
18561856
"extra": {

vendor/composer/installed.php

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

vendor/rector/extension-installer/src/GeneratedConfig.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*/
1010
final class GeneratedConfig
1111
{
12-
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 46e4f77'), '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 a110e2f'), '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 a791fc9'), '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 eadb590'));
12+
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 46e4f77'), '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 a110e2f'), '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 7a914ca'), '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 eadb590'));
1313
private function __construct()
1414
{
1515
}

vendor/rector/rector-phpunit/config/sets/phpunit-code-quality.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
declare (strict_types=1);
44
namespace RectorPrefix202602;
55

6-
use Rector\PHPUnit\CodeQuality\Rector\Expression\DecorateWillReturnMapWithExpectsMockRector;
76
use Rector\Config\RectorConfig;
87
use Rector\PHPUnit\CodeQuality\Rector\CallLike\DirectInstanceOverMockArgRector;
98
use Rector\PHPUnit\CodeQuality\Rector\Class_\AddParamTypeFromDependsRector;
@@ -27,6 +26,7 @@
2726
use Rector\PHPUnit\CodeQuality\Rector\ClassMethod\RemoveStandaloneCreateMockRector;
2827
use Rector\PHPUnit\CodeQuality\Rector\ClassMethod\ReplaceTestAnnotationWithPrefixedFunctionRector;
2928
use Rector\PHPUnit\CodeQuality\Rector\Expression\AssertArrayCastedObjectToAssertSameRector;
29+
use Rector\PHPUnit\CodeQuality\Rector\Expression\DecorateWillReturnMapWithExpectsMockRector;
3030
use Rector\PHPUnit\CodeQuality\Rector\Foreach_\SimplifyForeachInstanceOfRector;
3131
use Rector\PHPUnit\CodeQuality\Rector\FuncCall\AssertFuncCallToPHPUnitAssertRector;
3232
use Rector\PHPUnit\CodeQuality\Rector\MethodCall\AssertCompareOnCountableWithMethodToAssertCountRector;

vendor/rector/rector-phpunit/config/sets/phpunit120.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@
44
namespace RectorPrefix202602;
55

66
use Rector\Config\RectorConfig;
7+
use Rector\PHPUnit\PHPUnit120\Rector\CallLike\CreateStubInCoalesceArgRector;
78
use Rector\PHPUnit\PHPUnit120\Rector\CallLike\CreateStubOverCreateMockArgRector;
8-
use Rector\PHPUnit\PHPUnit120\Rector\Class_\AllowMockObjectsForDataProviderRector;
9-
use Rector\PHPUnit\PHPUnit120\Rector\Class_\AllowMockObjectsWhereParentClassRector;
10-
use Rector\PHPUnit\PHPUnit120\Rector\Class_\AllowMockObjectsWithoutExpectationsAttributeRector;
119
use Rector\PHPUnit\PHPUnit120\Rector\Class_\AssertIsTypeMethodCallRector;
1210
use Rector\PHPUnit\PHPUnit120\Rector\Class_\PropertyCreateMockToCreateStubRector;
1311
use Rector\PHPUnit\PHPUnit120\Rector\Class_\RemoveOverrideFinalConstructTestCaseRector;
@@ -18,12 +16,8 @@
1816
AssertIsTypeMethodCallRector::class,
1917
// stubs over mocks
2018
CreateStubOverCreateMockArgRector::class,
19+
CreateStubInCoalesceArgRector::class,
2120
ExpressionCreateMockToCreateStubRector::class,
2221
PropertyCreateMockToCreateStubRector::class,
23-
AllowMockObjectsWhereParentClassRector::class,
24-
AllowMockObjectsForDataProviderRector::class,
25-
// experimental, from PHPUnit 12.5.2
26-
// @see https://github.com/sebastianbergmann/phpunit/commit/24c208d6a340c3071f28a9b5cce02b9377adfd43
27-
AllowMockObjectsWithoutExpectationsAttributeRector::class,
2822
]);
2923
};
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
declare (strict_types=1);
4+
namespace RectorPrefix202602;
5+
6+
use Rector\Config\RectorConfig;
7+
use Rector\PHPUnit\PHPUnit120\Rector\Class_\AllowMockObjectsForDataProviderRector;
8+
use Rector\PHPUnit\PHPUnit120\Rector\Class_\AllowMockObjectsWhereParentClassRector;
9+
use Rector\PHPUnit\PHPUnit120\Rector\Class_\AllowMockObjectsWithoutExpectationsAttributeRector;
10+
return static function (RectorConfig $rectorConfig): void {
11+
$rectorConfig->rules([
12+
AllowMockObjectsWhereParentClassRector::class,
13+
AllowMockObjectsForDataProviderRector::class,
14+
// experimental, from PHPUnit 12.5.2
15+
// @see https://github.com/sebastianbergmann/phpunit/commit/24c208d6a340c3071f28a9b5cce02b9377adfd43
16+
AllowMockObjectsWithoutExpectationsAttributeRector::class,
17+
]);
18+
};
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
<?php
2+
3+
declare (strict_types=1);
4+
namespace Rector\PHPUnit\PHPUnit120\Rector\CallLike;
5+
6+
use PhpParser\Node;
7+
use PhpParser\Node\ArrayItem;
8+
use PhpParser\Node\Expr\BinaryOp\Coalesce;
9+
use PhpParser\Node\Expr\MethodCall;
10+
use PhpParser\Node\Expr\New_;
11+
use PhpParser\Node\Expr\StaticCall;
12+
use PhpParser\Node\Identifier;
13+
use Rector\PHPUnit\NodeAnalyzer\TestsNodeAnalyzer;
14+
use Rector\Rector\AbstractRector;
15+
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
16+
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
17+
/**
18+
* Related change in PHPUnit 12 https://phpunit.expert/articles/testing-with-and-without-dependencies.html
19+
*
20+
* @see \Rector\PHPUnit\Tests\PHPUnit120\Rector\CallLike\CreateStubInCoalesceArgRector\CreateStubInCoalesceArgRectorTest
21+
*/
22+
final class CreateStubInCoalesceArgRector extends AbstractRector
23+
{
24+
/**
25+
* @readonly
26+
*/
27+
private TestsNodeAnalyzer $testsNodeAnalyzer;
28+
public function __construct(TestsNodeAnalyzer $testsNodeAnalyzer)
29+
{
30+
$this->testsNodeAnalyzer = $testsNodeAnalyzer;
31+
}
32+
public function getRuleDefinition(): RuleDefinition
33+
{
34+
return new RuleDefinition('Use createStub() over createMock() when used as argument/array item coalesce ?? fallback', [new CodeSample(<<<'CODE_SAMPLE'
35+
use PHPUnit\Framework\TestCase;
36+
37+
final class SomeTest extends TestCase
38+
{
39+
public function test()
40+
{
41+
$mockObject = $this->>get('service');
42+
$this->someMethod($mockObject ?? $this->createMock(SomeClass::class));
43+
}
44+
45+
private function someMethod($someClass)
46+
{
47+
}
48+
}
49+
CODE_SAMPLE
50+
, <<<'CODE_SAMPLE'
51+
use PHPUnit\Framework\TestCase;
52+
53+
final class SomeTest extends TestCase
54+
{
55+
public function test()
56+
{
57+
$mockObject = $this->>get('service');
58+
$this->someMethod($mockObject ?? $this->createStub(SomeClass::class));
59+
}
60+
61+
private function someMethod($someClass)
62+
{
63+
}
64+
CODE_SAMPLE
65+
)]);
66+
}
67+
/**
68+
* @return array<class-string<Node>>
69+
*/
70+
public function getNodeTypes(): array
71+
{
72+
return [StaticCall::class, MethodCall::class, New_::class, ArrayItem::class];
73+
}
74+
/**
75+
* @param MethodCall|StaticCall|New_|ArrayItem $node
76+
* @return \PhpParser\Node\Expr\MethodCall|\PhpParser\Node\Expr\StaticCall|\PhpParser\Node\Expr\New_|\PhpParser\Node\ArrayItem|null
77+
*/
78+
public function refactor(Node $node)
79+
{
80+
if (!$this->testsNodeAnalyzer->isInTestClass($node)) {
81+
return null;
82+
}
83+
if ($node instanceof ArrayItem) {
84+
return $this->refactorArrayItem($node);
85+
}
86+
$hasChanges = \false;
87+
if ($node->isFirstClassCallable()) {
88+
return null;
89+
}
90+
foreach ($node->getArgs() as $arg) {
91+
if (!$arg->value instanceof Coalesce) {
92+
continue;
93+
}
94+
$coalesce = $arg->value;
95+
if (!$coalesce->right instanceof MethodCall) {
96+
continue;
97+
}
98+
$methodCall = $coalesce->right;
99+
if (!$this->isName($methodCall->name, 'createMock')) {
100+
continue;
101+
}
102+
$methodCall->name = new Identifier('createStub');
103+
$hasChanges = \true;
104+
}
105+
if ($hasChanges) {
106+
return $node;
107+
}
108+
return null;
109+
}
110+
private function refactorArrayItem(ArrayItem $arrayItem): ?ArrayItem
111+
{
112+
if (!$arrayItem->value instanceof Coalesce) {
113+
return null;
114+
}
115+
$coalesce = $arrayItem->value;
116+
if (!$coalesce->right instanceof MethodCall) {
117+
return null;
118+
}
119+
$methodCall = $coalesce->right;
120+
if (!$this->isName($methodCall->name, 'createMock')) {
121+
return null;
122+
}
123+
$methodCall->name = new Identifier('createStub');
124+
return $arrayItem;
125+
}
126+
}

0 commit comments

Comments
 (0)