Zend framework2 如何避免单元测试中的工厂关闭

Zend framework2 如何避免单元测试中的工厂关闭,zend-framework2,Zend Framework2,在my Module.php中,我有以下控制器配置: public function getControllerConfig() { return array( 'factories' => array( 'Application\Controller\Persons' => function($serviceLocator) { $controller = new Controller\PersonsC

在my Module.php中,我有以下控制器配置:

public function getControllerConfig() {
    return array(
        'factories' => array(
            'Application\Controller\Persons' => function($serviceLocator) {
                $controller = new Controller\PersonsController();
                $controller->setDocumentManager($serviceLocator->getServiceLocator()->get('doctrine.documentmanager.odm_default'));
                return $controller;
            }
        )
    );
}
现在我想在“phpunit”测试中覆盖工厂关闭,如下所示:

$this->getApplicationServiceLocator()->setAllowOverride(true);
    $this->getApplicationServiceLocator()->get('ControllerLoader')->setService('Application\Controller\Persons', function($serviceLocator) {
        $controller = new Controller\PersonsController();
        $controller->setDocumentManager($this->documentManagerMock);
        return $controller;
}))

但我认为这只是覆盖了一项服务

有人能帮我吗?

简单地说:

$this->getApplicationServiceLocator()->setAllowOverride(true);
$this->getApplicationServiceLocator()->get('ControllerLoader')->setFactory('Application\Controller\Persons', function($serviceLocator) {
        $controller = new Controller\PersonsController();
        $controller->setDocumentManager($this->documentManagerMock);
        return $controller;
};