gpt4 book ai didi

phpunit 抛出未捕获的异常'PHPUnit_Framework_Exception

转载 作者:可可西里 更新时间:2023-11-01 13:12:41 24 4
gpt4 key购买 nike

我有一个 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 beopened.' in D:\PHP\php5\PEAR\PHPUnit\Util\Skeleton\Test.php:102Stack 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com