phpspec / prophecy

Highly opinionated mocking framework for PHP 5.3+
MIT License
8.53k stars 240 forks source link

SplFileObject generated code is syntax error on PHP8.2 #610

Closed reioto closed 10 months ago

reioto commented 10 months ago

TestCode is

$fileMock = $this->prophesize(SplFileObject::class);
$file = $fileMock->reveal();

Returned Error Message on PHP8.2:

ParseError: syntax error, unexpected token "{"

vendor/phpspec/prophecy/src/Prophecy/Doubler/Doubler.php:137
vendor/phpspec/prophecy/src/Prophecy/Doubler/CachedDoubler.php:36
vendor/phpspec/prophecy/src/Prophecy/Doubler/Doubler.php:100
vendor/phpspec/prophecy/src/Prophecy/Doubler/LazyDouble.php:135
vendor/phpspec/prophecy/src/Prophecy/Prophecy/ObjectProphecy.php:118

Of course there are no syntax error in this package. But I found it in the generated code.

public  function getChildren(): ? {
return $this->getProphecy()->makeProphecyMethodCall(__FUNCTION__, func_get_args());
}

So, SplFileObject::getChildren() is always returned null. It's caused by a method that returns null In this case.

I think. Part of what is causing this problem is here. https://github.com/phpspec/prophecy/blob/master/src/Prophecy/Doubler/Generator/ClassCodeGenerator.php#L89 The null is converted to "".

reioto commented 10 months ago
PHP Type declarations:
Changelog
8.2.0 | The types null and false can now be used standalone.

Probably false type too.

stof commented 10 months ago

Already fixed in the dev version by https://github.com/phpspec/prophecy/pull/598

reioto commented 10 months ago

Oh nice! thanks!