kenjis/ci-phpunit-test

'Replacement data still remain' logic error cause

pgee70 opened this issue · 6 comments

This isn't really a bug report, just an error report, more to help others.

when installing via composer your library kenjis/ci-phpunit-test:2.x-dev
this installed the most recent version of nikic/php-parser V4.7.0

when php-parser v4.7 tokenises a file, this version has a post-processing step. This step changes the offsets of the nodes, so that functions that have to be substituted out (from the white-list + overloads) are out of sync with the nodes from token_get_all().
so when your code gets around to using static::$replacement in abstract class AbstractPatcher, the nodes have the wrong index.
This in turn causes the function to not be found in FunctionPatcher::generateNewSource, generating a throw new LogicException('Replacement data still remain');

While the cause took me many hours to locate, the fix is simple, explicitly use the recommended version of php-parser, so my composer.json becomes:

 "require-dev": {
    "phpunit/phpunit": "8.4.3",
    "kenjis/ci-phpunit-test": "2.x-dev",
    "nikic/php-parser": "4.2.5"
  }

then just update composer and the problem was fixed!

@pgee70 Thank you for reporting!

I didn't know why Travis tests fail recently.

I fixed the version for now. #347

Because of #347, we can't install PHPUnit 9.3.

I'm trying to fix this problem, but it is still in the way.
See #364
See #365

Fixed #366

Fixed in v0.19.0.