Laravel unit test how to test Event with email without send an email -
how can test snippet without send email ?
public function forgot() { $isvalid = $this->updateform->valid(input::only('email')); if ($isvalid) { $result = $this->user->forgot($this->updateform->data()); if (isset($result['user']) && ($result['success'] > 0)) { event::fire('user.mail.forgot', array('data'=>$result['user'])); return response::json(array('success'=>1),200); } $error = isset($result['error'])?array_pop($result):trans('user.generror'); return response::json(array( 'success'=>0, 'errors' => array('error'=>array($error))), 200); } return response::json(array( 'success' => 0, 'errors' => $this->updateform->errors()), 200 ); }
by test with:
public function _getsuccess($content) { $json = str_replace(")]}',\n", '', $content); $native = json_decode($json); return $native->success; } public function _set200($method, $uri, $parameters = array()) { $this->client->setserverparameter('http_x-requested-with', 'xmlhttprequest'); $response = $this->call($method, $uri, $parameters); $this->assertresponsestatus(200); return $response; } public function testuserforgot200success() { $response = $this->_set200('post', '/api/v1/users/forgot', array('email' => $this->useremail)); $this->assertsame(1, $this->_getsuccess($response->getcontent())); }
but in way have set mail config file in testing folder , sustem send email :(
create app/config/testing/mail.php
file , set pretend true on it:
<?php return [ 'pretend' => true, ];
Comments
Post a Comment