zend-framework - 找不到类 Zend_Test_PHPUnit_ControllerTestCase

标签 zend-framework phpunit

当我运行 phpunit 来测试我的 Controller 时,总是会出现消息:Class Zend_Test_PHPUnit_Controller_TestCase could not be found ...

所有的 require_once 都被执行并且运行没有错误。

我的文件:

测试.php:

<?php

require_once 'bootstrap.php';

class indexTest extends Zend_Test_PHPUnit_ControllerTestCase
{
    protected function setUp ()
    {
        $this->bootstrap = array($this, 'appBootstrap');
        parent::setUp();
    }

    public function appBootstrap ()
    {
        $this->frontController->registerPlugin(new DemoApp_Controller_Plugin_Initialize('test', PROJECT_ROOT));
    }

    public function testIndex()
    {
        $this->dispatch('/');
        $this->assertController('login');
    }   
}

bootstrap.php:

<?php
define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../src/application/'));

set_include_path( APPLICATION_PATH . '/../library' . PATH_SEPARATOR .
        APPLICATION_PATH . '/modules' . PATH_SEPARATOR .
        APPLICATION_PATH . '/layouts' . PATH_SEPARATOR .
        get_include_path() );

require_once 'PHPUnit/Framework.php';     
require_once 'PHPUnit/Framework/TestSuite.php';    
require_once 'PHPUnit/TextUI/TestRunner.php';

error_reporting(E_ALL);

require_once APPLICATION_PATH . "/../library/Zend/Loader.php";
Zend_Loader::registerAutoload();

// Set up the config in the registry path relative to public/index.php
$config = new Zend_Config_Ini(APPLICATION_PATH . '/config.ini'); //, 'test'
Zend_Registry::set('config', $config);

/*// Set up the database in the Registry
$db = Zend_Db::factory($config->db);
Zend_Db_Table_Abstract::setDefaultAdapter($db);
*/

// Set timezone
date_default_timezone_set("Europe/Berlin");

最佳答案

该类不在您的包含路径中,或者您根本没有该类。
采取的步骤:

  1. 找到类文件
  2. 确保类(class)在你的 包括路径,包括 auto_loader 名称解析: Z_Y_YourClass 将被视为 include_path/Z/Y/YourClass.php

祝你好运

关于zend-framework - 找不到类 Zend_Test_PHPUnit_ControllerTestCase,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/760640/

相关文章:

php - 命名空间函数未在 PHPUnit 测试中运行

zend-framework - Zend 导航 : current page

php - 我如何在 PHP 中重新创建我的数据库(例如用于单元测试)

symfony - 在 Symfony2 中运行 PHPUnit 测试时,JMS Serializer 不读取配置

php - 关于如何在 PHPUnit 中使用 setUp() 和 tearDown() 的真实示例?

PHPUnit equalTo 日期与 delta

php - Linux 上意外的 T_STRING

php - 同步两个客户端之间的时间?

php - zend_db 适配器不在/zend_db_expr

PhpStorm 2016.3.3 找不到带有 PHPUnit 6.0 的测试类。*