Symfony 3.3과 PHPUnit 5.7을 사용 중이며 API 컨트롤러 테스트 서비스를 모의하려고합니다.PhpUnit과 Symfony : 모의 서비스가 작동하지 않습니다.
컨트롤러 :
class ApiTestManager extends BaseApiController{
public function getAction(): View
{
$response = $this->get('app.business.test_api')->getResponse();
return $this->view($response);
}}
테스트 클래스 :
class ApiTestManagerTest extends WebTestCase {
public function testApiCall()
{
$client = static::createClient();
$service = $this->getMockBuilder(ApiTestManager::class)
->disableOriginalConstructor()
->setMethods(['getResponse'])
->getMock()
->expects($this->any())
->method('getResponse')
->will($this->returnValue(new Response()));
$client->getContainer()->set('app.business.test_api', $service);
$client->request('GET', 'de/api/v1/getResponse');
$this->assertEquals(200, $client->getResponse()->getStatusCode());
}}
내가 실수를 찾으려고 노력에 시간을 소비했지만, 매번 나는 그것이 나에게 다음과 같은 오류를 제공이 테스트를 실행합니다
Error: Call to undefined method PHPUnit_Framework_MockObject_Builder_InvocationMocker::getResponse()
누구든지 내 코드에 무슨 문제가 있다고 말할 수 있습니까? 감사합니다 :)
'getMockBuilder()'의 매개 변수로 완전한 클래스 이름을 사용하는 것이 좋습니다. 그리고 올바른 WebTestCase 클래스 인'Symfony \ Bundle \ FrameworkBundle \ Test \ WebTestCase'를 확장 했습니까? –
불행히도 이것은 별다른 차이를 만들지 못합니다. 맞습니다. WebTestCase : – jennymo