我正在尝试(相当长一段时间,在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
属性读取的。问题是,为什么? 更新
phpunit -c "D:\Websites\htdocs\lamed\tests\phpunit.xml"
实际上会得到相同的结果。 Custom
目录与phpunit.xml
文件位于同一文件夹中。 我很困惑。将不胜感激。
最佳答案
从/*
元素中删除<directory>
。该元素的文本内容应指向目录,而不是文件glob。
<directory>Custom</directory>
有关指定单个文件和包含模式的更多详细信息,请参见PHPUnit configuration documentation。
默认情况下,将检查所有以
Test.php
(例如UserTest.php
)结尾的文件是否存在测试用例。如果您使用其他命名约定,则可以切换或添加suffix
属性。例如,如果您将测试命名为User.test.php
,则使用以下命令:<directory suffix=".test.php">Custom</directory>
关于phpunit - 尝试使用配置XML文件运行PHPUnit会导致异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11853974/