1

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

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

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

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

设置类似:

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

使这些警告消失,但我觉得 phpunit 安装中存在更深层次的问题需要挖掘。

有什么建议么?

4

1 回答 1

2

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

于 2013-03-19T10:32:00.053 回答