【问题标题】:phpunit tries to include directories when given empty suffixphpunit 在给定空后缀时尝试包含目录
【发布时间】:2013-03-07 10:53:00
【问题描述】:

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

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

phpunit 与 composer 一起安装(即所谓的 per-project 依赖):

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

设置类似:

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

让那些警告消失了,但我觉得phpunit安装中还有一个更深层次的问题有待挖掘。

有什么建议吗?

【问题讨论】:

    标签: php phpunit warnings composer-php


    【解决方案1】:

    您确实应该将后缀设置为“.php” - 否则 phpunit 会尝试包含所有包含“”的文件,即所有文件和所有目录。

    【讨论】:

    • 哦,我明白了,我真的应该这样做。感谢您解决这个问题!我相信这是 PHPUnit 的问题。无论给出什么后缀,包括目录都不是正确的做法。
    猜你喜欢
    • 2022-09-23
    • 2014-04-28
    • 1970-01-01
    • 2021-09-01
    • 2017-07-03
    • 2020-11-17
    • 2019-08-24
    • 2015-04-06
    • 1970-01-01
    相关资源
    最近更新 更多