[PHPUnit] AddInstanceofAssertForNullableInstanceRector enters an infinite loop on a test trait
Ya se ha fusionado un pull request relacionado.
- #818 de @samsonasik — fusionado
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 1-2 días
- Aptitud para principiantes
- 25/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Estancado
- Stack tecnológico
- php
- Área
- testing-qa
Línea de trabajo
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.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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.
- Lenguaje dominante
- PHP
- Estrellas
- 10.5k
- Forks
- 742
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Sin plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de rectorphp/rector
-
bug
Dificultad 4/5 3-5 días Aptitud para principiantes 48/100
-
MyCLabsMethodCallToEnumConstRector should only refactor according to RuleDefinitionPosiblemente ocupada @samsonasik la tomó hace 2 días. Abiertobug
Dificultad 3/5 Medio día Aptitud para principiantes 55/100
-
Dificultad 3/5 1-2 días Aptitud para principiantes 52/100
Todos los issues de rectorphp/rector
Issues similares
-
Author mapping step: "create new user" and "assign to existing user" fields have no spacing between themPosiblemente ocupada @umeshnevase la tomó hoy. Abierto
Dificultad 1/5 1-3 horas Aptitud para principiantes 78/100
WordPress/wordpress-importer#275 ·
-
security/openvpn-legacy: read-only user can stop a running VPNPosiblemente ocupada @besendorf la tomó hoy. Abiertoincomplete
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
opnsense/plugins#5887 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
jira-created
Dificultad 2/5 1-3 horas Aptitud para principiantes 77/100
-
No Code Attached Yet
Dificultad 1/5 Menos de una hora Aptitud para principiantes 90/100
joomla/joomla-cms#48786 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
Icinga/icingaweb2-module-director#3188 ·
Los mantenedores suelen responder en 4 días