【问题标题】:Trouble running PHPUnit in Travis Build在 Travis Build 中运行 PHPUnit 时遇到问题
【发布时间】:2023-03-30 21:55:01
【问题描述】:

我在从 Travis 运行 PHPUnit 时遇到了一些问题。

我的travis配置很简单

language: php
php:
  - 7.0
  - 7.1
script: phpunit

而我的phpunit.xml如下,

<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="vendor/autoload.php">
    <testsuites>
        <testsuite name="Basic Test Suite">
            <directory suffix=".php">./tests/</directory>
        </testsuite>
    </testsuites>
</phpunit>

还有我的 composer.json

{
    "name": "nikhilkuria/nikeandphp",
    "description": "A PHP library used to work with Nike+ API",
    "type": "library",
    "authors": [
        {
            "name": "nikhilkuria",
            "email": "nikhilkuria@gmail.com"
        }
    ],
    "require": {
        "monolog/monolog": "^1.22"
    },
    "require-dev": {
      "phpunit/phpunit": "5.7.*"
    },
    "autoload": {
        "psr-4": {"NikeAndPhp\\": "src/NikeAndPhp"}
}
}

问题是 Travis 无法找到我的 autoload.php。这是我在 travis 日志中看到的,

无法打开文件“/home/travis/build/nikhilkuria/nikeandphp/vendor/autoload.php”。

整个日志都是here

这里似乎缺少什么?

【问题讨论】:

  • 整个日志的链接失效了

标签: php phpunit composer-php travis-ci


【解决方案1】:

单独的 bin 路径

对于在 composer.json 中定义了单独的 bin-path 的情况,必须相应地调整 phpunit 的路径。

composer.json:

{
  ...
  "config": {
    "vendor-dir": ".Build/vendor",
    "bin-dir": ".Build/bin",
  },
  ...
}

.travis.yaml:

language: php  
...
script:
  - >
    echo;
    echo "Running unit tests";
    .Build/bin/phpunit --colors  -c .Build/vendor/.../UnitTests.xml
...

【讨论】:

    【解决方案2】:

    除了您的 Travis 配置缺少 composer install 步骤之外,您安装 PHPUnit 的方式也有问题。

    script: phpunit 表示您使用全局安装的 PHPUnit 调用 PHPUnit,该 PHPUnit 在 $PATH 上以 phpunit 的形式提供。您很可能不希望这样,因为您已在 composer.json 中将 PHPUnit 列为开发依赖项。要使用使用 Composer 安装的 PHPUnit,您需要改用 script: ./vendor/bin/phpunit

    【讨论】:

    • 这成功了。添加脚本:./vendor/bin/phpunit tests/ - 谢谢!
    【解决方案3】:

    从您的日志输出中可以看出,您没有运行 composer install 命令,这就是您收到 Cannot open file "/home/travis/build/nikhilkuria/nikeandphp/vendor/autoload.php". 错误消息的原因。

    添加

    before_script:
        - composer install
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-02-07
    • 2018-10-15
    • 2018-11-20
    • 1970-01-01
    • 2020-12-16
    • 1970-01-01
    • 1970-01-01
    • 2020-12-11
    相关资源
    最近更新 更多