PHPUnit - Can Mocking/Stubbing happen without the actual class file?

Hello All,

I was wondering if Mocking/Stubbing can be done without the original class file that has to be mocked/stubbed?


Yes, you can mock a non-existent class. Just call getMock with the required class name and set it up as normal.

public function testCanMockNonexistentClass()
    $mock = $this->getMock('Foo');

    $this->assertTrue($mock instanceof Foo);