Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code Coverage uses PHPUnit but does not include in composer.json #820

Closed
thekid opened this issue Oct 4, 2020 · 4 comments
Closed

Code Coverage uses PHPUnit but does not include in composer.json #820

thekid opened this issue Oct 4, 2020 · 4 comments

Comments

@thekid
Copy link

thekid commented Oct 4, 2020

Q A
php-code-coverage version 9.2.0
PHP version 7.4.9
Driver Xdebug
Xdebug version (if used) 2.9.4
Installation Method Composer
Usage Method Standalone
PHPUnit version (if used) (none)

When generating a HTML report using phpunit/php-code-coverage standalone, a fatal error occurs here:

Error(0, (0x2f)'Class 'PHPUnit\Runner\BaseTestRunner' not found') [line 995 of File.php]

This is due to the fact that the switch statement uses PHPUnit\Runner\BaseTestRunner class constants but does not include a runtime dependency on phpunit/phpunit.

dvdoug added a commit to dvdoug/php-code-coverage that referenced this issue Oct 9, 2020
dvdoug added a commit to dvdoug/php-code-coverage that referenced this issue Oct 9, 2020
@thekid
Copy link
Author

thekid commented Oct 27, 2020

Anything I can do to get this fixed? As far as I see there's even a pull request waiting to be merged.

@sebastianbergmann
Copy link
Owner

I just need time to review #822.

@sebastianbergmann
Copy link
Owner

Anything I can do to get this fixed?

What would make things a bit easier for me would be feedback on whether #822 solves your problem. Thanks!

@thekid
Copy link
Author

thekid commented Oct 31, 2020

What would make things a bit easier for me would be feedback on whether #822 solves your problem. Thanks!

✅ It does!

First, I removed my workaround:

diff --git a/src/main/php/unittest/coverage/impl/Coverage9.class.php ...
index d8861cd..989f450 100755
--- a/src/main/php/unittest/coverage/impl/Coverage9.class.php
+++ b/src/main/php/unittest/coverage/impl/Coverage9.class.php
@@ -7,25 +7,6 @@ use SebastianBergmann\CodeCoverage\Driver\Selector;
 /** Coverage implementation for php-code-coverage >= 9.0 */
 class Coverage9 extends Implementation {

-  /** @codeCoverageIgnore */
-  static function __static() {
-
-    // Workaround for fatal error in php-code-coverage when PHPUnit is not loaded
-    // See https://github.com/sebastianbergmann/php-code-coverage/issues/820
-    if (!class_exists(BaseTestRunner::class)) {
-      eval('namespace PHPUnit\Runner; class BaseTestRunner {
-        const STATUS_UNKNOWN    = -1;
-        const STATUS_PASSED     = 0;
-        const STATUS_SKIPPED    = 1;
-        const STATUS_INCOMPLETE = 2;
-        const STATUS_FAILURE    = 3;
-        const STATUS_ERROR      = 4;
-        const STATUS_RISKY      = 5;
-        const STATUS_WARNING    = 6;
-      }');
-    }
-  }
-

...and created a coverage report, reproducing the error:

$ XP_RT=7.4x xp coverage -p src/main/php/ -r coverage-report/ src/test/php/
[............................Exception lang.Error (Class 'PHPUnit\Runner\BaseTestRunner' not found)
  at <native>::Error(0, (0x2f)'Class 'PHPUnit\Runner\BaseTestRunner' not found') [line 994 of File.php]
# ...

Next, I upgraded phpunit/php-code-coverage to ^9.2.2, which includes the fix:

$ composer up
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 0 installs, 1 update, 0 removals
  - Updating phpunit/php-code-coverage (9.2.1 => 9.2.3): Loading from cache
Writing lock file
Generating autoload files
4 packages you are using are looking for funding.
Use the `composer fund` command to find out more!

...and re-ran the above command, correctly producing the report.

Thanks!

thekid added a commit to xp-forge/coverage that referenced this issue Oct 31, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants