Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could we add this as a bash file to tests folder, or .travis folder? no big deal, but it seems a bit much for the travis configuration file

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont think so. Im not sure how you can "export" a function in bash/travis.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah i see, bash function, not bash script. i guess thats fine then. maybe bash source-ing the file would work, but i will merge as is and tag another patch release


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