dtcu5885 2011-05-16 10:04
浏览 27
已采纳

为什么mock对象有错误的类型提示?

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?

  • 写回答

1条回答 默认 最新

  • douzi0609 2011-05-16 10:13
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 mmocr的训练错误,结果全为0
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀