diff --git a/.travis.yml b/.travis.yml index 92acfab..1b55738 100644 --- a/.travis.yml +++ b/.travis.yml @@ -25,8 +25,8 @@ matrix: include: - 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 @@ -35,6 +35,38 @@ 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="$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) && + 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/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], diff --git a/tests/install.sh b/tests/install.sh new file mode 100755 index 0000000..1f7480f --- /dev/null +++ b/tests/install.sh @@ -0,0 +1,52 @@ +#!/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 "" +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 + exit 0 +fi + +echo "We did find a class but we were not supposed to" +echo "" +exit 1