1
我想用嘲笑來確定我的控制器是否被正確調用。嘲笑似乎沒有正常工作
我在我的測試用例中調用函數,並且方法正確返回。但是,Mockery似乎沒有接到這個電話。
我試着用$ this-> call和$ this-> client-> request來進行呼叫。這兩個調用都會返回結果,所以Mockery應該計算對控制器的調用。
public function testIndex()
{
/**$entity = \Entity\Classes\Entity::get();
var_dump($entity); **/
//This works, and is returning all the entities for that entity
$headers = array();
$mock = Mockery::mock('\Entity\Classes\Entity');
$mock->shouldReceive('index')->once();
$crawler = $this->custom_request('GET', '/entity/entities/114', $headers);
//echo $response = $this->client->getResponse()->getContent();
//This also works, so the call is being made. custom_request calls $this->client->request method
//$this->call('GET', 'http://myurl:1000/entity/entities/114');
//This alternate method to make the call also work
$this->assertResponseOk();
}
錯誤:
1) ClassTest::testIndex
Mockery\Exception\InvalidCountException: Method index() from
Mockery_0_Entity_Classes_Entity should be called
exactly 1 times but called 0 times.
啊。當我發佈這篇文章時,我正在研究一些事情,並且我也遇到了你的迴應。事實證明,我確實需要使用別名嘲笑,因爲一切都是靜態的。你能指出我有點別名嘲弄嗎?我找不到任何重要的gye項目。 – Dynelight
@Dynelight再次看到答案,添加鏈接 –
Dave最後一個問題:過濾器是否應該使用這個問題?我嘗試添加別名,並且在這個模擬對象上沒有存在'BadMethodCallException:Method Entity \ Controllers \ Entity :: getAfterFilters()'...是您的意思嗎? – Dynelight