Thanks to Gerard Meszaros, we have the following (names for) categories of test doubles:
Of these, PHPUnit has had built-in support for stubs and mocks for quite some time.
The stubs and mocks generated by PHPUnit(_MockObject) can be used in every context where an object of the original class is expected. As it should be, the code of the original class is not executed when a method is called on the stub or mock.
When writing integration tests in general and edge-to-edge tests in particular, you generally do not want to stub or mock dependencies. Sometimes, though, the ability to have expectations such as "this method has to be called with these arguments for this test to be successful" would also be useful in tests that have a larger scope than unit tests.
The idea is to have a "Test Proxy" object that provides the same API for expectations as a mock object while at the same time proxying method calls to the original class.
public function doSomething(Bar $bar)
public function doSomethingElse()
class FooTest extends PHPUnit_Framework_TestCase
public function testSomething()
$proxy = $this->getMockBuilder('Bar')
$foo = new Foo;