Skip to content

Incorrect behavior of WithCallbackIdenticalToStandaloneAssertsRector with static anonymous function #9754

@LorisZ

Description

@LorisZ

Bug Report

Subject Details
Rector version 2.4.2
Installed as composer dependency

Minimal PHP Code Causing Issue

See https://getrector.com/demo/d8eb040a-bade-476f-80db-31a111b7720c

<?php

use PHPUnit\Framework\TestCase;

final class SomeTest extends TestCase
{
    public function test()
    {
        $this->createMock('SomeClass')
            ->expects($this->once())
            ->method('someMethod')
            ->with($this->callback(static function (array $args): bool {
               return count($args) === 2 && $args[0] === 'correct';
            }));
    }
}

Responsible rules

  • WithCallbackIdenticalToStandaloneAssertsRector

Expected Behavior

If the anonymouse function is static, it should also remove the static keyword, as otherwise the changed code containing the $this variable will break.

Just a minor thing. I think removing the static keyword should always be fine in this case, but maybe some deeper analysis is needed? Otherwise the rule should maybe ignore static functions.

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