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

Phaked nullable return type object will return phaked object #262

Open
FredM opened this issue Apr 3, 2018 · 2 comments
Open

Phaked nullable return type object will return phaked object #262

FredM opened this issue Apr 3, 2018 · 2 comments

Comments

@FredM
Copy link

FredM commented Apr 3, 2018

If a class declares a function with a nullable return type

public function find(int $id): ?Foo
{
    return $this->repository->find($id);
}

Then, when mocking this object without specifying behaviour for this method (Phake::when(...) ), Phake will automatically return a Phaked object of this type instead of null

@adoy
Copy link
Member

adoy commented Apr 23, 2021

Hi Fred :-)

This is because the default answer strategy used is SmartDefaultAnswer.

I think a good addition would be to add a new IAnswer implementation that does what you want so that you can change it.

I'll tag this as an Enhancement.

Thanks

@FredM FredM changed the title Automatic return phaked object on nullable return type in PHP7 Phaked nullable return type object will return phaked object Apr 24, 2021
@FredM
Copy link
Author

FredM commented Apr 24, 2021

Thanks for the explanation Pierrick!
Not sure of the context back then but obviously I found an alternative ;-) You can close it or keep it if you think that is could be a valuable improvement.

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

No branches or pull requests

2 participants