Currently, if we try to prophesize a class or an interface that doesn't exist, the mock is created anyway, but with nothing inside. This behavior is disturbing, because then, when we try to set a method behavior inside, we get a "method not found" error, as said in https://github.com/phpspec/prophecy/issues/154#issuecomment-184572986:
// The Person class does not exist
$mock = $this->prophesize(Person::class);
$mock->getName()->willReturn('Jérôme');
// Prophecy\Exception\Doubler\MethodNotFoundException: Method `Double\stdClass\P1::getName()` is not defined.
With this PR, trying to prophesize a class that does not exist will now throw a ClassNotFoundException with a comprehensive message that should help understanding what's actually happening.
This new behavior doesn't impact the creation of empty prophecy (i.e. calling prophesize without any argument). However, this might still be a BC break for people who use this method to mock inexistant classes on purpose.
Currently, if we try to prophesize a class or an interface that doesn't exist, the mock is created anyway, but with nothing inside. This behavior is disturbing, because then, when we try to set a method behavior inside, we get a "method not found" error, as said in https://github.com/phpspec/prophecy/issues/154#issuecomment-184572986:
With this PR, trying to prophesize a class that does not exist will now throw a
ClassNotFoundException
with a comprehensive message that should help understanding what's actually happening. This new behavior doesn't impact the creation of empty prophecy (i.e. callingprophesize
without any argument). However, this might still be a BC break for people who use this method to mock inexistant classes on purpose.