Call to undefined method PhpParser\Comment\Doc::getStartLine()

Hello!

Little heads-up for app developers using phpunit 9.x. If you test against the app not just against Nextcloud server (or 21.0.x) but Nextcloud 20 and possibly older, you’ll very likely see phpunit stopping very early and printing

Call to undefined method PhpParser\Comment\Doc::getStartLine()

This has to do with the nikic/php-parser package which the phpunit/* and sebastian/* packages depend on. The parser required by those packages has the method Doc::getStartLine() as of version 4.10. Unfortunately in Nextcloud server’s 3rdparty vendor directory there is the same dependnecy but in an older version 4.3. That version doesn’t have Doc::getStartLine() yet, hence the error.

To work around this issue I found it useful to just update the nikic/parser package in the 3rdparty directory in Github action

    - name: Fix php-parser on stable20 incompatibility with phpunit 9.3+
      if: ${{ matrix.nextcloud-versions == 'stable20' }}
      working-directory: nextcloud/3rdparty
      run: composer require nikic/php-parser:4.10

It’s ugly, but does the job. The parser update shouldn’t have any influence on the app unit tests because that parser is only used by Nextcloud when running its own CI tests.

Hope this helps someone.

Cheers