一个根本没有通过的简单测试存在问题。我在控制器中有一个动作:
/**
* @Get("/parse")
* @param Dispatcher $dispatcher
* @return string
*/
public function parse(){
$xml_file = public_path()."/dummy.xml";
//File::get($xml_file); Tried this as well
$file = $this->file->get($xml_file);
return $file;
}
在测试中,我有一个类似的方法:
/**
* A basic functional test example.
*
* @return void
*/
public function testBasicExample(){
File::shouldReceive("get")->once();
$this->call('GET', '/parse');
}
在 Laravel 文档中,他们说每个 Facade 都可以直接模拟,而不需要实例化它,但是测试永远不会通过,我遇到了一个异常:
Mockery\Exception\InvalidCountException: Method get() from Mockery_0 should be called exactly 1 times but called 0 times.
PS:我有 Laravel 5,在测试类中我有 tearDown 方法,以防你想知道。