From a58578f3899a48a3db72cbc06721760ae4f372f8 Mon Sep 17 00:00:00 2001 From: Nyholm Date: Fri, 27 Dec 2019 13:17:51 +0100 Subject: [PATCH 1/4] Added small script to test installation on with different dependencies --- .travis.yml | 18 ++++++++++++++++-- tests/install.sh | 49 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+), 2 deletions(-) create mode 100755 tests/install.sh diff --git a/.travis.yml b/.travis.yml index 92acfab..ff5bd20 100644 --- a/.travis.yml +++ b/.travis.yml @@ -23,10 +23,24 @@ branches: matrix: fast_finish: true include: + - name: Test Install + php: 7.3 + install: + script: + # Test that we find Guzzle + - ./tests/install.sh "will-find" "Http\Discovery\HttpClientDiscovery::find();" "php-http/guzzle6-adapter" + # Test that we find a client with Symfony and Guzzle PSR-7 + - ./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" + # We should fail if we dont have php-http/message-factory or PSR-17 + - ./tests/install.sh cant-find "Http\Discovery\HttpClientDiscovery::find();" "symfony/http-client:5.* php-http/httplug php-http/message-factory guzzlehttp/psr7:1.*" + - ./tests/install.sh cant-find "Http\Discovery\HttpClientDiscovery::find();" "symfony/http-client:5.* php-http/httplug guzzlehttp/psr7:1.* http-interop/http-factory-guzzle" + # We should be able to find a client when Symfony is only partly installed and we have guzzle adapter installed + - ./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.*" + - name: PHPSpec code coverage php: 7.1 - # Disable code coverage until https://github.com/leanphp/phpspec-code-coverage/pull/38 is released - # DEPENDENCIES="leanphp/phpspec-code-coverage:^4.2" TEST_COMMAND="composer test-ci" + # Disable code coverage until https://github.com/leanphp/phpspec-code-coverage/pull/38 is released + # DEPENDENCIES="leanphp/phpspec-code-coverage:^4.2" TEST_COMMAND="composer test-ci" env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest" COVERAGE=true TEST_COMMAND="composer test" PULI_VERSION=1.0.0-beta9 - name: PHPUnit tests php: 7.3 diff --git a/tests/install.sh b/tests/install.sh new file mode 100755 index 0000000..3bb80ce --- /dev/null +++ b/tests/install.sh @@ -0,0 +1,49 @@ +#!/bin/bash + +gethash() { + if hash md5sum 2>/dev/null; then + echo -n "$@" | md5sum | awk '{print $1}' + else + echo -n "$@" | md5 | awk '{print $1}' + fi +} + +HASH=`gethash $@` +BUILD_DIR=build/`echo ${HASH::7}` + +echo "Using directory: ${BUILD_DIR}" +# Prepare a folder +#rm -rf $BUILD_DIR +mkdir -p $BUILD_DIR + +# Init composer +composer init --working-dir $BUILD_DIR --no-interaction +composer req --working-dir $BUILD_DIR php-http/discovery --no-update + +# Define packages from arguments +composer req --working-dir $BUILD_DIR $3 + +# Copy the current version of php-http/discovery +cp -R src $BUILD_DIR/vendor/php-http/discovery +cd $BUILD_DIR + +# Run PHP and check exit code +php -r "require 'vendor/autoload.php'; ${2}" > /dev/null +PHP_EXIT_CODE=$? + +# Print result +echo "" +if [ $PHP_EXIT_CODE -eq 0 ]; then + echo "We found a package" +else + echo "We did not find anything" +fi + +if [ "$1" = "will-find" ]; then + exit $PHP_EXIT_CODE; +elif [ $PHP_EXIT_CODE -ne 0 ]; then + exit 0 +fi + +echo "We did find a class but we were not supposed to" +exit 1 From 83c183a43d474fef47eb6e91704eb54de710fc08 Mon Sep 17 00:00:00 2001 From: Nyholm Date: Fri, 27 Dec 2019 13:54:29 +0100 Subject: [PATCH 2/4] Added folded reports --- .travis.yml | 45 +++++++++++++++++++++++++++++++-------------- tests/install.sh | 3 +++ 2 files changed, 34 insertions(+), 14 deletions(-) diff --git a/.travis.yml b/.travis.yml index ff5bd20..560d37c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -23,20 +23,6 @@ branches: matrix: fast_finish: true include: - - name: Test Install - php: 7.3 - install: - script: - # Test that we find Guzzle - - ./tests/install.sh "will-find" "Http\Discovery\HttpClientDiscovery::find();" "php-http/guzzle6-adapter" - # Test that we find a client with Symfony and Guzzle PSR-7 - - ./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" - # We should fail if we dont have php-http/message-factory or PSR-17 - - ./tests/install.sh cant-find "Http\Discovery\HttpClientDiscovery::find();" "symfony/http-client:5.* php-http/httplug php-http/message-factory guzzlehttp/psr7:1.*" - - ./tests/install.sh cant-find "Http\Discovery\HttpClientDiscovery::find();" "symfony/http-client:5.* php-http/httplug guzzlehttp/psr7:1.* http-interop/http-factory-guzzle" - # We should be able to find a client when Symfony is only partly installed and we have guzzle adapter installed - - ./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.*" - - name: PHPSpec code coverage php: 7.1 # Disable code coverage until https://github.com/leanphp/phpspec-code-coverage/pull/38 is released @@ -49,6 +35,37 @@ matrix: php: 7.3 env: TEST_COMMAND="./vendor/bin/phpunit --group=NothingInstalled" DEPENDENCIES="phpunit/phpunit:^7.5" + - name: Test Install + php: 7.3 + install: + - | + # install_test is a helper to create folded reports (From Symfony) + install_test () { + local title="./tests/install.sh \"$1\" \"$2\" \"$3\"" + local fold=$(date +%s%N) + echo -e "travis_fold:start:$fold" + echo -e "\\e[1;34m$title\\e[0m" + ./tests/install.sh "$1" "$2" "$3" 2>&1 + local ok=$? + (exit $ok) && + echo -e "\\e[32mOK\\e[0m $title\\n\\ntravis_fold:end:$fold" || + echo -e "\\e[41mKO\\e[0m $title\\n" + (exit $ok) + } + export -f install_test + + script: + # Test that we find Guzzle + - install_test "will-find" "Http\Discovery\HttpClientDiscovery::find();" "php-http/guzzle6-adapter" + # Test that we find a client with Symfony and Guzzle PSR-7 + - 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" + # We should fail if we dont have php-http/message-factory or PSR-17 + - install_test cant-find "Http\Discovery\HttpClientDiscovery::find();" "symfony/http-client:5.* php-http/httplug php-http/message-factory guzzlehttp/psr7:1.*" + - install_test cant-find "Http\Discovery\HttpClientDiscovery::find();" "symfony/http-client:5.* php-http/httplug guzzlehttp/psr7:1.* http-interop/http-factory-guzzle" + # We should be able to find a client when Symfony is only partly installed and we have guzzle adapter installed + - 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.*" + + before_install: - if [[ $COVERAGE != true ]]; then phpenv config-rm xdebug.ini || true; fi - if ! [ -z "$DEPENDENCIES" ]; then composer require --no-update ${DEPENDENCIES}; fi; diff --git a/tests/install.sh b/tests/install.sh index 3bb80ce..1f7480f 100755 --- a/tests/install.sh +++ b/tests/install.sh @@ -33,12 +33,14 @@ PHP_EXIT_CODE=$? # Print result echo "" +echo "" if [ $PHP_EXIT_CODE -eq 0 ]; then echo "We found a package" else echo "We did not find anything" fi +echo "" if [ "$1" = "will-find" ]; then exit $PHP_EXIT_CODE; elif [ $PHP_EXIT_CODE -ne 0 ]; then @@ -46,4 +48,5 @@ elif [ $PHP_EXIT_CODE -ne 0 ]; then fi echo "We did find a class but we were not supposed to" +echo "" exit 1 From 7049f7dfac2501a404c9737d6f590daa1c7ba3e7 Mon Sep 17 00:00:00 2001 From: Nyholm Date: Fri, 27 Dec 2019 14:21:57 +0100 Subject: [PATCH 3/4] Better title and cleaner output --- .travis.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 560d37c..07cd09a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -41,10 +41,11 @@ matrix: - | # install_test is a helper to create folded reports (From Symfony) install_test () { - local title="./tests/install.sh \"$1\" \"$2\" \"$3\"" + local title="$1 \"$2\" ..." local fold=$(date +%s%N) echo -e "travis_fold:start:$fold" echo -e "\\e[1;34m$title\\e[0m" + echo "./tests/install.sh \"$1\" \"$2\" \"$3\"" ./tests/install.sh "$1" "$2" "$3" 2>&1 local ok=$? (exit $ok) && From ae1671e39bd8f796a0c21a56a972948fc1e6d3b3 Mon Sep 17 00:00:00 2001 From: Nyholm Date: Fri, 27 Dec 2019 20:42:02 +0100 Subject: [PATCH 4/4] Fixed broken build --- .travis.yml | 2 +- src/Strategy/CommonClassesStrategy.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 07cd09a..1b55738 100644 --- a/.travis.yml +++ b/.travis.yml @@ -57,7 +57,7 @@ matrix: script: # Test that we find Guzzle - - install_test "will-find" "Http\Discovery\HttpClientDiscovery::find();" "php-http/guzzle6-adapter" + - install_test will-find "Http\Discovery\HttpClientDiscovery::find();" "php-http/guzzle6-adapter" # Test that we find a client with Symfony and Guzzle PSR-7 - 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" # We should fail if we dont have php-http/message-factory or PSR-17 diff --git a/src/Strategy/CommonClassesStrategy.php b/src/Strategy/CommonClassesStrategy.php index 55f4829..ccadaf9 100644 --- a/src/Strategy/CommonClassesStrategy.php +++ b/src/Strategy/CommonClassesStrategy.php @@ -74,7 +74,7 @@ final class CommonClassesStrategy implements DiscoveryStrategy ['class' => React::class, 'condition' => React::class], ], HttpClient::class => [ - ['class' => SymfonyHttplug::class, 'condition' => [SymfonyHttplug::class, RequestFactory::class]], + ['class' => SymfonyHttplug::class, 'condition' => [SymfonyHttplug::class, RequestFactory::class, Psr17RequestFactory::class]], ['class' => Guzzle6::class, 'condition' => Guzzle6::class], ['class' => Guzzle5::class, 'condition' => Guzzle5::class], ['class' => Curl::class, 'condition' => Curl::class],