2013-07-18 3 views
0

"SiteController"라는 컨트롤러가 있습니다. 거기에 정상적인 indexAction이 FrontPage를 표시합니다. 이 테스트는 상당히 쉽지만 매개 변수가있는 작업이 아닌 다른 함수를 테스트하는 방법은 무엇입니까? "sendMail ($ to, $ message)"함수가 있다고 가정 해 봅시다. 어떻게 테스트합니까?PHPUnit 및 Zend : 컨트롤러에서 함수 테스트?

<?php 

class ControllerTest extends Zend_Test_PHPUnit_ControllerTestCase 
{ 

    public function testShowCallsServiceFind() 
    { 
     $this->dispatch('/index'); // dont care about this... 

     // what I need is a way to do this: 
     $res = $controller->sendMail("bla", "bla"); // so that I can test sendMail? 

    } 
} 

어떻게 sendmail을 테스트 할 수 있습니까? 당신은 실제로 해달라고

답변

0

가 디스패치 메소드를 호출 할 필요가, 당신은 최대의 새로운 컨트롤러 객체를 직접 호출 방법 할 수 있습니다, 당신은 '모의'의존성 당신 때문에 돈에

$controller = new \My\Controller(); 

$actual_result = $controller->sendMail($params); 

$this->assertEquals($expected_result, $actual_result); 

그래도 조심해야합니다 테스트를 실행할 때 실제로 실제 이메일을 보냅니다! http://phpunit.de/manual/3.0/en/mock-objects.html

관련 문제