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.
Given the following class:
and the following test:
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()
" fromNoCallsPrediction
.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