phpunit 抛出未捕获的异常 'PHPUnit_Framework_Exception

2021-12-29 00:00:00 php zend-framework phpunit

我有一个 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

相关文章