Skip to content

Commit a58578f

Browse files
committed
Added small script to test installation on with different dependencies
1 parent 16a3327 commit a58578f

File tree

2 files changed

+65
-2
lines changed

2 files changed

+65
-2
lines changed

.travis.yml

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,24 @@ branches:
2323
matrix:
2424
fast_finish: true
2525
include:
26+
- name: Test Install
27+
php: 7.3
28+
install:
29+
script:
30+
# Test that we find Guzzle
31+
- ./tests/install.sh "will-find" "Http\Discovery\HttpClientDiscovery::find();" "php-http/guzzle6-adapter"
32+
# Test that we find a client with Symfony and Guzzle PSR-7
33+
- ./tests/install.sh will-find "Http\Discovery\HttpClientDiscovery::find();" "symfony/http-client:5.* php-http/httplug php-http/message-factory guzzlehttp/psr7:1.* http-interop/http-factory-guzzle"
34+
# We should fail if we dont have php-http/message-factory or PSR-17
35+
- ./tests/install.sh cant-find "Http\Discovery\HttpClientDiscovery::find();" "symfony/http-client:5.* php-http/httplug php-http/message-factory guzzlehttp/psr7:1.*"
36+
- ./tests/install.sh cant-find "Http\Discovery\HttpClientDiscovery::find();" "symfony/http-client:5.* php-http/httplug guzzlehttp/psr7:1.* http-interop/http-factory-guzzle"
37+
# We should be able to find a client when Symfony is only partly installed and we have guzzle adapter installed
38+
- ./tests/install.sh will-find "Http\Discovery\HttpClientDiscovery::find();" "symfony/http-client:5.* php-http/guzzle6-adapter php-http/httplug php-http/message-factory guzzlehttp/psr7:1.*"
39+
2640
- name: PHPSpec code coverage
2741
php: 7.1
28-
# Disable code coverage until https://github.com/leanphp/phpspec-code-coverage/pull/38 is released
29-
# DEPENDENCIES="leanphp/phpspec-code-coverage:^4.2" TEST_COMMAND="composer test-ci"
42+
# Disable code coverage until https://github.com/leanphp/phpspec-code-coverage/pull/38 is released
43+
# DEPENDENCIES="leanphp/phpspec-code-coverage:^4.2" TEST_COMMAND="composer test-ci"
3044
env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest" COVERAGE=true TEST_COMMAND="composer test" PULI_VERSION=1.0.0-beta9
3145
- name: PHPUnit tests
3246
php: 7.3

tests/install.sh

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/bin/bash
2+
3+
gethash() {
4+
if hash md5sum 2>/dev/null; then
5+
echo -n "$@" | md5sum | awk '{print $1}'
6+
else
7+
echo -n "$@" | md5 | awk '{print $1}'
8+
fi
9+
}
10+
11+
HASH=`gethash $@`
12+
BUILD_DIR=build/`echo ${HASH::7}`
13+
14+
echo "Using directory: ${BUILD_DIR}"
15+
# Prepare a folder
16+
#rm -rf $BUILD_DIR
17+
mkdir -p $BUILD_DIR
18+
19+
# Init composer
20+
composer init --working-dir $BUILD_DIR --no-interaction
21+
composer req --working-dir $BUILD_DIR php-http/discovery --no-update
22+
23+
# Define packages from arguments
24+
composer req --working-dir $BUILD_DIR $3
25+
26+
# Copy the current version of php-http/discovery
27+
cp -R src $BUILD_DIR/vendor/php-http/discovery
28+
cd $BUILD_DIR
29+
30+
# Run PHP and check exit code
31+
php -r "require 'vendor/autoload.php'; ${2}" > /dev/null
32+
PHP_EXIT_CODE=$?
33+
34+
# Print result
35+
echo ""
36+
if [ $PHP_EXIT_CODE -eq 0 ]; then
37+
echo "We found a package"
38+
else
39+
echo "We did not find anything"
40+
fi
41+
42+
if [ "$1" = "will-find" ]; then
43+
exit $PHP_EXIT_CODE;
44+
elif [ $PHP_EXIT_CODE -ne 0 ]; then
45+
exit 0
46+
fi
47+
48+
echo "We did find a class but we were not supposed to"
49+
exit 1

0 commit comments

Comments
 (0)