제 경우에는 사용자 지정 요청 및 응답 개체가 있습니다 : My_Controller_Request_Rest
및 My_Controller_Response_Rest
.
이 문제를 해결하기 위해 Zend_Controller_Request_HttpTestCase
및 Zend_Controller_Response_HttpTestCase
으로 각각 확장되는 My_Controller_Request_RestTestCase
및 My_Controller_Response_RestTestCase
을 새로 만들었습니다.
David Harkness은 실제로 문제를 해결합니다. 유일한 것은 개체가 각 클래스에 해당하는 HttpTestCase 클래스를 확장해야한다는 것입니다.
개체를 직접 설정할 수 없으므로 각 개체에 대한 설정자를 만들어야합니다.
library/My/Controller/Request/Rest.php
class My_Controller_Request_Rest extends Zend_Controller_Request_Http
{
// Nothing fancy.
}
:
tests/application/controllers/ControllerTestCase.php
abstract class ControllerTestCase extends Zend_Test_PHPUnit_ControllerTestCase
{
/**
* Application instance.
* @var Zend_Application
*/
protected $application;
/**
* Setup test suite.
*
* @return void
*/
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());
}
}
내 사용자 지정 요청 및 응답 객체가 다음 서명이 :
나는 다음과 같은 ControllerTestCase
코드를
class Bonzai_Controller_Response_Rest extends Zend_Controller_Response_Http
{
// Nothing fancy either
}
자,이 내가 library/My/Controller/Request/Rest.php
및 library/My/Controller/Controller/Request/RestTestCase.php
에서 동일한 코드를 반복하지 않도록하는 방법을 알아낼 수없는 것입니다. 코드는 Request/Rest.php와 Request/RestTestCase.php와 Response/Rest.php 및 Response/RestTestCase.php에서 동일하지만, Zend_Controller_(Request|Response)_HttpTestCase
을 확장합니다.
내가 분명히했으면 좋겠다. 나는 포스트가 오래되었음을 알고 있지만, 조금 더 연장 할 가치가 있다고 생각합니다.
참조 http://stackoverflow.com/questions/190292/phpunit-unit-testing-with-items-that-need-to-send-headers – ManseUK