【问题标题】:How to create a composer for travis build testing如何为 travis 构建测试创建作曲家
【发布时间】:2019-05-10 02:48:15
【问题描述】:

我正在尝试使用 travis 将 build-passing 状态添加到我的存储库中。我一直在关注网站上的tutorial

我当前的.travis.yml 文件如下所示:

language: php

php:
  - 7.0
  - 7.1
  - 7.2

matrix:
  include:
    - php: 7.2
      dist: precise

sudo: false

before_script: composer install
script: phpunit

我的作曲家是这样的:

{
    "name": "ArrayList",
    "description": "A simple library for arrays to use lambda.",
    "homepage": "https://github.com/Jaquarh/ArrayList",
    "authors": [
        {
            "name": "Kyle Jeynes",
            "email": "okaydots@gmail.com",
            "role": "Developer"
        }
    ],
    "license": "BSD-3-Clause",
    "require": {
        "php": ">=7.2.0"
    },
    "autoload": {
        "psr-4": {
            "Jaquarh\\ArrayList\\": "test"
        }
    },
    "require-dev": {
        "phpunit/phpunit": " 4.8.35"
    }
}

但是,当我在我的 repo 上开始构建时,它会因为这个错误而失败

“phpunit”命令以 2 退出。

原始输出(如果有用的话看起来像这样)

0.59s$ git clone --depth=50 --branch=master https://github.com/Jaquarh/ArrayList.git Jaquarh/ArrayList
Cloning into 'Jaquarh/ArrayList'...
remote: Enumerating objects: 59, done.
remote: Counting objects: 100% (59/59), done.
remote: Compressing objects: 100% (55/55), done.
remote: Total 59 (delta 27), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (59/59), done.
$ cd Jaquarh/ArrayList
$ git checkout -qf 3876173647ec1f766fabafdf2c5c85d1b2af781e
0.02s$ phpenv global 7.1 2>/dev/null
pearrc
Writing /home/travis/.pearrc
0.30s0.21s$ pear config-show
Configuration (channel pear.php.net):
=====================================
Auto-discover new Channels     auto_discover    1
Default Channel                default_channel  pear.php.net
HTTP Proxy Server Address      http_proxy       <not set>
PEAR server [DEPRECATED]       master_server    pear.php.net
Default Channel Mirror         preferred_mirror pear.php.net
Remote Configuration File      remote_config    <not set>
PEAR executables directory     bin_dir          /home/travis/.phpenv/versions/7.1/bin
PEAR documentation directory   doc_dir          /home/travis/.phpenv/versions/7.1/docs
PHP extension directory        ext_dir          /home/travis/.phpenv/versions/7.1.11/lib/php/extensions/no-debug-zts-20160303
PEAR directory                 php_dir          /home/travis/.phpenv/versions/7.1/share/pear
PEAR Installer cache directory cache_dir        /tmp/pear/cache
PEAR configuration file        cfg_dir          /home/travis/.phpenv/versions/7.1/cfg
directory
PEAR data directory            data_dir         /home/travis/.phpenv/versions/7.1/data
PEAR Installer download        download_dir     /tmp/pear/install
directory
Systems manpage files          man_dir          /home/travis/.phpenv/versions/7.1/man
directory
PEAR metadata directory        metadata_dir     <not set>
PHP CLI/CGI binary             php_bin          /home/travis/.phpenv/versions/7.1.11/bin/php
php.ini location               php_ini          /home/travis/.phpenv/versions/7.1.11/etc/php.ini
--program-prefix passed to     php_prefix       <not set>
PHP's ./configure
--program-suffix passed to     php_suffix       <not set>
PHP's ./configure
PEAR Installer temp directory  temp_dir         /tmp/pear/install
PEAR test directory            test_dir         /home/travis/.phpenv/versions/7.1/tests
PEAR www files directory       www_dir          /home/travis/.phpenv/versions/7.1/www
Cache TimeToLive               cache_ttl        3600
Preferred Package State        preferred_state  stable
Unix file mask                 umask            2
Debug Log Level                verbose          1
PEAR password (for             password         <not set>
maintainers)
Signature Handling Program     sig_bin          /usr/bin/gpg
Signature Key Directory        sig_keydir       /home/travis/.phpenv/versions/7.1.11/etc/pearkeys
Signature Key Id               sig_keyid        <not set>
Package Signature Type         sig_type         gpg
PEAR username (for             username         <not set>
maintainers)
User Configuration File        Filename         /home/travis/.pearrc
System Configuration File      Filename         /home/travis/.phpenv/versions/7.1.11/etc/pear.conf
0.02s$ phpenv global 7.1
1.34s$ composer self-update
Updating to version 1.8.0 (stable channel).
   Downloading (connecting...)Downloading (100%)
Use composer self-update --rollback to return to version 1.5.2
$ php --version
PHP 7.1.11 (cli) (built: Oct 26 2017 16:25:55) ( ZTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies
    with Zend OPcache v7.1.11, Copyright (c) 1999-2017, by Zend Technologies
    with Xdebug v2.5.5, Copyright (c) 2002-2017, by Derick Rethans
$ composer --version
Composer version 1.8.0 2018-12-03 10:31:16
8.06s$ composer install
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.
  Problem 1
    - This package requires php >=7.2.0 but your PHP version (7.1.11) does not satisfy that requirement.
The command "composer install" failed and exited with 2 during .
Your build has been stopped.

文档说明我需要为 travis 创建一个作曲家来执行我的指令。我假设这就像一个“测试”。

我创建了一个包含所有库的新文件,并在test/travis.php 中进行了如下所示的测试:

require_once '../ArrayList.php';

$myArray = new ArrayList([
    ['id' => 1, 'username' => 'foo', 'privilidges' => ['can_read' => 1, 'can_write' => 0], 'incomming' => ''],
    ['id' => 2, 'username' => 'bar', 'privilidges' => ['can_read' => 1, 'can_write' => 1], 'incomming' => 'Hi everyone!']
]);

$myArray->where(function($x) {
    $privilidges = (object) $x['privilidges'];
    return $privilidges->can_write;
})->getFirstOrDefault()
  ->ifPresent(function($x) {
      if(!empty(($incomming = $x['incomming']))) echo $incomming;
  });

但是,这不是作曲家,我不知道如何让 Travis 执行此操作。

如果有任何想法或帮助,我们将不胜感激,这是我第一次使用 Travis,文档对于创建 travis 构建测试环境的参考没有帮助。

This is my repository 看看有没有帮助。

更新我的作曲家以使用 PHP 7.1.11 后,我收到此错误

您的需求无法解决为一组可安装的软件包。

【问题讨论】:

  • 错误信息是否不清楚? “此软件包需要 php >=7.2.0,但您的 PHP 版本 (7.1.11) 不满足该要求。”您的 composer.json 明确需要 PHP 7.2,但您正在尝试使用 PHP 7.1。更改您的 composer.json 或升级 PHP。
  • 实际上,我已经为此工作了一整天,并且刚刚开始工作。 是的,该错误在技术上是不言自明的,但通过更改 PHP 版本,它只是给了我更多关于使用 7.2 或 7.1.11 等的错误消息。一旦我修复了这个问题,就像它在在 OP 结束时,我收到了另一个关于可安装软件包集的错误。无论如何我回答了我自己的问题,因为它需要比你所说的更多的修复@Chris
  • 检查作曲家错误跟踪系统。 Composer 修复了一个错误,该错误导致它不会拒绝一些损坏的设置。然后升级导致这些设置失败。
  • 从外观上看,问题不在我的作曲家,Travis 期望将依赖项用作测试服务,因此我必须创建一个 PHPUnit 测试脚本,然后修复所有构建错误@ UlrichEckhardt 感谢您的帮助

标签: php github travis-ci php-7.1


【解决方案1】:

我设法弄清楚 PHPUnit 和作曲家需要什么。

我更改了.travis.yml 以测试所有 PHP 版本并执行运行测试所需的脚本。

language: php

php:
  - 5.4
  - 5.5
  - 5.6
  - 7.0
  - 7.1
  - 7.2

matrix:
  include:
    - php: 5.3
      dist: precise

sudo: false

before_script: composer install
script: phpunit

测试需要配置,所以在一个新文件phpunit.xml.dist我放了这个:

<?xml version="1.0" encoding="UTF-8"?>

<phpunit backupGlobals="false"
         backupStaticAttributes="false"
         colors="true"
         convertErrorsToExceptions="true"
         convertNoticesToExceptions="true"
         convertWarningsToExceptions="true"
         processIsolation="false"
         stopOnFailure="false"
         syntaxCheck="false"
         bootstrap="tests/bootstrap.php"
>
    <testsuites>
        <testsuite name="PHP ArrayList Test Suite">
            <directory>./tests</directory>
        </testsuite>
    </testsuites>
</phpunit>

接下来,我为此配置创建了一个脚本,名为run-tests.sh

php --version
php phpunit.phar --configuration phpunit.xml.dist

我更新了我的作曲家以使用 PHP 5.3 作为开始:

{
    "name": "ArrayList",
    "description": "A simple library for arrays to use lambda.",
    "homepage": "https://github.com/Jaquarh/ArrayList",
    "authors": [
        {
            "name": "Kyle Jeynes",
            "email": "okaydots@gmail.com",
            "role": "Developer"
        }
    ],
    "license": "MIT",
    "require": {
        "php": ">=5.3.0"
    },
    "autoload": {
        "psr-4": {
            "Jaquarh\\ArrayList\\": "src"
        }
    },
    "require-dev": {
        "phpunit/phpunit": " 4.8.35"
    }
}

最后,我构建了包含bootstrap.phpautoload.php.dist 的测试:

if (file_exists($file = __DIR__ . '/autoload.php')) {
    require_once $file;
} elseif (file_exists($file = __DIR__ . '/autoload.php.dist')) {
    require_once $file;
}

// if the library is the project, try to use the composer's autoload for the tests
$composerAutoload = __DIR__ . '/../vendor/autoload.php';

if (is_file($composerAutoload)) {
    include $composerAutoload;
} else {
    die('Unable to find autoload.php file, please use composer to load dependencies:

wget http://getcomposer.org/composer.phar
php composer.phar install

Visit http://getcomposer.org/ for more information.

');
}

【讨论】:

    猜你喜欢
    • 2015-07-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-27
    • 1970-01-01
    • 1970-01-01
    • 2014-11-16
    • 1970-01-01
    相关资源
    最近更新 更多