testing - CakePHP 3 integeration test without a model/entity -


i'm trying test controller function... want test couple of things: a) throws invalid request exception when argument used b) works correctly when correct argument made.

i've written unit tests , seem cool. documentation can find on http://book.cakephp.org/3.0/en/development/testing.html integration testing, whilst interesting , potentially useful, can't seem how suppose implement without using fixtures (which don't want necessarily).

namespace app\test\testcase\controller; use cake\orm\tableregistry; use cake\testsuite\integrationtestcase;  class mustercontrollertest extends integrationtestcase  {  public function testin() {      $this->in();     $this->setexpectedexception('invalid request'); } 

}

class mustercontroller extends appcontroller {  public $helpers = array('address');   public function beforefilter(event $event) {      $this->auth->allow('in');         $this->layout = 'blank';     $this->autorender = false;     $this->loadcomponent('rule');            parent::beforefilter($event); }  public function in($param = null){      if (!$this->request->is(array('post', 'put')) || $this->request->data('proc')!='yada' || is_null($param)){         throw new notfoundexception(__('invalid request'));     }      $this->processrequest($this->request->data('hit'), $this->request->data('proc'), $param);  } 

pointers appreciated.

the integrationtestcase class, name implies, meant integration testing. is, testing interaction between controller , other class uses rendering response.

there way of testing controller, more difficult accomplish, allows test controller methods in isolation:

public function testmycontrollermethod() {     $request = $this->getmock('cake\network\request');     $response = $this->getmock('cake\network\response');     $controller = new mycontroller($request, $response);     $controller->startupprocess();      // add assertions , expectations here     // example assing $controller->tablename mock class      // call method want test     $controller->mymethod('param1', 'param2'); } 

Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

gradle error "Cannot convert the provided notation to a File or URI" -

python - NameError: name 'subprocess' is not defined -