【问题标题】:Loading Zend-Framework Model in Phpunit Class在 Phpunit 类中加载 Zend-Framework 模型
【发布时间】:2013-10-03 09:25:37
【问题描述】:

我想调用我的 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”

【问题讨论】:

标签: php zend-framework phpunit


【解决方案1】:

看起来您的测试套件文件夹没有解析为实际的应用程序文件夹。看看你的情况

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

但是您的 dirname 当前指向 test/application/controller 目录,当然,该目录没有您的实际应用程序。尝试指向顶部根目录下的应用程序文件夹,

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-06-27
    • 1970-01-01
    • 2013-07-04
    • 1970-01-01
    • 2014-08-28
    • 1970-01-01
    • 2015-07-24
    • 2012-10-10
    相关资源
    最近更新 更多