How to create phpunit mock objects from namespaced classes

If the autoloader is enabled:

$mock = $this->getMockBuilder('MyNamespace\sub\ClassToMock')
                   ->setMethods(array('methodToMock', 'methodToMock2'))
                   //->disableOriginalConstructor()
                   ->getMock();

works in phpunit 3.6.7, with or without a namespace specified at the top of the test class.

You can leave a response, or trackback from your own site.

Leave a Reply