Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/274.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PhpUnit测试-不存在非模拟方法_Php_Unit Testing_Phpunit - Fatal编程技术网

PhpUnit测试-不存在非模拟方法

PhpUnit测试-不存在非模拟方法,php,unit-testing,phpunit,Php,Unit Testing,Phpunit,我在调用公共方法时遇到问题。有一个简单的例子: 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-&

我在调用公共方法时遇到问题。有一个简单的例子:

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();
我得到了以下结果:

bool(true)
bool(false)

Fatal error: Call to undefined method Mock_Foo_abdf1ea1::bar()

上面提到的自动加载问题我的bootstrap.php没有加载。 所以类已经创建,但不是从真实的类创建的。 我在网上遇到一个错误:

new Foo();

因此,在这种情况下,我认为这是检查类加载的最佳方法。

添加数组“uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu。如果我创建了一个包含类和测试的文件,那么就没有问题了。自动加载有问题,该类不可用。所以PHPUnit不知道这个类有方法barYeah,非常感谢!这太简单了。