PHPUnit causes undefined method error when --coverage-text (using pcov)

436 Views Asked by At

I'm trying to get coverage with pcov & PHPUnit for my Laravel project on docker.

I get an error PHP Fatal error: Uncaught Error: Call to undefined method Illuminate\Container\Container::basePath() when I add --coverage-text. No error occurs without --coverage-text.

What should I do to fix this?

  • Case with --coverage-text
# php -d pcov.enabled=1 ./vendor/bin/phpunit --coverage-text tests/Unit/path/to/my/file
PHPUnit 8.5.9 by Sebastian Bergmann and contributors.

PHP Fatal error:  Uncaught Error: Call to undefined method Illuminate\Container\Container::basePath() in /var/www/html/laravel/vendor/laravel/framework/src/Illuminate/Foundation/helpers.php:192
Stack trace:
#0 /var/www/html/laravel/app/Some/MyClass.php(5): base_path('vendor/autoload...')
#1 /var/www/html/laravel/vendor/phpunit/php-code-coverage/src/CodeCoverage.php(955): include_once('/var/www/html/...')
#2 /var/www/html/laravel/vendor/phpunit/php-code-coverage/src/CodeCoverage.php(239): SebastianBergmann\CodeCoverage\CodeCoverage->initializeData()
#3 /var/www/html/laravel/vendor/phpunit/phpunit/src/Framework/TestResult.php(646): SebastianBergmann\CodeCoverage\CodeCoverage->start(Object(Tests\Unit\Path\To\My\File))
#4 /var/www/html/laravel/vendor/phpunit/phpunit/src/Framework/TestCase.php(763): PHPUnit\Framework\TestResult->run(Object(Tests\Unit\Path\To\My\File))
#5 /var/www/html/laravel/vendor/php in /var/www/html/laravel/vendor/laravel/framework/src/Illuminate/Foundation/helpers.php on line 192
  • Case without --coverage-text
# php -d pcov.enabled=1 ./vendor/bin/phpunit tests/Unit/path/to/my/file
PHPUnit 8.5.9 by Sebastian Bergmann and contributors.

...........                                                       11 / 11 (100%)

Time: 45.6 seconds, Memory: 64.50 MB

OK (11 tests, 291 assertions)

Versions:

  • PHP: 7.4.29
  • Laravel: 6.20.3
  • pcov: 1.0.11
  • Xdebug: 3.1.4

I installed pcov with pecl in Dockerfile.

RUN yes | pecl install pcov && docker-php-ext-enable pcov
0

There are 0 best solutions below