0
簡單測試根本沒有通過。 我有在控制器內的動作:Mockery無法在門面上計算方法調用
/**
* @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文檔,它們說,每個門面可以直接嘲笑,沒有實例它,但測試從不傳球,我發現了一個例外:
Mockery\Exception\InvalidCountException: Method get() from Mockery_0 should be called exactly 1 times but called 0 times.
PS:我有Laravel 5和測試類我剛纔在c拆卸方法你想知道的。
你如何將'$ this-> file'注入控制器? – 2014-11-20 17:58:27
通過構造函數,Laravel通過Depency Injector完成剩下的工作,但是如果我通過構造函數嘗試File :: get() – Burimi 2014-11-20 18:13:21
,那麼這是行不通的,我的意思是代碼如何在你的'ServiceProvider'中綁定。 – 2014-11-20 18:15:49