沃梦达 / 编程问答 / php问题 / 正文

phpunit 抛出未捕获的异常'PHPUnit_Framework_Exception

phpunit throws Uncaught exception #39;PHPUnit_Framework_Exception(phpunit 抛出未捕获的异常PHPUnit_Framework_Exception)

本文介绍了phpunit 抛出未捕获的异常'PHPUnit_Framework_Exception的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a Zend Framework project, and want to using unit testing to test it.

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

In tests folder, I have the phpunit.xml as following;

<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 如下:

And I have bootstrap.php in /tests/application folder as follows:

    <?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();

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

when I go to the command line, run the following command

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:PHPphp5PEARPHPUnitUtilSkeletonTest.php:102
Stack trace:
#0 D:PHPphp5PEARPHPUnitTextUICommand.php(157): PHPUnit_Util_Skeleton_Test-
>__construct('Application Tes...', '')
#1 D:PHPphp5PEARPHPUnitTextUICommand.php(129): PHPUnit_TextUI_Command->run
(Array, true)
#2 D:PHPphp5phpunit(53): PHPUnit_TextUI_Command::main()
#3 {main}
  thrown in D:PHPphp5PEARPHPUnitUtilSkeletonTest.php on line 102

我该如何解决?

推荐答案

您会注意到它抛出了异常,因为它正在寻找与您为测试套件提供的 name 同名的文件.您需要实际编写一个测试套件,然后将该测试套件的名称提供给您的配置:http://www.phpunit.de/manual/3.2/en/organizing-test-suites.html

Youll notice its throwing the exception because its looking for a file named the same as the name you provided for your test suite. You need to actually write a test suite and then supply the name of that test suite to your config: http://www.phpunit.de/manual/3.2/en/organizing-test-suites.html

这篇关于phpunit 抛出未捕获的异常'PHPUnit_Framework_Exception的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:phpunit 抛出未捕获的异常'PHPUnit_Framework_Exception

基础教程推荐