rectorphp / rector-phpunit

Rector upgrade rules for PHPUnit
https://getrector.com/find-rule?activeRectorSetGroup=phpunit
MIT License
68 stars 47 forks source link

`AssertTrueFalseToSpecificMethodRector` class incorrectly assumes `class-string` is an `object` #198

Closed ghostwriter closed 1 year ago

ghostwriter commented 1 year ago

Bug Report

Subject Details
Rector version ^0.17.1
Installed as composer

Minimal PHP Code Causing Issue

See https://getrector.com/demo/3be3c0d9-dbea-4e1d-8c59-ea7fa84c4440

<?php

use PHPUnit\Framework\TestCase;

final class DemoFileTest extends TestCase
{
    /**
     * @var class-string<ExceptionInterface::class> $exception
     * @dataProvider exceptionsDataProvider
     **/
    public function testExceptionIsInstanceOfExceptionInterface(string $exception): void
    {
        self::assertTrue(is_a($exception, ExceptionInterface::class, true));
    }

    public static function exceptionsDataProvider(): iterable
    {
        yield from [
            ExceptionInterface::class => [ExceptionInterface::class]
        ];
    }
}

interface ExceptionInterface {
}

Responsible rules

Expected Behavior

to remain unchanged.

TomasVotruba commented 1 year ago

Thank you for your report!

We'll need an isolated failing demo link from: http://getrector.org/demo, that way we can reproduce the bug.

ghostwriter commented 1 year ago

@TomasVotruba thanks for looking into this.

Here is the isolated failing demo link you requested. https://getrector.com/demo/3be3c0d9-dbea-4e1d-8c59-ea7fa84c4440

samsonasik commented 1 year ago

@ghostwriter you can click "Create a Test" button next to create fixture file for failing test case, would be better if you can provide a patch as well ;)

ghostwriter commented 1 year ago

Sure, I'll send a PR with a fix.