Skip to content

AssertCompareToSpecificMethodRector shouldn't flip Assert* parameters #8942

@VincentLanglet

Description

@VincentLanglet

Bug Report

Subject Details
Rector version last dev-main
Installed as composer dependency

Minimal PHP Code Causing Issue

See https://getrector.com/demo/1565705e-66cb-46eb-a365-4b25236fa3c5

<?php

use PHPUnit\Framework\TestCase;

final class MyTest extends TestCase
{
    public function testSomeFoo()
    {   
        $ids = ['foo', 'bar'];
        $result = myMethod($ids);
        
        self::assertSame(count($ids), $result);
    }
}

Responsible rules

  • AssertCompareToSpecificMethodRector

Expected Behavior

In this example self::assertSame(count($ids), $result); is changed to self::assertCount($result, $ids);,
but this give an inverted error message when the assertion is wrong.

It basically do the opposite of what FlipAssertRector users wants.

So I think such replacement shouldn't be done, or split in another rule to allow using "safe" replacement like

self::assertSame($expected, count($result));

to

self::assertCount($expected, $result);

which respect the order of the messages.

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