pestphp / drift

[WIP] Command-line tool to migrate your PHPUnit tests to Pest
https://pestphp.com/docs/guides/drift
MIT License
28 stars 7 forks source link

Add support for String Interpolation when migrating helper methods #20

Closed olivernybroe closed 4 years ago

olivernybroe commented 4 years ago

Right now we have a test which fails because we are trying to migrate a class method to a pest helper method.

However the original class method was used in string interpolation which is not supported by functions, so the string interpolation has to be split up, so it can use the pest helper.

Example: We have the following php class

class MethodStringInterpolationTest extends TestCase
{
    private function alwaysTrueHelper()
    {
        return "true";
    }

    public function testMethod()
    {
        "{$this->alwaysTrueHelper()} works";
    }
}

Which should be converted to

function alwaysTrueHelper()
{
    return "true";
}
test('testMethod', function () {
    alwaysTrueHelper() . " works";
});

Because doing "{alwaysTrueHelper()} works"; is not valid php code.

Fixture file: https://github.com/pestphp/drift/blob/master/tests/fixtures/PHPUnit/ClassMethod/HelperMethodRector/phpunit_method_to_pest_helper_used_in_string_interpolation.php.inc

olivernybroe commented 4 years ago

Hey @TomasVotruba, you told me a while ago to tag you with a failing test case for string interpolation conversion 👍

Any pointers on how to solve this would be really nice, we have a failing test in our testsuite right now for this.

TomasVotruba commented 4 years ago

Hi, could you link me to the Rector rule + failing line in CI?

olivernybroe commented 4 years ago

Sure.

TomasVotruba commented 4 years ago

Thank you. I've used all the links :)