Skip to content

Commit

Permalink
Merge pull request #157 from Nyholm/install-test
Browse files Browse the repository at this point in the history
Added small script to test installation on with different dependencies
  • Loading branch information
dbu authored Dec 27, 2019
2 parents 16a3327 + ae1671e commit e95c211
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 3 deletions.
36 changes: 34 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/Strategy/CommonClassesStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
52 changes: 52 additions & 0 deletions tests/install.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit e95c211

Please sign in to comment.