In my case, I have custom request and response objects: My_Controller_Request_Rest and My_Controller_Response_Rest .
What I did for this, I created new My_Controller_Request_RestTestCase and My_Controller_Response_RestTestCase , which extend Zend_Controller_Request_HttpTestCase and Zend_Controller_Response_HttpTestCase respectively.
What David Harkness suggested actually solves the problem. The only thing your objects need to extend is the HttpTestCase class corresponding to each class.
You need to create setters for each object, since you are not allowed to set them directly.
I have the following ControllerTestCase code:
tests/application/controllers/ControllerTestCase.php
abstract class ControllerTestCase extends Zend_Test_PHPUnit_ControllerTestCase { protected $application; public function setUp() { $this->_setupInitializers(); $this->bootstrap = array( $this, 'applicationBootstrap', ); parent::setUp(); $this->setRequest(new My_Controller_Request_RestTestCase()); $this->setResponse(new My_Controller_Response_RestTestCase()); } }
My custom request and response objects have the following signature:
library/My/Controller/Request/Rest.php
class My_Controller_Request_Rest extends Zend_Controller_Request_Http {
library/My/Controller/Response/Rest.php
class Bonzai_Controller_Response_Rest extends Zend_Controller_Response_Http {
Now this is what I could not figure out how to avoid repeating the same code in library/My/Controller/Request/Rest.php and library/My/Controller/Controller/Request/RestTestCase.php . The code in my case is the same in Request / Rest.php and Request / RestTestCase.php, as well as in Response / Rest.php and Response / RestTestCase.php, but they extend Zend_Controller_(Request|Response)_HttpTestCase .
I hope I get it. I know the message is outdated, but I think it’s worth a little more to increase it.