phpunit 抛出未捕获的异常'PHPUnit_Framework_Exception

标签 php zend-framework phpunit

我有一个 Zend Framework 项目,想用单元测试来测试它。

在测试文件夹中,我有如下的 phpunit.xml

<phpunit bootstrap="./application/bootstrap.php" colors="true">
<testsuite name="Application Test Suite">
    <directory>./</directory>
</testsuite>

<filter>
    <whitelist>
        <directory suffix=".php">../application/</directory>
        <exclude>
            <directory suffix=".phtml">../application/</directory>
            <file>../application/Bootstrap.php</file>
            <file>../application/controllers/ErrorController.php</file>
        </exclude>
    </whitelist>
</filter>

<logging>
    <log type="coverage-html" target="./log/reprot" charset="UTP-8"
    yui="true" highlight = "true" lowUpoerBound="50" highLowerBound="80"/>
    <log type="textdox" target="./log/testdox.html" />
</logging>

我在/tests/application 文件夹中有 bootstrap.php,如下所示:

    <?php
error_reporting(E_ALL | E_STRICT);

// Define path to application directory
defined('APPLICATION_PATH')
    || define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../../application'));

// Define application environment
defined('APPLICATION_ENV')
    || define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'testing'));

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

require_once 'Zend/Loader/Autoloader.php';

require_once 'controllers/ControllerTestCase.php';
Zend_Loader_Autoloader::getInstance();

当我转到命令行时,运行以下命令

phpunit --configuration phpunit.xml

它抛出异常:

PHP Fatal error:  Uncaught exception 'PHPUnit_Framework_Exception' with message
'Neither "Application Test Suite.php" nor "Application Test Suite.php" could be
opened.' in D:\PHP\php5\PEAR\PHPUnit\Util\Skeleton\Test.php:102
Stack trace:
#0 D:\PHP\php5\PEAR\PHPUnit\TextUI\Command.php(157): PHPUnit_Util_Skeleton_Test-
>__construct('Application Tes...', '')
#1 D:\PHP\php5\PEAR\PHPUnit\TextUI\Command.php(129): PHPUnit_TextUI_Command->run
(Array, true)
#2 D:\PHP\php5\phpunit(53): PHPUnit_TextUI_Command::main()
#3 {main}
  thrown in D:\PHP\php5\PEAR\PHPUnit\Util\Skeleton\Test.php on line 102

我该如何解决?

最佳答案

我在使用相同的设置时遇到了同样的问题。据我了解,较新版本的 PHPUnit 至少需要一项实际测试才能正常运行。在创建一个简单的测试后,它成功了。

myProject/tests/application/DemoTest.php

<?php
class DemoTest extends ControllerTestCase
{
    public function setUp() {
        parent::setUp();
    }

    public function testCanDoUnitTest() {
        $this->assertTrue(true);
    }
}

关于phpunit 抛出未捕获的异常'PHPUnit_Framework_Exception,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5777877/

相关文章:

php - 这是从服务层组织类的好方法吗?

php - 如何使用数据表和数据映射器?它们有必要吗?

magento - PHPStorm/调试器不会在某些断点处停止

PHPUnit 错误调用模拟上的未定义方法

php - ZendFramework - 如何将 CSV 文件加载到数据库中,重复插入下一条记录而不自动退出?

php - 在 LAMP 配置中创建虚 URL

php - MYSQL_FREE_RESULT如何正确使用?

php - Laravel 关闭异常处理程序

php - Zend Framework 2 Doctrine 2 模块 - Controller 单元测试中没有服务定位器

php - 使用 Laravel 测试 JSON 响应