rectorphp / rector-phpunit

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

[PHPUnit 10] abstract *Test rename to *TestCase: some use/extends statements not updated with new *TestCase class name #162

Closed arderyp closed 1 year ago

arderyp commented 1 year ago

I'm using Rector\PHPUnit\Set\PHPUnitSetList::PHPUNIT_100

Here is the basic hierarchy before the rector run:

namespace App\Test;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
abstract class AbstractWebTest extends WebTestCase

namespace App\Test\Controller;
use App\Test\AbstractWebTest;
abstract class AbstractControllerTest extends AbstractWebTest

namespace App\Test\Controller;
class ExampleControllerTest extends AbstractControllerTest

AbstractWebTest

BEFORE

namespace App\Test;

use App\A;
use App\B;
use App\C;
use App\D;
use DateTime;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;

abstract class AbstractWebTest extends WebTestCase
{
    ...
}

AFTER

namespace App\Test;

use DateTime;

# why FQCN below instead of use statement?
abstract class AbstractWebTestCase extends \Symfony\Bundle\FrameworkBundle\Test\WebTestCase
{
    # why are these down here?
    # why a leading slash?
    # what happened to the App\C and App\D imports, which are now direct FQCN references in the code below?
    use \App\A;
    use \App\B;
}

AbstractControllerTest

BEFORE

namespace App\Test\Controller;

use App\Test\AbstractWebTest;

abstract class AbstractControllerTest extends AbstractWebTest

AFTER

namespace App\Test\Controller;

# while the class name suffix was updated from Test to TestCase, the AbstractWebTest was not updated to AbstractWebTestCase
abstract class AbstractControllerTestCase extends \Coe\Cee\Tests\Common\AbstractWebTest

ExampleControllerTest

This class was completely untouched by rector, when its extends clause should have been changed to reflect the new name of the child abstract (AbstractControllerTest --> AbstractControllerTestCase)

class ExampleControllerTest extends AbstractControllerTestCase
arderyp commented 1 year ago

additionally, phpstan annotations in the class docblock aren't updated to reflect new parent abstract (when using generics, for example)

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.

arderyp commented 1 year ago

cool, I will try to reproduce it there when I get a chance. It may be rather complicated, because some children were affected, and others were not. I still havent figured out the pattern.

TomasVotruba commented 1 year ago

Hi, after few usages of this rule, we've decided to remove it, as it does not work reliable because we cannot get the whole project context.

Better handle these manually in safer way :+1: