作曲家包的Travis配置

Travis configuration for composer packages

在处理 laravel 5.1+ 软件包时,我需要通过 travis-ci.org 进行 运行 自动化测试。与常规自动化测试的不同之处在于需要将此包包含到框架中并将特定配置选项设置为 运行 测试。

所以要求是:

我到处找;在 laravel forums, asked in a travis community chat and saw this topic 被关闭时被问到过于本地化(尽管现在回答肯定会有帮助)。我希望我的问题适合保持开放状态。

此时我的配置如下:

language: php

php:
  - 5.5
  - 5.6
  - hhvm

addons:
  hosts:
    - system.hyn.me
    - tenant.hyn.me

before_install:
  - sudo composer self-update

install:
  - composer create-project laravel/laravel
  - cd ./laravel
  - composer require hyn-me/multi-tenant ~0.1.0
  - composer update


before_script:
  - cp .env.travis .env
  - export APP_ENV="testing"
  - php artisan migrate -q -n --path ./vendor/hyn-me/multi-tenant/src/migrations
  - cd ./vendor/hyn-me/multi-tenant

script: phpunit

然而,我对 travis 的了解(到目前为止)是有限的,在我发送不需要的提交数来解决我的问题之前,我宁愿听取您的意见,看看什么是测试集成到框架中的好方法.

Ps。这涉及包 hyn/multi-tenant.

关于如何使这个问题尽可能通用的建议会有所帮助。我希望在不明确提及最佳实践和请求集成到框架示例的情况下有助于定义答案的范围。

所以在将提交推送到 travis 数周之后,我终于完成了这项工作。

.travis.yml:

language: php

sudo: true

php:
  - 5.5
  - 5.6
  - 7.0
  - hhvm

addons:
  hosts:
    - system.hyn.me
    - tenant.hyn.me

install:
  # fix ipv6 issue that prevented composer requests and resulted in failing builds
  - sudo sh -c "echo 'precedence ::ffff:0:0/96  100' >> /etc/gai.conf"
  # updates composer on travis
  - travis_retry composer self-update
  # clear composer cache, might speed up finding new tags
  - travis_retry composer clear-cache
  # set the global github token, so connections won't be cancelled
  - composer config -g github-oauth.github.com $GITHUB_TOKEN
  # create a new database for the hyn connection
  - mysql -e 'create database hyn;' -uroot
  - mysql -e "grant all privileges on *.* to 'travis'@'localhost' with grant option;" -uroot
  # create a new laravel project in the subfolder laravel (default composer behaviour)
  - composer create-project laravel/laravel
  # set global variables
  - export DB_USERNAME=travis DB_DATABASE=hyn DB_PASSWORD= QUEUE_DRIVER=sync

script:
  # run the script calling unit tests and so on
  - ./scripts/travis.sh

after_script:
  - if [[ $TRAVIS_PHP_VERSION != '7.0' ]]; then php vendor/bin/ocular code-coverage:upload --format=php-clover ${TRAVIS_BUILD_DIR}/coverage.clover; fi

和 scripts/travis.sh

#!/bin/bash

# e causes to exit when one commands returns non-zero
# v prints every line before executing
set -ev

cd ${TRAVIS_BUILD_DIR}/laravel

BRANCH_REGEX="^(([[:digit:]]+\.)+[[:digit:]]+)$"

if [[ ${TRAVIS_BRANCH} =~ $BRANCH_REGEX ]]; then
    echo "composer require ${TRAVIS_REPO_SLUG}:${TRAVIS_BRANCH}"
    composer require ${TRAVIS_REPO_SLUG}:${TRAVIS_BRANCH}
else
    echo "composer require ${TRAVIS_REPO_SLUG}:dev-${TRAVIS_BRANCH}"
    # development package of framework could be required for the package
    composer require hyn-me/framework "dev-master as 0.1.99"
    composer require "${TRAVIS_REPO_SLUG}:dev-${TRAVIS_BRANCH}#${TRAVIS_COMMIT}"
fi

# moves the unit test to the root laravel directory
cp ./vendor/${TRAVIS_REPO_SLUG}/phpunit.travis.xml ./phpunit.xml

phpunit
# phpunit --coverage-text --coverage-clover=${TRAVIS_BUILD_DIR}/coverage.clover

由于新 Laravel 版本或 travis 的变化,此代码可能会发生变化。如果是这种情况,您将找到最新版本 here