如何为 travis 构建测试创建作曲家
How to create a composer for travis build testing
我正在尝试使用 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"
}
}
但是,当我在我的存储库上开始构建时,它失败并出现此错误
The command "phpunit" exited with 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 创建一个 composer 来执行我的指令。我假设这就像 'test'.
我创建了一个包含所有库的新文件,并在 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 后,我收到此错误
Your requirements could not be resolved to an installable set of packages.
我设法弄清楚 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.php
和 autoload.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.
');
}
我正在尝试使用 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"
}
}
但是,当我在我的存储库上开始构建时,它失败并出现此错误
The command "phpunit" exited with 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 创建一个 composer 来执行我的指令。我假设这就像 'test'.
我创建了一个包含所有库的新文件,并在 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 后,我收到此错误
Your requirements could not be resolved to an installable set of packages.
我设法弄清楚 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.php
和 autoload.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.
');
}