我正试图使用travis将build-passing
状态添加到我的repo中。我一直在遵循网站上的教程。
我当前的.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"
}
}
然而,当我开始构建我的回购时,它失败了,出现了这个错误
命令"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创建一个composer来执行我的指令。我认为这就像一次"测试"。
我创建了一个包含所有库的新文件,并在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构建的测试环境没有帮助。
这是我的存储库,如果查看它有任何帮助的话。
在更新我的composer以使用PHP 7.1.11之后,我得到了这个错误
您的需求无法解析为一组可安装的软件包。
我设法弄清楚PHPUnit和composer需要什么。
我更改了.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
我更新了我的composer,使用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.
');
}