当给定空后缀时,phpunit尝试包含目录

时间:2013-03-18 22:21:42

标签: php phpunit warnings composer-php

我正在尝试对我的新项目进行测试。目录布局如下:

src/ (project's code here)    
test/
    EviType/
        Main.php
    phpunit.xml
composer.json

Phpunit与composer一起安装(所谓的每个项目依赖项):

{
    "require-dev": {
        "phpunit/phpunit": ">=3.7.5"
    },
}

我使用composer install/update选项运行--dev

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 bug,但它应该像很久以前一样修复。

设置类似:

<php>
    <ini name="display_errors" value="0"/>
</php>

让这些警告消失,但我觉得phpunit安装中有一个更深层次的问题需要挖出来。

有什么建议吗?

1 个答案:

答案 0 :(得分:1)

你真的应该将后缀设置为“.php” - 否则phpunit会尝试包含所有包含“”的文件,这些文件都是文件和所有目录。