[PHPUnit] AddInstanceofAssertForNullableInstanceRector enters an infinite loop on a test trait
已经有一个关联 PR 被合并了。
- #818 来自 @samsonasik —— 已合并
评估
- 难度
- 4/5
- 预计耗时
- 1-2 天
- 新手友好度
- 25/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 停滞
- 技术栈
- php
- 领域
- testing-qa
调研方向
Start with the AddInstanceofAssertForNullableInstanceRector class under the PHPUnit CodeQuality ClassMethod rules, and check how it handles methods inside a trait. Reproduce with the input.php and rector.php from the report, using a timeout so the loop cannot run forever. Done means one assertInstanceOf() is added, a second pass makes no change, and the run terminates. Check the linked open pull request first, since it may already cover this.
由索引模型根据 Issue 内容生成。
描述
Bug Report
| Subject | Details |
|---|---|
| Rector version | 2.8.3, confirmed with vendor/bin/rector --version |
| PHP version | 8.4.27 |
AddInstanceofAssertForNullableInstanceRector repeatedly inserts the same assertInstanceOf() call when processing a public test method in a trait. This happens within a single Rector invocation, not just across subsequent CLI runs. Rector never reaches a stable result.
I reproduced this with a fresh installation of rector/rector:2.8.3 and only this rule enabled. The input uses PHP's built-in Throwable interface and contains no project-specific code.
Minimal PHP Code Causing Issue
input.php:
<?php
trait T
{
function test(Throwable $e)
{
$p = $e->getPrevious();
$p->getMessage();
}
}
rector.php:
<?php
use Rector\Config\RectorConfig;
use Rector\PHPUnit\CodeQuality\Rector\ClassMethod\AddInstanceofAssertForNullableInstanceRector;
use Rector\ValueObject\PhpVersion;
return RectorConfig::configure()
->withRules([
AddInstanceofAssertForNullableInstanceRector::class,
]);
Run with a hard deadline to avoid leaving the process running indefinitely:
vendor/bin/rector --version
# Rector 2.8.3
timeout -s KILL 10 vendor/bin/rector process input.php \
--config=rector.php \
--dry-run --debug --no-progress-bar --clear-cache
The uninstrumented run did not finish before the deadline and was killed with exit code 137.
Expected Behaviour
Rector should add a single assertion before $p->getMessage() and terminate:
$p = $e->getPrevious();
$this->assertInstanceOf(\Throwable::class, $p);
$p->getMessage();
The transformation should be idempotent: processing the transformed code again should not insert another identical assertion.
- 主要语言
- PHP
- 星标
- 10.5k
- 派生
- 742
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
rectorphp/rector 的其他 Issue
-
bug
难度 4/5 3-5 天 新手友好度 48/100
-
MyCLabsMethodCallToEnumConstRector should only refactor according to RuleDefinition可能已有人在做 @samsonasik 于 2 天前认领。 未关闭bug
难度 3/5 半天 新手友好度 55/100
-
难度 3/5 1-2 天 新手友好度 52/100
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 72/100
YunoHost-Apps/snappymail_ynh#205 ·
-
难度 2/5 1-3 小时 新手友好度 83/100
ExpressionEngine/ExpressionEngine#5453 ·
维护者通常 1 天内回复
-
✨️ai-candidate effort: [XS] Made by AI module: user interface type: bug
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复
-
0. Needs triage bug
难度 2/5 1-3 小时 新手友好度 65/100
维护者通常 1 天内回复
-
Type: Enhancement Type: Support
难度 1/5 1 小时以内 新手友好度 88/100
google/site-kit-wp#14096 ·
维护者通常 2 天内回复