[PHPUnit] AddInstanceofAssertForNullableInstanceRector enters an infinite loop on a test trait
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 25/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Ferma
- Stack tecnologico
- php
- Ambito
- testing-qa
Direzione di ricerca
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.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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.
- Lingua principale
- PHP
- Stelle
- 10.5k
- Fork
- 742
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di rectorphp/rector
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
-
RemoveDefaultValueFromAssignedPropertyRector does not work with nested conditional assignmentsApertabug
Difficoltà 4/5 3-5 giorni Idoneità per principianti 40/100
-
bug
Difficoltà 3/5 Mezza giornata Idoneità per principianti 55/100
-
bug
Difficoltà 3/5 1-2 giorni Idoneità per principianti 45/100
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 52/100
Tutte le issue di rectorphp/rector
Issue simili
-
Issue: ready for confirmation Reported on 2.4.9 Triage: Dev.Experience
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
magento/magento2#41773 · 1 commento ·
I maintainer di solito rispondono entro 5 giorni
-
[BUG] Add bounds validation for numberOfContestants in TeamsGroup::apiCreate()Forse già presa @RAJJADHAV10 l’ha presa oggi. Apertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
omegaup/omegaup#10512 · 1 commento ·
I maintainer di solito rispondono entro 5 giorni
-
documentation good first issue
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
sorocharge/sorocharge-php#14 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 66/100
filesender/filesender#2898 ·
I maintainer di solito rispondono entro 1 giorno
-
cleanup
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno