Skip to content

Commit 30e54ca

Browse files
committed
Updated Rector to commit c4b68d5fd646875fa96f68941e4b2b643a06d1f8
rectorphp/rector-src@c4b68d5 [Php70] Handle class named Pool on Php4ConstructorRector (#6887)
1 parent 6fe147b commit 30e54ca

9 files changed

Lines changed: 119 additions & 10 deletions

File tree

rules/Php70/Rector/ClassMethod/Php4ConstructorRector.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public function refactor(Node $node) : ?\PhpParser\Node\Stmt\Class_
9999
// process parent call references first
100100
$this->processClassMethodStatementsForParentConstructorCalls($psr4ConstructorMethod, $scope);
101101
// does it already have a __construct method?
102-
if (!$classReflection->hasNativeMethod(MethodName::CONSTRUCT)) {
102+
if (!$node->getMethod(MethodName::CONSTRUCT) instanceof ClassMethod) {
103103
$psr4ConstructorMethod->name = new Identifier(MethodName::CONSTRUCT);
104104
}
105105
$classMethodStmts = $psr4ConstructorMethod->stmts;

src/Application/VersionResolver.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ final class VersionResolver
1919
* @api
2020
* @var string
2121
*/
22-
public const PACKAGE_VERSION = 'ef1c19fa032bc7937c0ab58ee9ea042039504486';
22+
public const PACKAGE_VERSION = 'c4b68d5fd646875fa96f68941e4b2b643a06d1f8';
2323
/**
2424
* @api
2525
* @var string
2626
*/
27-
public const RELEASE_DATE = '2025-05-05 18:47:57';
27+
public const RELEASE_DATE = '2025-05-06 21:50:14';
2828
/**
2929
* @var int
3030
*/

vendor/composer/autoload_classmap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1858,6 +1858,7 @@
18581858
'Rector\\PHPUnit\\PHPUnit100\\NodeDecorator\\WillReturnIfNodeDecorator' => $vendorDir . '/rector/rector-phpunit/rules/PHPUnit100/NodeDecorator/WillReturnIfNodeDecorator.php',
18591859
'Rector\\PHPUnit\\PHPUnit100\\NodeFactory\\WillReturnCallbackFactory' => $vendorDir . '/rector/rector-phpunit/rules/PHPUnit100/NodeFactory/WillReturnCallbackFactory.php',
18601860
'Rector\\PHPUnit\\PHPUnit100\\Rector\\Class_\\AddProphecyTraitRector' => $vendorDir . '/rector/rector-phpunit/rules/PHPUnit100/Rector/Class_/AddProphecyTraitRector.php',
1861+
'Rector\\PHPUnit\\PHPUnit100\\Rector\\Class_\\ParentTestClassConstructorRector' => $vendorDir . '/rector/rector-phpunit/rules/PHPUnit100/Rector/Class_/ParentTestClassConstructorRector.php',
18611862
'Rector\\PHPUnit\\PHPUnit100\\Rector\\Class_\\PublicDataProviderClassMethodRector' => $vendorDir . '/rector/rector-phpunit/rules/PHPUnit100/Rector/Class_/PublicDataProviderClassMethodRector.php',
18621863
'Rector\\PHPUnit\\PHPUnit100\\Rector\\Class_\\RemoveNamedArgsInDataProviderRector' => $vendorDir . '/rector/rector-phpunit/rules/PHPUnit100/Rector/Class_/RemoveNamedArgsInDataProviderRector.php',
18631864
'Rector\\PHPUnit\\PHPUnit100\\Rector\\Class_\\StaticDataProviderClassMethodRector' => $vendorDir . '/rector/rector-phpunit/rules/PHPUnit100/Rector/Class_/StaticDataProviderClassMethodRector.php',

vendor/composer/autoload_static.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2077,6 +2077,7 @@ class ComposerStaticInit85a5c971754a67e64efb2b2dadc9a1fe
20772077
'Rector\\PHPUnit\\PHPUnit100\\NodeDecorator\\WillReturnIfNodeDecorator' => __DIR__ . '/..' . '/rector/rector-phpunit/rules/PHPUnit100/NodeDecorator/WillReturnIfNodeDecorator.php',
20782078
'Rector\\PHPUnit\\PHPUnit100\\NodeFactory\\WillReturnCallbackFactory' => __DIR__ . '/..' . '/rector/rector-phpunit/rules/PHPUnit100/NodeFactory/WillReturnCallbackFactory.php',
20792079
'Rector\\PHPUnit\\PHPUnit100\\Rector\\Class_\\AddProphecyTraitRector' => __DIR__ . '/..' . '/rector/rector-phpunit/rules/PHPUnit100/Rector/Class_/AddProphecyTraitRector.php',
2080+
'Rector\\PHPUnit\\PHPUnit100\\Rector\\Class_\\ParentTestClassConstructorRector' => __DIR__ . '/..' . '/rector/rector-phpunit/rules/PHPUnit100/Rector/Class_/ParentTestClassConstructorRector.php',
20802081
'Rector\\PHPUnit\\PHPUnit100\\Rector\\Class_\\PublicDataProviderClassMethodRector' => __DIR__ . '/..' . '/rector/rector-phpunit/rules/PHPUnit100/Rector/Class_/PublicDataProviderClassMethodRector.php',
20812082
'Rector\\PHPUnit\\PHPUnit100\\Rector\\Class_\\RemoveNamedArgsInDataProviderRector' => __DIR__ . '/..' . '/rector/rector-phpunit/rules/PHPUnit100/Rector/Class_/RemoveNamedArgsInDataProviderRector.php',
20822083
'Rector\\PHPUnit\\PHPUnit100\\Rector\\Class_\\StaticDataProviderClassMethodRector' => __DIR__ . '/..' . '/rector/rector-phpunit/rules/PHPUnit100/Rector/Class_/StaticDataProviderClassMethodRector.php',

vendor/composer/installed.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1804,12 +1804,12 @@
18041804
"source": {
18051805
"type": "git",
18061806
"url": "https:\/\/github.com\/rectorphp\/rector-phpunit.git",
1807-
"reference": "27f53d05bc0d308c0d9079417f59d68374765e8d"
1807+
"reference": "48203503078e4224c91eba3ba038a575c9c25586"
18081808
},
18091809
"dist": {
18101810
"type": "zip",
1811-
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-phpunit\/zipball\/27f53d05bc0d308c0d9079417f59d68374765e8d",
1812-
"reference": "27f53d05bc0d308c0d9079417f59d68374765e8d",
1811+
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-phpunit\/zipball\/48203503078e4224c91eba3ba038a575c9c25586",
1812+
"reference": "48203503078e4224c91eba3ba038a575c9c25586",
18131813
"shasum": ""
18141814
},
18151815
"require": {
@@ -1833,7 +1833,7 @@
18331833
"tomasvotruba\/class-leak": "^1.2",
18341834
"tracy\/tracy": "^2.10"
18351835
},
1836-
"time": "2025-05-02T22:30:02+00:00",
1836+
"time": "2025-05-05T17:05:33+00:00",
18371837
"default-branch": true,
18381838
"type": "rector-extension",
18391839
"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 826f808'), '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 2b141c8'), '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 27f53d0'), '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 37d320e'));
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 826f808'), '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 2b141c8'), '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 4820350'), '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 37d320e'));
1313
private function __construct()
1414
{
1515
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
use Rector\Config\RectorConfig;
77
use Rector\PHPUnit\PHPUnit100\Rector\Class_\AddProphecyTraitRector;
8+
use Rector\PHPUnit\PHPUnit100\Rector\Class_\ParentTestClassConstructorRector;
89
use Rector\PHPUnit\PHPUnit100\Rector\Class_\PublicDataProviderClassMethodRector;
910
use Rector\PHPUnit\PHPUnit100\Rector\Class_\StaticDataProviderClassMethodRector;
1011
use Rector\PHPUnit\PHPUnit100\Rector\MethodCall\PropertyExistsWithoutAssertRector;
@@ -15,7 +16,7 @@
1516
use Rector\Renaming\ValueObject\MethodCallRename;
1617
return static function (RectorConfig $rectorConfig) : void {
1718
$rectorConfig->sets([PHPUnitSetList::ANNOTATIONS_TO_ATTRIBUTES]);
18-
$rectorConfig->rules([StaticDataProviderClassMethodRector::class, PublicDataProviderClassMethodRector::class, AddProphecyTraitRector::class, WithConsecutiveRector::class, RemoveSetMethodsMethodCallRector::class, PropertyExistsWithoutAssertRector::class]);
19+
$rectorConfig->rules([StaticDataProviderClassMethodRector::class, PublicDataProviderClassMethodRector::class, AddProphecyTraitRector::class, WithConsecutiveRector::class, RemoveSetMethodsMethodCallRector::class, PropertyExistsWithoutAssertRector::class, ParentTestClassConstructorRector::class]);
1920
$rectorConfig->ruleWithConfiguration(RenameMethodRector::class, [
2021
// https://github.com/sebastianbergmann/phpunit/issues/4087
2122
new MethodCallRename('PHPUnit\\Framework\\Assert', 'assertRegExp', 'assertMatchesRegularExpression'),
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
<?php
2+
3+
declare (strict_types=1);
4+
namespace Rector\PHPUnit\PHPUnit100\Rector\Class_;
5+
6+
use PhpParser\Modifiers;
7+
use PhpParser\Node;
8+
use PhpParser\Node\Arg;
9+
use PhpParser\Node\Expr\ClassConstFetch;
10+
use PhpParser\Node\Expr\StaticCall;
11+
use PhpParser\Node\Name;
12+
use PhpParser\Node\Stmt\Class_;
13+
use PhpParser\Node\Stmt\ClassMethod;
14+
use PhpParser\Node\Stmt\Expression;
15+
use Rector\PHPUnit\NodeAnalyzer\TestsNodeAnalyzer;
16+
use Rector\Rector\AbstractRector;
17+
use Rector\ValueObject\MethodName;
18+
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
19+
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
20+
/**
21+
* @see https://github.com/sebastianbergmann/phpunit/issues/3975
22+
* @see https://github.com/sebastianbergmann/phpunit/commit/705874f1b867fd99865e43cb5eaea4e6d141582f
23+
*
24+
* @see \Rector\PHPUnit\Tests\PHPUnit100\Rector\Class_\ParentTestClassConstructorRector\ParentTestClassConstructorRectorTest
25+
*/
26+
final class ParentTestClassConstructorRector extends AbstractRector
27+
{
28+
/**
29+
* @readonly
30+
*/
31+
private TestsNodeAnalyzer $testsNodeAnalyzer;
32+
public function __construct(TestsNodeAnalyzer $testsNodeAnalyzer)
33+
{
34+
$this->testsNodeAnalyzer = $testsNodeAnalyzer;
35+
}
36+
public function getRuleDefinition() : RuleDefinition
37+
{
38+
return new RuleDefinition('PHPUnit\\Framework\\TestCase requires a parent constructor call', [new CodeSample(<<<'CODE_SAMPLE'
39+
use PHPUnit\Framework\TestCase;
40+
41+
final class SomeHelper extends TestCase
42+
{
43+
}
44+
CODE_SAMPLE
45+
, <<<'CODE_SAMPLE'
46+
use PHPUnit\Framework\TestCase;
47+
48+
final class SomeHelper extends TestCase
49+
{
50+
public function __construct()
51+
{
52+
parent::__construct(static::class);
53+
}
54+
}
55+
CODE_SAMPLE
56+
)]);
57+
}
58+
/**
59+
* @return array<class-string<Node>>
60+
*/
61+
public function getNodeTypes() : array
62+
{
63+
return [Class_::class];
64+
}
65+
/**
66+
* @param Class_ $node
67+
*/
68+
public function refactor(Node $node) : ?Node
69+
{
70+
if (!$this->testsNodeAnalyzer->isInTestClass($node)) {
71+
return null;
72+
}
73+
if ($this->shouldSkipClass($node)) {
74+
return null;
75+
}
76+
// it already has a constructor, skip as it might require specific tweaking
77+
if ($node->getMethod(MethodName::CONSTRUCT)) {
78+
return null;
79+
}
80+
$constructorClassMethod = new ClassMethod(MethodName::CONSTRUCT);
81+
$constructorClassMethod->flags |= Modifiers::PUBLIC;
82+
$constructorClassMethod->stmts[] = new Expression($this->createParentConstructorCall());
83+
$node->stmts = \array_merge([$constructorClassMethod], $node->stmts);
84+
return $node;
85+
}
86+
private function createParentConstructorCall() : StaticCall
87+
{
88+
$staticClassConstFetch = new ClassConstFetch(new Name('static'), 'class');
89+
return new StaticCall(new Name('parent'), MethodName::CONSTRUCT, [new Arg($staticClassConstFetch)]);
90+
}
91+
private function shouldSkipClass(Class_ $class) : bool
92+
{
93+
if ($class->isAbstract()) {
94+
return \true;
95+
}
96+
if ($class->isAnonymous()) {
97+
return \true;
98+
}
99+
$className = $this->getName($class);
100+
// loaded automatically by PHPUnit
101+
if (\substr_compare((string) $className, 'Test', -\strlen('Test')) === 0) {
102+
return \true;
103+
}
104+
return \substr_compare((string) $className, 'TestCase', -\strlen('TestCase')) === 0;
105+
}
106+
}

0 commit comments

Comments
 (0)