나는이 같은 것을 사용 내 AbstractHttpControllerTestCase
:
/**
* @param array $roles e.g. ['admin']
*/
protected function login($roles) {
$userMock = $this->getMock('Application\Entity\User', [], [], '', false);
$userMock->expects($this->any())
->method('getRoles')->will($this->returnValue($roles));
$storageMock = $this->getMock('\Zend\Authentication\Storage\NonPersistent');
$storageMock->expects($this->any())
->method('isEmpty')->will($this->returnValue(false));
$storageMock->expects($this->any())
->method('read')->will($this->returnValue($userMock));
$sm = $this->getApplicationServiceLocator();
$auth = $sm->get('Zend\Authentication\AuthenticationService');
$auth->setStorage($storageMock);
}
그런 다음 내 테스트 자체에 :
$this->login(['admin']);
$this->dispatch($url);
덕분에 Danielss89 @ 나는 ZfcUserIdentity 컨트롤러 플러그인 조롱하지만 난 방법을 완벽하게 이해할 수 없다 코드를 살펴보고 AuthenticationService를 조롱하고 getIdentity 메소드에서 user 엔티티를 기대합니다. 완벽하게 작동하십시오. –