Skip to content

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

@mikey179

Description

@mikey179

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions