phpunit引发未捕获的异常'PHPUnit_Framework_Exception [英] phpunit throws Uncaught exception 'PHPUnit_Framework_Exception

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

问题描述

我有一个Zend Framework项目,并且想要使用单元测试来对其进行测试.

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

在tests文件夹中,我的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:\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

我该如何解决?

推荐答案

您会注意到它引发了异常,因为它正在寻找与您为测试套件提供的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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆