Skip to content

PreferPHPUnitSelfCallRector, PreferPHPUnitThisCallRector missing some static methods #9198

@philiprabbett

Description

@philiprabbett

Bug Report

Subject Details
Rector version 2.0.16

Upgrading to PHPUnit v12, I expected rector to handle conversion of some method calls from self / static to $this but not all conversions occurred. See Related MR

Minimal PHP Code Causing Issue

https://getrector.com/demo/b92dacdc-c967-4b3f-b53f-1daef8f6f772

<?php

use PHPUnit\Framework\TestCase;

final class SomeTest extends TestCase
{
    public function test()
    {
        self::any();
        self::never();
        self::atLeast();
        self::atLeastOnce();
        self::once();
        self::exactly();
        self::atMost();
        self::throwException();
        self::getActualOutputForAssertion();
        self::expectOutputRegex();
        self::expectOutputString();
        self::expectException();
        self::expectExceptionCode();
        self::expectExceptionMessage();
        self::expectExceptionMessageMatches();
        self::expectExceptionObject();
        self::expectNotToPerformAssertions();
        self::getMockBuilder();
    }
}
<?php

use Rector\Config\RectorConfig;
use Rector\PHPUnit\CodeQuality\Rector\Class_\PreferPHPUnitSelfCallRector;
use Rector\PHPUnit\CodeQuality\Rector\Class_\PreferPHPUnitThisCallRector;

return RectorConfig::configure()
    ->withRules([
        PreferPHPUnitThisCallRector::class,
        PreferPHPUnitSelfCallRector::class,
    ]);

Expected Behaviour

    public function test()
    {
-        self::any();
-        self::never();
-        self::atLeast();
-        self::atLeastOnce();
-        self::once();
-        self::exactly();
-        self::atMost();
-        self::throwException();
-        self::getActualOutputForAssertion();
-        self::expectOutputRegex();
-        self::expectOutputString();
-        self::expectException();
-        self::expectExceptionCode();
-        self::expectExceptionMessage();
-        self::expectExceptionMessageMatches();
-        self::expectExceptionObject();
-        self::expectNotToPerformAssertions();
-        self::getMockBuilder();
+        $this->any();
+        $this->never();
+        $this->atLeast();
+        $this->atLeastOnce();
+        $this->once();
+        $this->exactly();
+        $this->atMost();
+        $this->throwException();
+        $this->getActualOutputForAssertion();
+        $this->expectOutputRegex();
+        $this->expectOutputString();
+        $this->expectException();
+        $this->expectExceptionCode();
+        $this->expectExceptionMessage();
+        $this->expectExceptionMessageMatches();
+        $this->expectExceptionObject();
+        $this->expectNotToPerformAssertions();
+        $this->getMockBuilder();
    }

Actual Behaviour

    public function test()
    {
        self::any();
-        self::never();
-        self::atLeast();
-        self::atLeastOnce();
-        self::once();
+        $this->never();
+        $this->atLeast();
+        $this->atLeastOnce();
+        $this->once();
        self::exactly();
        self::atMost();
        self::throwException();
        self::getActualOutputForAssertion();
        self::expectOutputRegex();
        self::expectOutputString();
-        self::expectException();
-        self::expectExceptionCode();
-        self::expectExceptionMessage();
-        self::expectExceptionMessageMatches();
+        $this->expectException();
+        $this->expectExceptionCode();
+        $this->expectExceptionMessage();
+        $this->expectExceptionMessageMatches();
        self::expectExceptionObject();
        self::expectNotToPerformAssertions();
        self::getMockBuilder();
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions