2013-09-27 38 views
0

我想调用我的zend框架模型并使用AuthenticationControllerTest.php中的函数,但是当我从终端运行它时出现错误。在Phpunit类中加载Zend-Framework模型

- -MyZendproject 
- -application 
    -model 
    -testmodel 
- +public 
- -tests 
    - aplication 
    - controller 
     - .AuthenticationControllerTest.php 

这里是我的AuthenticationControllerTest.php文件

<?php 
require_once `PHPUnit/Framework/TestCase.php`; 

defined(`APPLICATION_PATH`) 
     || define(`APPLICATION_PATH`, realpath(dirname(__FILE__) . `/../application`)); 

    // Define application environment 
     defined(`APPLICATION_ENV`) || define(`APPLICATION_ENV`, `tests`); 

     // Ensure library/ is on include_path 
     set_include_path(implode(PATH_SEPARATOR, 
       array(realpath(APPLICATION_PATH . `../../../library`), get_include_path()))); 

     // Zend_Application 
     require_once `Zend/Application.php`; 

     $application = new Zend_Application(
       APPLICATION_ENV, 
       realpath(APPLICATION_PATH .`configs/application.ini`) 
     ); 
class AuthenticationControllerTest extends PHPUnit_Framework_TestCase 
{ 
    public function testLoginRetriespLogin() { 
     $testmodel = new Model_testmodel_Object();//my model 
    } 
} 

但是当来自终端 “的PHPUnit AuthenticationControllerTest” 运行它,它给我的错误:

$ phpunit AuthenticationControllerTest

..FPHP Fatal error: Class 'Model_testmodel_Object' not found in /var/www/versioned/pm160form/tests/application/controllers/AuthenticationControllerTest.php on line 146

+0

由于您使用了许多[反引号(执行运算符)](http://php.net/language.operators.execution),您的代码实际上应该会产生更多的错误。除此之外,你在你的问题中描述的只是一个缺少的类定义。只需要包含它的文件。 – hakre

+0

另外,我认为你可以从phpunit bootstrap文件和xml配置中获益:http://phpunit.de/manual/current/en/appendixes.configuration.html – hakre

回答

0

看起来你的测试套文件夹没有解决朝着实际的应用文件夹。看你怎么有

|| define(`APPLICATION_PATH`, realpath(dirname(__FILE__) . `/../application`)); 

但你的目录名,目前指向测试/应用/控制器,当然,没有实际的应用程序目录。试着指出这是顶级的根,而不是下的应用程序文件夹,

|| define(`APPLICATION_PATH`, realpath(dirname(__FILE__) . `/../../../application`)); 

此外,应注意遵循在http://framework.zend.com/manual/1.12/en/zend.test.phpunit.html描述Zend框架使用PHP单位的标准。在自动加载器可以工作之前,框架需要完全自举。