【问题标题】:PHPUnit installed via Composer uses wrong autoload通过 Composer 安装的 PHPUnit 使用错误的自动加载
【发布时间】:2014-07-26 09:52:58
【问题描述】:

我有一个正常的目录结构:

 - root
  - vendor
      - bin/phpunit
  - tests
     - bootstrap.php

我的 composer.json:

{
    "name": "test/testing",
    "minimum-stability": "dev",
    "require": {
        "phpunit/phpunit": "4.1.*@dev",
        "phpunit/phpunit-mock-objects": "2.2.*@dev"
    },
    "autoload": {
        "classmap": ["tests/config.inc","test.inc"]
    }
}

我的 bootstrap.php:

<?php

require_once 'vendor/autoload.php';

引导程序中还有一些其他的东西,这就是我需要它的原因, 但我在这里删除了它,因为它与我的问题无关。

当我尝试在根文件夹运行 PHPUnit 时:

vendor/bin/phpunit --bootstrap tests/bootstrap.php tests/ItemsTest.php

我得到错误:

PHP Warning:  require(xxxx/vendor/phpunit/phpunit-mock-objects/tests/../vendor/autoload.php): failed to open stream: No such file or directory in xxxxxxx/vendor/phpunit/phpunit-mock-objects/tests/bootstrap.php on line 4

我不知道为什么 phpunit/自动加载器正在加载这个引导程序:

phpunit-mock-objects/tests/bootstrap.php

当然还有第 4 行:

require __DIR__ . '/../vendor/autoload.php';

不起作用。

【问题讨论】:

    标签: php phpunit composer-php


    【解决方案1】:

    无论出于何种原因,PhpUnit 都无法将引导路径理解为相对路径。

    如下替换引导路径似乎可以解决问题:

    vendor/bin/phpunit --bootstrap ./tests/bootstrap.php tests/ItemsTest.php
    

    【讨论】:

    • 太棒了!多谢!我没有在所有的树之间看到这个...... ;)
    猜你喜欢
    • 1970-01-01
    • 2014-12-25
    • 2016-03-29
    • 2023-04-04
    • 2017-03-22
    • 2017-01-26
    • 2015-01-21
    • 2013-09-12
    • 1970-01-01
    相关资源
    最近更新 更多