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

shouldNotBeCalled does not raise error when the method is called #617

Open
Deuchnord opened this issue Feb 26, 2024 · 0 comments
Open

shouldNotBeCalled does not raise error when the method is called #617

Deuchnord opened this issue Feb 26, 2024 · 0 comments

Comments

@Deuchnord
Copy link
Contributor

Given the following class:

class SomeClass
{
    public function foo(): Foo
    {
        // some logic here
        return $foo;
    }
}

and the following test:

$mock = $this->prophesize(SomeClass::class);
$mock->foo()->shouldNotBeCalled();

$obj = new Bar($mock->reveal());
$obj->doSomething();

If the foo() method is called during the test, we get the error "Return value must be of type Foo, null returned" instead of the "No calls expected that match: SomeClass::foo()" from NoCallsPrediction.

This makes debugging tests very hard, because the error suggests that we accidentally returned null in a method that, in fact, should not have been called.

I have made a reproducer for this issue to make it more clear: https://github.com/Deuchnord/prophecy-reproducer

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