将PHPUnit与Zend_Test和模拟对象一起使用时出现问题

问题描述

| 我在将PHPUnit与Zend_Test和模拟对象一起使用时遇到问题。我正在使用Keith Pope的结构来学习单元测试。我在测试/模块/默认/控制器中有控制器测试,而在测试/模块/默认/模型中有单元测试。模型目录中还有一个名为TestResources的子目录,其中包含创建模拟对象的文件。 有一个名为Default_Model_UserTest的模型单元测试。它继承自ControllerTestCase,后者具有用于所有测试的设置功能。在Default_Model_UserTest中,附加设置将强制测试使用TestResources文件夹中的User.php作为资源。设置功能如下:
protected function setUp() {
    parent::setUp();

    // Replace Model Resources with TestResources
    $autoloader = new Zend_Loader_Autoloader_Resource(array(
        \'basePath\' => dirname(__FILE__),\'namespace\' => \'Default\'
        )
    );
    $autoloader->addResourceType(\'modelResource\',\'TestResources\',\'Resource\');

    $this->object = new Default_Model_User;

}
当我自己运行测试时,它可以使用模拟对象正常运行。我也有一个控制器测试,用于测试用户是否可以对mysql数据库进行身份验证。当运行此命令时,CustomerControllerTest之后的Default_Model_UserTest不使用TestResources文件夹中的User.php,但是它使用主应用程序目录中的资源User.php,因此它使用的是mysql数据库而不是模拟对象。我不知道为什么。在尝试调试它时,我看到身份验证测试一旦运行,它将完全忽略TestResources文件夹中的User.php。 如果问题与测试未正确重置有关,我在ControllerTestCase.php中添加了拆解功能:
protected function tearDown()
{
    Zend_Controller_Front::getInstance()->resetInstance();
    $this->resetRequest();
    $this->resetResponse();

    $this->request->setPost(array());
    $this->request->setQuery(array());

    unset($_SERVER[\'DOCUMENT_ROOT\']);
    parent::tearDown();
}
CustomerControllerTest.php中的拆解函数为:
protected function tearDown() 
{
    Zend_Auth::getInstance()->clearIdentity();
    Zend_Session::forgetMe();
     parent::tearDown();            
}
我到处都可以找到这个问题的答案,但找不到任何东西。我正在使用PHPUnit 3.5.11和Zend框架1.11.3。如果有人对它为什么如此行事有任何见解,我将不胜感激。     

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)