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

Methods returning void or never can not be mocked to throw an Exception #120

Open
mikey179 opened this issue Jan 27, 2024 · 0 comments
Open

Comments

@mikey179
Copy link
Member

mikey179 commented Jan 27, 2024

Methods and functions with return type declaration void or never can not be mocked to throw an Exception:

class Example {
    public function store(string $something): void { ... }
}
$mock = NewInstance::of(Example::class)
$mock->returns(['store' => throws(new Exception('failure'))]);

InvalidArgumentException: Trying to map method Example::store(), but it is declared as returning void or never.

It should be possible to throw an exception from such a method, while providing a regular return value should still be forbidden.

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

No branches or pull requests

1 participant