| Q |
A |
| PHPUnit version |
9.5.18 |
| PHP version |
8.1.2 |
| Installation Method |
Composer |
Summary
createMock is not working with new in initializers
Current behavior
Tests fail with an incomprehensible error:
PHP Fatal error: Constant expression contains invalid operations in /var/www/html/app/vendor/phpunit/phpunit/src/Framework/MockObject/MockClass.php(51) : eval()'d code on line 9
How to reproduce
class MyClass {
public static function create(Example $example = new Example()) {
// ...
}
}
// ...
public function testSome(): void
{
$this->createMock(MyClass::class); // <--- PHP Fatal error
}
/ ...
Expected behavior
Mock is created successfully.
Summary
createMock is not working with new in initializers
Current behavior
Tests fail with an incomprehensible error:
PHP Fatal error: Constant expression contains invalid operations in /var/www/html/app/vendor/phpunit/phpunit/src/Framework/MockObject/MockClass.php(51) : eval()'d code on line 9How to reproduce
Expected behavior
Mock is created successfully.