I try to mock readonly class from PHP 8.2 in PHPUnit and got next error:
Symfony\Component\ErrorHandler\Error\FatalError^ {#7 #message: "Compile Error: Non-readonly class Mock_Provider_f80b7c4d cannot extend readonly class App\Validator\Password\Rule\Provider" #code: 0 #file: "/var/www/html/teach-me/vendor/phpunit/phpunit/src/Framework/MockObject/MockClass.php(51) : eval()'d code" #line: 3 -error: array:4 [ "type" => 64 "message" => "Non-readonly class Mock_Provider_f80b7c4d cannot extend readonly class App\Validator\Password\Rule\Provider" "file" => "/var/www/html/teach-me/vendor/phpunit/phpunit/src/Framework/MockObject/MockClass.php(51) : eval()'d code" "line" => 3 ] }
I think this problem appears because PHPUnit creates default non-readonly class for mocked object. Is there a way to force the creation of a readonly class?
"phpunit/phpunit": "^9.5"
I removed readonly keyword from my class and this error disappeared. I would like to use the new features of PHP, but without the ability to mock objects, this is not possible. Perhaps I am doing something wrong and the problem is not at all what I think?