我正在尝试在我的新项目上运行测试。目录布局如下:
src/ (project's code here)
test/
EviType/
Main.php
phpunit.xml
composer.json
Phpunit安装了composer(所谓的每项目依赖):
{
"require-dev": {
"phpunit/phpunit": ">=3.7.5"
},
}
我用--dev
选项运行composer install/update
。
Phpunit配置被定义为一个极简的test/phpunit.xml
:
<?xml version="1.0" encoding="utf-8"?>
<phpunit colors="true">
<testsuites>
<testsuite>
<directory suffix="">EviType</directory>
</testsuite>
</testsuites>
</phpunit>
test/EviType/Main.php
中的测试代码也尽可能短:
<?php
class Main extends PHPUnit_Framework_TestCase
{
public function test()
{
$this->assertTrue(true);
}
}
所以当我运行phpunit:
php54 -C vendor/bin/phpunit -c test/
(系统安装了多个php版本,php54是/usr/local/php54/bin/php
的别名)
我得到了几个简洁的警告消息:
X-Powered-By: PHP/5.4.5
Content-type: text/html
<br />
<b>Warning</b>: include_once(/path/to/docs/test): failed to open stream: Success in <b>/path/to/docs/vendor/phpunit/phpunit/PHPUnit/Util/Fileloader.php</b> on line <b>92</b><br />
<br />
<b>Warning</b>: include_once(): Failed opening '/path/to/docs/test' for inclusion (include_path='/path/to/docs/vendor/phpunit/phpunit/:/path/to/docs/vendor/phpunit/phpunit/../../symfony/yaml:/path/to/docs/vendor/phpunit/phpunit/vendor/phpunit/php-text-template/:/path/to/docs/vendor/phpunit/phpunit/vendor/phpunit/php-token-stream/:/path/to/docs/vendor/phpunit/phpunit/vendor/phpunit/php-file-iterator/:/path/to/docs/vendor/phpunit/phpunit/vendor/phpunit/php-code-coverage/:/path/to/docs/vendor/phpunit/phpunit/vendor/phpunit/php-timer/:/path/to/docs/vendor/phpunit/phpunit/vendor/phpunit/phpunit-mock-objects/:.:/usr/local/php54/lib/php') in <b>/path/to/docs/vendor/phpunit/phpunit/PHPUnit/Util/Fileloader.php</b> on line <b>92</b><br />
<br />
<b>Warning</b>: include_once(/path/to/docs/test/EviType): failed to open stream: Success in <b>/path/to/docs/vendor/phpunit/phpunit/PHPUnit/Util/Fileloader.php</b> on line <b>92</b><br />
<br />
<b>Warning</b>: include_once(): Failed opening '/path/to/docs/test/EviType' for inclusion (include_path='/path/to/docs/vendor/phpunit/phpunit/:/path/to/docs/vendor/phpunit/phpunit/../../symfony/yaml:/path/to/docs/vendor/phpunit/phpunit/vendor/phpunit/php-text-template/:/path/to/docs/vendor/phpunit/phpunit/vendor/phpunit/php-token-stream/:/path/to/docs/vendor/phpunit/phpunit/vendor/phpunit/php-file-iterator/:/path/to/docs/vendor/phpunit/phpunit/vendor/phpunit/php-code-coverage/:/path/to/docs/vendor/phpunit/phpunit/vendor/phpunit/php-timer/:/path/to/docs/vendor/phpunit/phpunit/vendor/phpunit/phpunit-mock-objects/:.:/usr/local/php54/lib/php') in <b>/path/to/docs/vendor/phpunit/phpunit/PHPUnit/Util/Fileloader.php</b> on line <b>92</b><br />
PHPUnit 3.7.14 by Sebastian Bergmann.
Configuration read from /path/to/docs/test/phpunit.xml
.
Time: 0 seconds, Memory: 2.50Mb
OK (1 test, 1 assertion)
断言报告让我很高兴,但我不明白为什么它甚至试图包括目录:
include_once(/path/to/docs/test)
以及神秘的failed to open stream: Success
子句的含义。这似乎是一个php的错误,但它应该在很久以前修复。
设置如下:
<php>
<ini name="display_errors" value="0"/>
</php>
使这些警告消失,但我觉得在phpunit安装中有一个更深层的问题需要挖掘。
有什么建议吗?
您应该将后缀设置为".php" -否则phpunit会尝试包含所有包含"的文件,即所有文件和所有目录。