dtol41388 2013-09-27 07:05
浏览 45

在Phpunit类中加载Zend-Framework模型

I want to call my zend-framework model and use there functions in AuthenticationControllerTest.php but I am getting error when i run it from terminal.

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

Here is my AuthenticationControllerTest.php file

<?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
    }   
}

but when run it from terminal "phpunit AuthenticationControllerTest" it give me error:

$ phpunit AuthenticationControllerTest

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

  • 写回答

1条回答 默认 最新

  • dongpouda6700 2013-09-28 12:53
    关注

    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.

    评论

报告相同问题?

悬赏问题

  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教