0

I am developing a test for a controller function and basically it just acts upon a cake request, is there anyway to mock cake request inside the test function so that whenever the controller tries to access $this->request->data it returns the data i have set in the test case? if there is a way please tell me how.

Regards

2
  • Have you heard of PHPUnit? book.cakephp.org/2.0/en/development/testing.html May 14, 2012 at 9:56
  • Yes, actually i mocked the Auth component to be able to return the user whenever my controller asks for it, not sure how to do it with cake request tho $this->myController= $this->generate('Posts', array( 'components' => array('Session','Auth' => array('User'), ) ));
    – Niro
    May 14, 2012 at 14:57

1 Answer 1

0

The documentation contains an example of how to set the request data. For quick reference:

public function testIndexPostData() {
    $data = array(
        'Article' => array(
            'user_id' => 1,
            'published' => 1,
            'slug' => 'new-article',
            'title' => 'New Article',
            'body' => 'New Body'
        )
    );
    $result = $this->testAction(
        '/articles/index',
        array('data' => $data, 'method' => 'post')
    );
    debug($result);
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.