我创建了一个视图助手:
class SousMenuContrat extends AbstractHelper
{
private $maiContratService;
public function __construct(
FMaiContratService $maiContratService,
) {
$this->maiContratService = $maiContratService;
}
public function __invoke($iMaiContratId, $sActive)
{
$oContrat = $this->maiContratService->selectById($iMaiContratId);
return $this->getView()->partial('maintenance/sousmenucontrat', array(
'oContrat' => $oContrat
));
}
}
现在我需要使用PHPUnit进行测试:
class SousMenuContratTest extends TestCase
{
private $myService;
public function setUp()
{
$maiContratService = $this->getMockBuilder('Maintenance\Service\Model\FMaiContratService')
->disableOriginalConstructor()
->getMock();
$oContrat = new FMaiContrat();
$stub = $this->returnValue($oContrat);
$maiContratService->expects($this->any())->method('selectById')->will($stub);
$this->myService = new SousMenuContrat(
$maiContratService
);
}
public function testInvoque()
{
$this->myService->__invoke(2, 'contrat');
}
}
但是测试会发送错误,因为测试不知道:
$this->getView()->partial();
提前感谢 :)