json 페이로드를 허용하는 컨트롤러 함수를 테스트하려고합니다.Cakephp testAction()이 컨트롤러에 json 페이로드를 보내지 않습니다.
testAction()의 문서에 따라 $ options [ 'data']를 적절한 문자열로 설정하면됩니다. 그게 나를 위해 작동하지 않습니다. 여기에 인용 된 문서를 참조하십시오 : http://api20.cakephp.org/class/controller-test-case (testAction() 섹션을 아래로 스크롤하십시오).
내 테스트 사례입니다.
public function testCreate(){
//Some code here
$this->testAction('/shippingbatches/create', array('data' => '[3,6]', 'method' => 'post'));
//Some more code here
}
여기 내 컨트롤러 기능
public function create(){
debug($this->request); //This debug shows me an empty array in $this->request->data
ob_flush();
$order_ids = json_decode($this->request->data);
//Some more code here
}
컨트롤러 함수의 첫 번째 라인은 저 $ this-> 요청 -> 데이터 빈 어레이를 보이고있다. testAction()에서 전달 된 '데이터'가 실제 배열이면 nice &이됩니다. 하지만 그것은 문자열로 설정되어 있지 않습니다 (설명서에 나와있는 것과는 다릅니다).
다음은 디버그 결과입니다.
object(Mock_CakeRequest_ef4431a5) {
params => array(
'plugin' => null,
'controller' => 'shippingbatches',
'action' => 'create',
'named' => array(),
'pass' => array(),
'return' => (int) 1,
'bare' => (int) 1,
'requested' => (int) 1
)
data => array()
query => array(
'case' => 'Controller\ShippingBatchesController'
)
url => 'shippingbatches/create'
base => ''
webroot => '/'
here => '/shippingbatches/create'
}
도와주세요.
Gurpreet는
감사합니다. 그렇지만 어떻게하면 아이디어를 테스트를 읽는 지 알 수있을 것입니다 ... –
그 테스트는 테스트 어플리케이션의'TestsAppsPostsController :: input_data()'를 사용합니다. 거기를보고, 나는'CakeRequest :: input()'이 입력을 잡는 데 사용된다는 것을 발견했다. – jeremyharris