Skip to content
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

Cannot use "mixed" as class name #1149

Closed
lindelius opened this issue Nov 11, 2021 · 4 comments · Fixed by #1156
Closed

Cannot use "mixed" as class name #1149

lindelius opened this issue Nov 11, 2021 · 4 comments · Fixed by #1156

Comments

@lindelius
Copy link

lindelius commented Nov 11, 2021

We're getting the following error when running our PHPUnit suite:

Cannot use 'mixed' as class name as it is reserved in /tmp/MockerykqgHQz on line 1

PHP version: 8.0.8
Mockery version: 1.4.4
PHPUnit version: 9.5.10


The contents of the generated file:

<?php class mixed {} 
@ghostwriter
Copy link
Member

Attempting to declare a class with name mixed in PHP 8: mixed-type results the following error:
Fatal error: Cannot use 'mixed' as class name as it is reserved in ... on line … https://3v4l.org/hebJi

do you have a test, that attempts to mock a class with the name mixed?

@lindelius
Copy link
Author

Hi,

The issue is apparently caused by having methods with a return type of mixed, and then when mocking that class adding shouldReceive that then expects the method to return an object. It's resolved by simply removing the mixed type hint.

interface MyInterface {
    public function getSomething(): mixed;
}

$object = Mockery::mock(MyInterface::class);
$object->shouldReceive('getSomething->someMethod')->andReturn("someValue");

Seems like Mockery should know that mixed is a reserved keyword and just treat it as a stdClass object or whatever. The same code works fine without the return type on the method.

@ramsey
Copy link

ramsey commented Jan 9, 2022

I have a reproducible example in #1155, which is the same type of bug with the static return type.

@ghostwriter
Copy link
Member

Hey @lindelius and @ramsey,

your respective issues have been resolved via #1156 and #1157 (awaiting code review cc: @davedevelopment @padraic).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants