0
我想用模擬來測試一個控制器。Cakephp 3使用模擬來測試控制器
在我的控制器
public function myAction() {
$email = new MandrillApi(['template_name'=>'myTemplate']);
$result = $email
->subject('My title')
->from('[email protected]')
->to('[email protected]')
->send();
if (isset($result[0]['status']) && $result[0]['status'] === 'sent')
return $this->redirect(['action' => 'confirmForgotPassword']);
$this->Flash->error(__("Error"));
}
在測試
public function testMyAction() {
$this->get("users/my-action");
$this->assertRedirect(['controller' => 'Users', 'action' => 'confirmForgotPassword']);
}
如何嘲笑類MandrillApi?謝謝
我首先會評估你是否真的需要嘲笑課程。我猜你不想將數據發送到測試中的實時API?鑑於你沒有通過任何憑據,我會假設該類讀取一些全局配置值?也許可以配置它,以便將數據發送到虛擬端點? – ndm
是的,可能需要通過此API的測試密鑰,但是我想知道是否可以在控制器中模擬一個類 – Ozee