Trying to do a simple mock of Zend_Config for a method that requires a Zend_Config object type, but the mock returns a 开发者_开发知识库type of Mock_Zend_Config.
Surely I missed something at this late hour and I am obviously wrong in the function call but I fail to spot my error.
$config = $this->getMock("Zend_Config");
Returns Mock_Zend_Config, and my object needs to be of type Zend_Config. Looked up the function signature in a cheatsheet and changed the method call to:
$config = $this->getMock("Zend_Config", array(), array($confArray),"Zend_Config",true);
This version generates a fatal error with message "Zend_Config already exists".
On a sidenote and probably not related to phpunit as such but the typehint does not generate a fatal error as it should , and does so when run without tests.
Any idea of what I'm missing in la mock?
Mock objects extend the mocked object. A type hint for Zend_Config
will be satisfied by any class extending Zend_Config
because by definition a Mock_Zend_Config
extends Zend_Config
and therefor is a Zend_Config
. Consequently, you will get a Fatal Error when trying to name the mock like the class it extends and none if you dont.
精彩评论