phpunit 抛出未捕获的异常'PHPUnit_Framework_Exception

本教程将介绍phpunit 抛出未捕获的异常'PHPUnit_Framework_Exception的处理方法,这篇教程是从别的地方看到的,然后加了一些国外程序员的疑问与解答,希望能对你有所帮助,好了,下面开始学习吧。

phpunit 抛出未捕获的异常'PHPUnit_Framework_Exception 教程 第1张

问题描述

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

好了关于phpunit 抛出未捕获的异常'PHPUnit_Framework_Exception的教程就到这里就结束了,希望趣模板源码网找到的这篇技术文章能帮助到大家,更多技术教程可以在站内搜索。