提问人:Madara's Ghost 提问时间:8/8/2012 最后编辑:Madara's Ghost 更新时间:10/31/2014 访问量:13569
尝试使用配置 XML 文件运行 PHPUnit 会导致异常
Attempting to run PHPUnit with a configuration XML file results in exception
问:
我正在尝试(在PHP聊天室的家伙的帮助下)成功地将PHPUnit与PhpStorm集成。
我设置了文件如下:phpunit.xml
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
backupGlobals = "false"
backupStaticAttributes = "false"
colors = "true"
convertErrorsToExceptions = "true"
convertNoticesToExceptions = "true"
convertWarningsToExceptions = "true"
processIsolation = "false"
stopOnFailure = "false"
syntaxCheck = "false"
bootstrap = "bootstrap.php" >
<testsuites>
<testsuite name="Lamed Test Suite">
<directory>Custom/*</directory>
</testsuite>
</testsuites>
</phpunit>
并成功配置 PHP storm 以从该文件中读取数据。
问题是,我在运行测试时在 PhpStorm 的控制台中收到以下错误:
D:\Websites\php\php.exe C:\fakepath\ide-phpunit.php --bootstrap D:\Websites\htdocs\lamed\tests\boostrap.php --configuration D:\Websites\htdocs\lamed\tests\phpunit.xml
Testing started at 23:51 ...
Fatal error: Uncaught exception 'PHPUnit_Framework_Exception' with message 'Neither "Lamed Test Suite.php" nor "Lamed Test Suite.php" could be opened.' in D:\Websites\php\pear\PHPUnit\Util\Skeleton\Test.php:100
Stack trace:
#0 D:\Websites\php\pear\PHPUnit\TextUI\Command.php(157): PHPUnit_Util_Skeleton_Test->__construct('Lamed Test Suit...', '')
#1 C:\Users\Dor\AppData\Local\Temp\ide-phpunit.php(95): PHPUnit_TextUI_Command->run(Array, true)
#2 C:\Users\Dor\AppData\Local\Temp\ide-phpunit.php(434): IDE_PHPUnit_TextUI_Command::main()
#3 {main}
thrown in D:\Websites\php\pear\PHPUnit\Util\Skeleton\Test.php on line 100
Process finished with exit code 255
它显然是从元素的属性中读取的。问题是,为什么?name=
testsuite
更新
- 我正在运行 Windows Seven x64 SP1 和 PHPStorm 4.0.3。PHPUnit 版本为 3.6.12。
- 在 CLI 中键入实际上会得到相同的结果。
phpunit -c "D:\Websites\htdocs\lamed\tests\phpunit.xml"
- 我的目录与文件位于同一文件夹中。
Custom
phpunit.xml
我很困惑。将不胜感激任何形式的帮助。
答:
从元素中删除 。此元素的文本内容应指向目录,而不是文件通配。/*
<directory>
<directory>Custom</directory>
请参阅 PHPUnit 配置文档,了解有关指定单个文件和包含模式的更多详细信息。
默认情况下,将检查所有以 (e.g.) 结尾的文件是否存在测试用例。如果具有不同的命名约定,则可以切换或添加属性。例如,如果将测试命名为 this:Test.php
UserTest.php
suffix
User.test.php
<directory suffix=".test.php">Custom</directory>
评论
Object_Freezer
Object/Freezer
Test
您所经历的是回退。看起来你的测试套件是空的(并且没有其他额外的非空测试套件)。
在这种情况下,PHPUnit 也会尝试打开一些合适的东西,这是行不通的。然后你会看到一个错误。
如果你只有一个空的测试套件,你会看到异常,其中添加了测试套件的名称和php来尝试它。
Uncaught exception 'PHPUnit_Framework_Exception' with message 'Neither "Empty-Testuite.php" nor "Empty-Testuite.php" could be opened.'
如果您有多个空的测试套件并且没有工作的测试套件,您将看到仅有关 php 的错误,没有添加名称。
Uncaught exception 'PHPUnit_Framework_Exception' with message 'Neither ".php" nor ".php" could be opened.'
如果您至少有一个工作测试套件,但有一个或多个空测试套件,您将看到每个空测试套件的简短报告,但没有错误:
Empty test suite.
当我写到这是一个后备时,它一定不意味着这种行为是 PHPUnit 的意图。在您的案例中看到错误是可以的,因为在开始测试之前,您至少需要运行一个测试。在开始配置测试套件之前,也是一样的。
修复测试缺失且错误消失的根本问题。
据我所知,另一个答案中提到的通配符 - 即使我确信没有它是正确的 - 对你的问题没有任何作用。*
此答案中的信息基于
- PHPUnit 3.6.7 由 Sebastian Bergmann 编写。
- PHP 5.4.5 的 php.net
评论
lamed.php
lamedTest.php
如果同样的问题将目录的值更改为绝对路径而不是相对路径,并且它起作用了。 例如,我更改了 测试 到 C:\eclipse\Workspace\testweb
太糟糕了,我不得不浏览很多非信息,这在文档中没有提到,也没有记录如何使用配置 xml 文件启动命令行界面。
phpunit -c 测试/all.xml
php 测试文件必须以 test 结尾,就像 myTest.php 一样,即使您添加文件元素也是如此 C:\eclipse\Workspace\testweb\tests\classes\something.php 行不通,但 C:\eclipse\工作区\测试web\测试\类\somethingtest.php 会起作用
评论
phpunit -c "D:\Websites\htdocs\lamed\tests\phpunit.xml"