Bug Report
| Subject |
Details |
| Rector version |
2.4.2 |
| PHP version |
8.5.2 |
$someObject->isType() inside a subclass of PHPUnit\Framework\TestCase crashes the AssertIsTypeMethodCallRector when an enum case is passed in.
Error:
[ERROR] Could not process
"thefile.php" file, due to:
"System error: "Cannot access offset of type App\Enums\SomeEnum in isset or empty"
Run Rector with "--debug" option and post the report here: https://github.com/rectorphp/rector/issues/new". On line: 92
Minimal PHP Code Causing Issue
The violating file:
<?php
namespace Tests;
use App\Enums\SomeEnum;
use PHPUnit\Framework\TestCase;
use stdClass;
final class MyTest extends TestCase
{
public function test_ing(): void
{
(new stdClass)->isType(SomeEnum::ONE);
}
}
With enum:
<?php
namespace App\Enums;
enum SomeEnum: string
{
case ONE = 'one';
}
Rector.php:
<?php
use Rector\Config\RectorConfig;
use Rector\TypeDeclaration\Rector\Property\TypedPropertyFromAssignsRector;
return RectorConfig::configure()
->withRules([
\Rector\PHPUnit\PHPUnit120\Rector\Class_\AssertIsTypeMethodCallRector::class
]);
https://getrector.com/demo/ can't reproduce it since:
- The Enum should be in another namespace in another file (not sure why it doesn't crash when the enum is in the same file)
- The demo can't check if a class is a phpunit testcase
Expected Behaviour
Rector shouldn't crash and shouldn't have anything to do with this specific case since the isType method is not called on $this.
Bug Report
$someObject->isType()inside a subclass ofPHPUnit\Framework\TestCasecrashes theAssertIsTypeMethodCallRectorwhen an enum case is passed in.Error:
Minimal PHP Code Causing Issue
The violating file:
With enum:
Rector.php:
Expected Behaviour
Rector shouldn't crash and shouldn't have anything to do with this specific case since the
isTypemethod is not called on$this.