PHPUnit: stub methods undefined

sonn

New Member
I must be missing something. I'm trying to stub methods on a class in PHPUnit, but when I invoke the method on the mock object, it tells me that method is undefined.Example class to stub:\[code\]namespace MyApp;class MyStubClass { public function mrMethod() { // doing stuff } }\[/code\]To stub it, I write:\[code\]// specifying all getMock() args to disable calling of class __construct()$stub = $this->getMock('MyStubClass', array(), array(), 'MockMyStubClass', false, false, false);$stub->expects($this->any()) ->method('mrMethod') ->will($this->returnValue('doing stuff'));\[/code\]But upon invoking the stubbed method, I get an exception:\[code\]$stub->mrMethod();//PHP Fatal error: Call to undefined method MockMyStubClass::mrMethod()\[/code\]I'm using PHPUnit 3.4.3 with PHP 5.3.0. Another small thing I noticed was that if specifying a namespace in the \[code\]getMock()\[/code\] method results in a class loading exception because of a double namespace:\[code\]$stub = $this->getMock('MyApp\MyStubClass');// Fatal error: Class 'MyApp\MyApp\MyStubClass' not found\[/code\]That strikes me as rather odd (and getmock() will not accept a namespace with a leading backslash). The only thing I could think to cause that would may be because this class isregistered with an autoloader?Any thoughts?
 
Back
Top