-
Notifications
You must be signed in to change notification settings - Fork 242
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
PHP 8 | 'static' is an invalid class name #527
Comments
Support for this new return type has not been added yet in Prophecy. However, I'm not quite sure how to implement that properly regarding the value actually returned by the double (when Prophecy guesses the returned value because it is not set explicitly). |
I think it only needs to be handled the same way There's no need to resolve the class, as this is valid:
|
@AlexandruGG do you want to make this change? We'd add some tests too https://github.com/phpspec/prophecy/blob/master/spec/Prophecy/Doubler/Generator/Node/ReturnTypeNodeSpec.php#L108-L120 |
Oh hm you're right @stof that is tricky |
@ciaranmcnulty generating the right signature is easy. But generating the right behavior is not. My own opinion is that Prophecy should drop all that logic, and expect all calls to be explicitly configured (which solves that case for |
In the short term (+ in prophecy 1.x) we can have a special case for |
I'm hitting this as well.. Any workaround besides dropping the use of the static return type in my code? |
@RobinHoutevelts this is the workaround I'm using for now. Works with static analysers like PHPStan and Psalm: /**
* @return static
*/
public function setName(string $name): self
{
$this->name = $name;
return $this;
} |
irontec@2d17db5 kinda did it for me as wel. Not sure what impact it has but at least my tests are green. Thanks for the help! |
The fix from irontec@2d17db5 works. Could this be merged? |
Well, nobody has submitted a PR with a fix yet |
Yeah we don't scour forks for fixes; if someone can open a PR and write a test to go with it we can consider merging |
Here is fix of the issue |
Avoid bug in Prophecy phpspec/prophecy#527
* Allow Symfony 6 * Switch to phpunit mocking for Process test Avoid bug in Prophecy phpspec/prophecy#527 * Fix CS Co-authored-by: Boudry Julien <[email protected]>
Fixed in #545 |
Hello, I'm seeing a fatal error trying to use Prophecy with PHPUnit in a Symfony 5 project running PHP 8 with the new
static
return type. Here is the error:And a simplified version of the Entity I'm trying to create a prophecy for:
Is this a known issue with PHP 8? Apologies if so but I couldn't find any mention of it.
Or am I doing something wrong with this usage?
Thanks
The text was updated successfully, but these errors were encountered: