[英]PhpUnit test - Non-mocked method does not exist
I got a problem with call public method. 我在调用公共方法时遇到了问题。 There is a simple example:
有一个简单的例子:
class Foo {
public function bar()
{
return array();
}
}
//test code
$test = $this->getMock('Foo', array('____'));
var_dump($test instanceof Foo);
var_dump(method_exists($test, 'bar'));
$result = $test->bar();
And I got following result: 我得到以下结果:
bool(true)
bool(false)
Fatal error: Call to undefined method Mock_Foo_abdf1ea1::bar()
The problem in autoloading as guys mentioned above (my bootstrap.php didn't load). 像上面提到的那样,自动加载中的问题(我的bootstrap.php没有加载)。 So class has been created but not from real class.
因此,已经创建了班级,但不是来自实际班级。 I got an error on line:
我在网上遇到了一个错误:
new Foo();
So in such case I think it's the best way to check class loading. 因此,在这种情况下,我认为这是检查类加载的最佳方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.