Skip to content

Commit e95c211

Browse files
authored
Merge pull request #157 from Nyholm/install-test
Added small script to test installation on with different dependencies
2 parents 16a3327 + ae1671e commit e95c211

File tree

3 files changed

+87
-3
lines changed

3 files changed

+87
-3
lines changed

.travis.yml

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ matrix:
2525
include:
2626
- name: PHPSpec code coverage
2727
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"
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"
3030
env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest" COVERAGE=true TEST_COMMAND="composer test" PULI_VERSION=1.0.0-beta9
3131
- name: PHPUnit tests
3232
php: 7.3
@@ -35,6 +35,38 @@ matrix:
3535
php: 7.3
3636
env: TEST_COMMAND="./vendor/bin/phpunit --group=NothingInstalled" DEPENDENCIES="phpunit/phpunit:^7.5"
3737

38+
- name: Test Install
39+
php: 7.3
40+
install:
41+
- |
42+
# install_test is a helper to create folded reports (From Symfony)
43+
install_test () {
44+
local title="$1 \"$2\" ..."
45+
local fold=$(date +%s%N)
46+
echo -e "travis_fold:start:$fold"
47+
echo -e "\\e[1;34m$title\\e[0m"
48+
echo "./tests/install.sh \"$1\" \"$2\" \"$3\""
49+
./tests/install.sh "$1" "$2" "$3" 2>&1
50+
local ok=$?
51+
(exit $ok) &&
52+
echo -e "\\e[32mOK\\e[0m $title\\n\\ntravis_fold:end:$fold" ||
53+
echo -e "\\e[41mKO\\e[0m $title\\n"
54+
(exit $ok)
55+
}
56+
export -f install_test
57+
58+
script:
59+
# Test that we find Guzzle
60+
- install_test will-find "Http\Discovery\HttpClientDiscovery::find();" "php-http/guzzle6-adapter"
61+
# Test that we find a client with Symfony and Guzzle PSR-7
62+
- install_test 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"
63+
# We should fail if we dont have php-http/message-factory or PSR-17
64+
- install_test cant-find "Http\Discovery\HttpClientDiscovery::find();" "symfony/http-client:5.* php-http/httplug php-http/message-factory guzzlehttp/psr7:1.*"
65+
- install_test cant-find "Http\Discovery\HttpClientDiscovery::find();" "symfony/http-client:5.* php-http/httplug guzzlehttp/psr7:1.* http-interop/http-factory-guzzle"
66+
# We should be able to find a client when Symfony is only partly installed and we have guzzle adapter installed
67+
- install_test will-find "Http\Discovery\HttpClientDiscovery::find();" "symfony/http-client:5.* php-http/guzzle6-adapter php-http/httplug php-http/message-factory guzzlehttp/psr7:1.*"
68+
69+
3870
before_install:
3971
- if [[ $COVERAGE != true ]]; then phpenv config-rm xdebug.ini || true; fi
4072
- if ! [ -z "$DEPENDENCIES" ]; then composer require --no-update ${DEPENDENCIES}; fi;

src/Strategy/CommonClassesStrategy.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ final class CommonClassesStrategy implements DiscoveryStrategy
7474
['class' => React::class, 'condition' => React::class],
7575
],
7676
HttpClient::class => [
77-
['class' => SymfonyHttplug::class, 'condition' => [SymfonyHttplug::class, RequestFactory::class]],
77+
['class' => SymfonyHttplug::class, 'condition' => [SymfonyHttplug::class, RequestFactory::class, Psr17RequestFactory::class]],
7878
['class' => Guzzle6::class, 'condition' => Guzzle6::class],
7979
['class' => Guzzle5::class, 'condition' => Guzzle5::class],
8080
['class' => Curl::class, 'condition' => Curl::class],

tests/install.sh

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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+
echo ""
37+
if [ $PHP_EXIT_CODE -eq 0 ]; then
38+
echo "We found a package"
39+
else
40+
echo "We did not find anything"
41+
fi
42+
43+
echo ""
44+
if [ "$1" = "will-find" ]; then
45+
exit $PHP_EXIT_CODE;
46+
elif [ $PHP_EXIT_CODE -ne 0 ]; then
47+
exit 0
48+
fi
49+
50+
echo "We did find a class but we were not supposed to"
51+
echo ""
52+
exit 1

0 commit comments

Comments
 (0)