I spend some time debugging an object test, only to discover that PHPUnit was silently ignoring the specified stub behavior due to the fact that the method was not yet defined in the class that was being stubbed:

<?php class SomeClass { public function aMethod() { // exists, but no body; } } class someOtherClassTest extends \PHPUnit_Framework_TestCase { public function testSomeDependentClassMethod() { $stub = $this->getMock('SomeClass'); $stub->expects($this->once()) ->method('aFakeMethod') ->will($this->returnValue('foo')); // silently returns nothing! $stub->aFakeMethod(); $stub->expects($this->once()) ->method('aMethod') ->will($this->returnValue('bar')); // as expected, returns 'bar' $stub->aMethod(); } }

Is this intentional? If so, what is the reasoning behind it?

I can't find anything about this behavior in the documentation, but don't want to report it as a bug if it is intended to work that way.