0

我想调用我的 zend-framework 模型并在其中使用函数,AuthenticationControllerTest.php但是当我从终端运行它时出现错误。

 - -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 致命错误:在第 146 行的 /var/www/versioned/pm160form/tests/application/controllers/AuthenticationControllerTest.php 中找不到类“Model_testmodel_Object”

4

1 回答 1

0

Looks like your test suit folder is not resolving towards the actual application folder. See how you have

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

but your dirname is currently pointing to the test/application/controller directory which, of course, does not have your actual application. Try pointing the application folder that is under the top root instead,

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

Also, take care to follow the standard of using PHP Unit in Zend Framework as described at http://framework.zend.com/manual/1.12/en/zend.test.phpunit.html . The framework needs to be fully bootstraped before the autoloader can work.

于 2013-09-28T12:53:46.560 回答