Merge pull request #534 from zachborboa/docker

Add ability to run unit tests in containers
This commit is contained in:
Zach Borboa
2018-07-29 00:44:26 -07:00
committed by GitHub
28 changed files with 296 additions and 2 deletions
+5
View File
@@ -349,7 +349,12 @@ To run tests:
$ composer update
$ ./tests/run.sh
To run all container tests:
$ ./tests/test_all.sh
### Contribute
1. Check for open issues or open a new issue to start a discussion around a bug or feature.
1. Fork the repository on GitHub to start making your changes.
1. Write one or more tests for the new feature or that expose the bug.
+1 -1
View File
@@ -1106,7 +1106,7 @@ class CurlTest extends \PHPUnit\Framework\TestCase
$test->curl->get(Test::ERROR_URL);
$this->assertTrue($test->curl->error);
$this->assertTrue($test->curl->curlError);
$possible_errors = array(CURLE_SEND_ERROR, CURLE_OPERATION_TIMEOUTED, CURLE_COULDNT_CONNECT);
$possible_errors = array(CURLE_SEND_ERROR, CURLE_OPERATION_TIMEOUTED, CURLE_COULDNT_CONNECT, CURLE_GOT_NOTHING);
$this->assertTrue(
in_array($test->curl->errorCode, $possible_errors, true),
'errorCode: ' . $test->curl->errorCode
+2 -1
View File
@@ -601,7 +601,8 @@ class MultiCurlTest extends \PHPUnit\Framework\TestCase
\PHPUnit\Framework\Assert::assertTrue($instance->error);
\PHPUnit\Framework\Assert::assertTrue($instance->curlError);
\PHPUnit\Framework\Assert::assertFalse($instance->httpError);
$possible_errors = array(CURLE_SEND_ERROR, CURLE_OPERATION_TIMEOUTED, CURLE_COULDNT_CONNECT);
$possible_errors = array(
CURLE_SEND_ERROR, CURLE_OPERATION_TIMEOUTED, CURLE_COULDNT_CONNECT, CURLE_GOT_NOTHING);
\PHPUnit\Framework\Assert::assertTrue(
in_array($instance->errorCode, $possible_errors, true),
'errorCode: ' . $instance->errorCode
+2
View File
@@ -0,0 +1,2 @@
# Build an image.
docker build --tag="php-curl-class/php56" .
+15
View File
@@ -0,0 +1,15 @@
# Run image to create container.
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
set -x
cd "${SCRIPT_DIR}/../../.."
project_dir="${PWD}"
docker start "php56" ||
docker run \
--detach \
--interactive \
--mount "type=bind,src=${project_dir},dst=/data,readonly=true" \
--name="php56" \
--tty \
"php-curl-class/php56"
+17
View File
@@ -0,0 +1,17 @@
# Run tests inside container.
command=$(cat <<-END
mkdir --parents "/tmp/php-curl-class" &&
rsync --exclude=".git" --exclude="vendor" --links --recursive "/data/" "/tmp/php-curl-class/" &&
cd "/tmp/php-curl-class" &&
export TRAVIS_PHP_VERSION="5.6" &&
(
[ ! -f "/tmp/.composer_updated" ] &&
composer --no-interaction update &&
touch "/tmp/.composer_updated" ||
exit 0
) &&
bash "tests/before_script.sh" &&
bash "tests/script.sh"
END
)
docker exec --interactive --tty "php56" sh -c "${command}"
+3
View File
@@ -0,0 +1,3 @@
# Stop container.
docker stop "php56"
+18
View File
@@ -0,0 +1,18 @@
FROM php:5.6-cli
ENV DEBIAN_FRONTEND noninteractive
RUN apt-get --assume-yes --quiet update
RUN apt-get --assume-yes --quiet install git && \
apt-get --assume-yes --quiet install libpng-dev && \
apt-get --assume-yes --quiet install zip
RUN curl --silent --show-error "https://getcomposer.org/installer" | php && \
mv "composer.phar" "/usr/local/bin/composer" && \
composer global require --no-interaction "phpunit/phpunit"
RUN docker-php-ext-configure gd && \
docker-php-ext-install gd
ENV PATH /root/.composer/vendor/bin:$PATH
CMD ["bash"]
+14
View File
@@ -0,0 +1,14 @@
# Run image to create container and attach to it.
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
set -x
cd "${SCRIPT_DIR}/../../.."
project_dir="${PWD}"
docker run \
--interactive \
--mount "type=bind,src=${project_dir},dst=/data,readonly=true" \
--name="php56" \
--rm \
--tty \
"php-curl-class/php56" /bin/bash
+2
View File
@@ -0,0 +1,2 @@
# Build an image.
docker build --tag="php-curl-class/php70" .
+15
View File
@@ -0,0 +1,15 @@
# Run image to create container.
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
set -x
cd "${SCRIPT_DIR}/../../.."
project_dir="${PWD}"
docker start "php70" ||
docker run \
--detach \
--interactive \
--mount "type=bind,src=${project_dir},dst=/data,readonly=true" \
--name="php70" \
--tty \
"php-curl-class/php70"
+17
View File
@@ -0,0 +1,17 @@
# Run tests inside container.
command=$(cat <<-END
mkdir --parents "/tmp/php-curl-class" &&
rsync --exclude=".git" --exclude="vendor" --links --recursive "/data/" "/tmp/php-curl-class/" &&
cd "/tmp/php-curl-class" &&
export TRAVIS_PHP_VERSION="7.0" &&
(
[ ! -f "/tmp/.composer_updated" ] &&
composer --no-interaction update &&
touch "/tmp/.composer_updated" ||
exit 0
) &&
bash "tests/before_script.sh" &&
bash "tests/script.sh"
END
)
docker exec --interactive --tty "php70" sh -c "${command}"
+3
View File
@@ -0,0 +1,3 @@
# Stop container.
docker stop "php70"
+18
View File
@@ -0,0 +1,18 @@
FROM php:7.0-cli
ENV DEBIAN_FRONTEND noninteractive
RUN apt-get --assume-yes --quiet update
RUN apt-get --assume-yes --quiet install git && \
apt-get --assume-yes --quiet install libpng-dev && \
apt-get --assume-yes --quiet install zip
RUN curl --silent --show-error "https://getcomposer.org/installer" | php && \
mv "composer.phar" "/usr/local/bin/composer" && \
composer global require --no-interaction "phpunit/phpunit"
RUN docker-php-ext-configure gd && \
docker-php-ext-install gd
ENV PATH /root/.composer/vendor/bin:$PATH
CMD ["bash"]
+14
View File
@@ -0,0 +1,14 @@
# Run image to create container and attach to it.
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
set -x
cd "${SCRIPT_DIR}/../../.."
project_dir="${PWD}"
docker run \
--interactive \
--mount "type=bind,src=${project_dir},dst=/data,readonly=true" \
--name="php70" \
--rm \
--tty \
"php-curl-class/php70" /bin/bash
+2
View File
@@ -0,0 +1,2 @@
# Build an image.
docker build --tag="php-curl-class/php71" .
+15
View File
@@ -0,0 +1,15 @@
# Run image to create container.
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
set -x
cd "${SCRIPT_DIR}/../../.."
project_dir="${PWD}"
docker start "php71" ||
docker run \
--detach \
--interactive \
--mount "type=bind,src=${project_dir},dst=/data,readonly=true" \
--name="php71" \
--tty \
"php-curl-class/php71"
+17
View File
@@ -0,0 +1,17 @@
# Run tests inside container.
command=$(cat <<-END
mkdir --parents "/tmp/php-curl-class" &&
rsync --exclude=".git" --exclude="vendor" --links --recursive "/data/" "/tmp/php-curl-class/" &&
cd "/tmp/php-curl-class" &&
export TRAVIS_PHP_VERSION="7.1" &&
(
[ ! -f "/tmp/.composer_updated" ] &&
composer --no-interaction update &&
touch "/tmp/.composer_updated" ||
exit 0
) &&
bash "tests/before_script.sh" &&
bash "tests/script.sh"
END
)
docker exec --interactive --tty "php71" sh -c "${command}"
+3
View File
@@ -0,0 +1,3 @@
# Stop container.
docker stop "php71"
+18
View File
@@ -0,0 +1,18 @@
FROM php:7.1-cli
ENV DEBIAN_FRONTEND noninteractive
RUN apt-get --assume-yes --quiet update
RUN apt-get --assume-yes --quiet install git && \
apt-get --assume-yes --quiet install libpng-dev && \
apt-get --assume-yes --quiet install zip
RUN curl --silent --show-error "https://getcomposer.org/installer" | php && \
mv "composer.phar" "/usr/local/bin/composer" && \
composer global require --no-interaction "phpunit/phpunit"
RUN docker-php-ext-configure gd && \
docker-php-ext-install gd
ENV PATH /root/.composer/vendor/bin:$PATH
CMD ["bash"]
+14
View File
@@ -0,0 +1,14 @@
# Run image to create container and attach to it.
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
set -x
cd "${SCRIPT_DIR}/../../.."
project_dir="${PWD}"
docker run \
--interactive \
--mount "type=bind,src=${project_dir},dst=/data,readonly=true" \
--name="php71" \
--rm \
--tty \
"php-curl-class/php71" /bin/bash
+2
View File
@@ -0,0 +1,2 @@
# Build an image.
docker build --tag="php-curl-class/php72" .
+15
View File
@@ -0,0 +1,15 @@
# Run image to create container.
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
set -x
cd "${SCRIPT_DIR}/../../.."
project_dir="${PWD}"
docker start "php72" ||
docker run \
--detach \
--interactive \
--mount "type=bind,src=${project_dir},dst=/data,readonly=true" \
--name="php72" \
--tty \
"php-curl-class/php72"
+17
View File
@@ -0,0 +1,17 @@
# Run tests inside container.
command=$(cat <<-END
mkdir --parents "/tmp/php-curl-class" &&
rsync --exclude=".git" --exclude="vendor" --links --recursive "/data/" "/tmp/php-curl-class/" &&
cd "/tmp/php-curl-class" &&
export TRAVIS_PHP_VERSION="7.2" &&
(
[ ! -f "/tmp/.composer_updated" ] &&
composer --no-interaction update &&
touch "/tmp/.composer_updated" ||
exit 0
) &&
bash "tests/before_script.sh" &&
bash "tests/script.sh"
END
)
docker exec --interactive --tty "php72" sh -c "${command}"
+3
View File
@@ -0,0 +1,3 @@
# Stop container.
docker stop "php72"
+18
View File
@@ -0,0 +1,18 @@
FROM php:7.2-cli
ENV DEBIAN_FRONTEND noninteractive
RUN apt-get --assume-yes --quiet update
RUN apt-get --assume-yes --quiet install git && \
apt-get --assume-yes --quiet install libpng-dev && \
apt-get --assume-yes --quiet install zip
RUN curl --silent --show-error "https://getcomposer.org/installer" | php && \
mv "composer.phar" "/usr/local/bin/composer" && \
composer global require --no-interaction "phpunit/phpunit"
RUN docker-php-ext-configure gd && \
docker-php-ext-install gd
ENV PATH /root/.composer/vendor/bin:$PATH
CMD ["bash"]
+14
View File
@@ -0,0 +1,14 @@
# Run image to create container and attach to it.
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
set -x
cd "${SCRIPT_DIR}/../../.."
project_dir="${PWD}"
docker run \
--interactive \
--mount "type=bind,src=${project_dir},dst=/data,readonly=true" \
--name="php72" \
--rm \
--tty \
"php-curl-class/php72" /bin/bash
+12
View File
@@ -0,0 +1,12 @@
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "${SCRIPT_DIR}"
for d in "dockerfiles/"* ; do
echo "Running ${d}" &&
pushd "${d}" &&
bash "1_build.sh" &&
bash "2_start.sh" &&
bash "3_test.sh" &&
bash "4_stop.sh" &&
popd
done