bypass-finals icon indicating copy to clipboard operation
bypass-finals copied to clipboard

PHPUnit 11 incompatibility

Open alebedev80 opened this issue 1 year ago • 2 comments

I have set up PHPUnit 11 and started test:

PHP Fatal error:  Non-readonly class SebastianBergmann\CodeUnit\ClassUnit cannot extend readonly class SebastianBergmann\CodeUnit\CodeUnit in /Users/alm/code/api_client/vendor/sebastian/code-unit/src/ClassUnit.php on line 15

With PHPUnit 10.5.13 everything works fine.

alebedev80 avatar Mar 13 '24 14:03 alebedev80

Isn't it possible that SebastianBergmann\CodeUnit\CodeUnit is loaded before BypassFinals is enabled?

dg avatar Mar 14 '24 16:03 dg

I just used this bootstrap.php:

<?php

use DG\BypassFinals;

require dirname(__DIR__).'/vendor/autoload.php';

BypassFinals::enable();
$cacheDir = dirname(__DIR__).'.phpunit.bypass.cache';
if (!file_exists($cacheDir) && !mkdir($cacheDir, 0777, true) && !is_dir($cacheDir)) {
    throw new \RuntimeException(sprintf('Directory "%s" was not created', $cacheDir));
}
BypassFinals::setCacheDirectory($cacheDir);

alebedev80 avatar Mar 14 '24 17:03 alebedev80

This error occurred because the cache was created with a different bypassReadOnly parameter setting than was used afterwards.

dg avatar May 16 '24 17:05 dg

This still seem to be an issue with PHPUnit 11 (11.2.5). Even if you use the Extension class recommended in the README I get the error "PHP Fatal error: Non-readonly class PHPUnit\Event\TestSuite\TestSuiteForTestClass cannot extend readonly class PHPUnit\Event\TestSuite\TestSuite in /builds/finpension/finpension-admins/vendor/phpunit/phpunit/src/Event/Value/TestSuite/TestSuiteForTestClass.php on line 19"

The only warkaround that works for me is, if I call "BypassFinals::enable(false, true);", with the readonly removal it won't work.

finpension-aless avatar Jul 01 '24 14:07 finpension-aless

@finpension-aless it was caused by something else. I tried to modify the extension class to skip the PHPUnit code altogether. Please try the dev version to see if it works for you.

dg avatar Jul 02 '24 22:07 dg