Php-cs-fixer: PhpUnitTestCaseStaticMethodCallsFixer - produces syntax error

Created on 14 Feb 2019  路  3Comments  路  Source: FriendsOfPHP/PHP-CS-Fixer

The PHP version you are using ($ php -v):

7.2.15

PHP CS Fixer version you are using ($ php-cs-fixer -V):

2.14.1

The command you use to run PHP CS Fixer:

php-cs-fixer fix --dry-run src/ -vvv

The configuration file you are using, if any:

https://github.com/msgphp/msgphp/blob/master/.php_cs.dist

Files that were not fixed due to errors reported during linting after fixing:
   1) /app/src/Eav/Tests/Entity/Fields/AttributeFieldTest.php


        [PhpCsFixer\Linter\LintingException]                       
        PHP Parse error: syntax error, unexpected '=' on line 38.  


      Applied fixers: php_unit_test_case_static_method_calls

See https://travis-ci.org/msgphp/msgphp/jobs/492145928#L198 for error during build.

I thought it was related to #4285, and as such fixed by #4286. But it seems this is not the case :(

kinbug

Most helpful comment

: D
I had this issue open for so long, I never saw the PR reference since I didn't reload the page :man_facepalming:

All 3 comments

Hi and thanks for reporting.

After checking I think the issues are with the PhpUnitTestCaseStaticMethodCallsFixer.
I see the fixer:

  • touching not-method calls ($this->attribute = 1;)
  • touching method calls within an anonymous class inside a PHHUnit class

Seen on both 2.12 and 2.14

minimal sample:

<?php

final class MyTest extends TestCase
{

    private function foo()
    {
        $this->attribute = 1;

        return new class {
            public function __construct()
            {
                $this->attribute = 1;
            }
        };
    }
}

@SpacePossum take a look at PR mentioned above ;)

: D
I had this issue open for so long, I never saw the PR reference since I didn't reload the page :man_facepalming:

Was this page helpful?
0 / 5 - 0 ratings