CakephpのテストでCakeRequestにアクセスする方法をメモ
Cakephp 2.5.3を使っています
まず、こんなコントローラーがあって
class SomethingController extends AppController {
public function doSomething() {
$data = ['aaa', 'bbb'];
$this->request->data = $data;
}
}
テストはこう
App::uses('SomethingController ', 'Controller');
class SomethingController extends ControllerTestCase {
public function testDoSomething() {
$result = $this->testAction(
'/Something/doSomething',
['return' => 'vars']
);
$expected = ['aaa', 'bbb'];
$this->assertEquals($expected, $this->controller->request->data));
}
}
$this->controller->request
でCakeRequestにアクセスできました