phpzend-frameworkphpunitzend-restrestful-architecture

Examples on Zend_Rest_Controller Unit Testing


I have found a bunch of examples how to unit test Zend_Controller, but I'm looking for examples on Zend_Rest_Controller Unit Testing. Any help is really appreciated. Thank you!


Solution

  • So, basically your question is how to emulate calling PUT and DELETE in your controller tests?
    Since this apparently doesn't work:

    $this->request->setMethod('PUT');
    

    You can access both these actions with plain HTTP POST by providing _method parameter.

    So to call PUT:

    $this->request->setMethod('POST');
    $this->dispatch('articles/123?_method=put');
    

    To call DELETE:

    $this->request->setMethod('POST');
    $this->dispatch('articles/123?_method=delete');
    

    More reading on how to deal with RESTful routing here - http://framework.zend.com/manual/en/zend.controller.router.html#zend.controller.router.routes.rest