Skip to content

Commit 2ffeeaa

Browse files
authored
Merge pull request php-curl-class#534 from zachborboa/docker
Add ability to run unit tests in containers
2 parents b794824 + 860c9ff commit 2ffeeaa

28 files changed

+296
-2
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,12 @@ To run tests:
349349
$ composer update
350350
$ ./tests/run.sh
351351

352+
To run all container tests:
353+
354+
$ ./tests/test_all.sh
355+
352356
### Contribute
357+
353358
1. Check for open issues or open a new issue to start a discussion around a bug or feature.
354359
1. Fork the repository on GitHub to start making your changes.
355360
1. Write one or more tests for the new feature or that expose the bug.

tests/PHPCurlClass/PHPCurlClassTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1106,7 +1106,7 @@ public function testError()
11061106
$test->curl->get(Test::ERROR_URL);
11071107
$this->assertTrue($test->curl->error);
11081108
$this->assertTrue($test->curl->curlError);
1109-
$possible_errors = array(CURLE_SEND_ERROR, CURLE_OPERATION_TIMEOUTED, CURLE_COULDNT_CONNECT);
1109+
$possible_errors = array(CURLE_SEND_ERROR, CURLE_OPERATION_TIMEOUTED, CURLE_COULDNT_CONNECT, CURLE_GOT_NOTHING);
11101110
$this->assertTrue(
11111111
in_array($test->curl->errorCode, $possible_errors, true),
11121112
'errorCode: ' . $test->curl->errorCode

tests/PHPCurlClass/PHPMultiCurlClassTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -601,7 +601,8 @@ public function testMultiCurlCallbackError()
601601
\PHPUnit\Framework\Assert::assertTrue($instance->error);
602602
\PHPUnit\Framework\Assert::assertTrue($instance->curlError);
603603
\PHPUnit\Framework\Assert::assertFalse($instance->httpError);
604-
$possible_errors = array(CURLE_SEND_ERROR, CURLE_OPERATION_TIMEOUTED, CURLE_COULDNT_CONNECT);
604+
$possible_errors = array(
605+
CURLE_SEND_ERROR, CURLE_OPERATION_TIMEOUTED, CURLE_COULDNT_CONNECT, CURLE_GOT_NOTHING);
605606
\PHPUnit\Framework\Assert::assertTrue(
606607
in_array($instance->errorCode, $possible_errors, true),
607608
'errorCode: ' . $instance->errorCode

tests/dockerfiles/php56/1_build.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Build an image.
2+
docker build --tag="php-curl-class/php56" .

tests/dockerfiles/php56/2_start.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Run image to create container.
2+
3+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
4+
set -x
5+
cd "${SCRIPT_DIR}/../../.."
6+
project_dir="${PWD}"
7+
8+
docker start "php56" ||
9+
docker run \
10+
--detach \
11+
--interactive \
12+
--mount "type=bind,src=${project_dir},dst=/data,readonly=true" \
13+
--name="php56" \
14+
--tty \
15+
"php-curl-class/php56"

tests/dockerfiles/php56/3_test.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Run tests inside container.
2+
command=$(cat <<-END
3+
mkdir --parents "/tmp/php-curl-class" &&
4+
rsync --exclude=".git" --exclude="vendor" --links --recursive "/data/" "/tmp/php-curl-class/" &&
5+
cd "/tmp/php-curl-class" &&
6+
export TRAVIS_PHP_VERSION="5.6" &&
7+
(
8+
[ ! -f "/tmp/.composer_updated" ] &&
9+
composer --no-interaction update &&
10+
touch "/tmp/.composer_updated" ||
11+
exit 0
12+
) &&
13+
bash "tests/before_script.sh" &&
14+
bash "tests/script.sh"
15+
END
16+
)
17+
docker exec --interactive --tty "php56" sh -c "${command}"

tests/dockerfiles/php56/4_stop.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Stop container.
2+
3+
docker stop "php56"

tests/dockerfiles/php56/Dockerfile

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
FROM php:5.6-cli
2+
ENV DEBIAN_FRONTEND noninteractive
3+
4+
RUN apt-get --assume-yes --quiet update
5+
6+
RUN apt-get --assume-yes --quiet install git && \
7+
apt-get --assume-yes --quiet install libpng-dev && \
8+
apt-get --assume-yes --quiet install zip
9+
10+
RUN curl --silent --show-error "https://getcomposer.org/installer" | php && \
11+
mv "composer.phar" "/usr/local/bin/composer" && \
12+
composer global require --no-interaction "phpunit/phpunit"
13+
14+
RUN docker-php-ext-configure gd && \
15+
docker-php-ext-install gd
16+
17+
ENV PATH /root/.composer/vendor/bin:$PATH
18+
CMD ["bash"]
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Run image to create container and attach to it.
2+
3+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
4+
set -x
5+
cd "${SCRIPT_DIR}/../../.."
6+
project_dir="${PWD}"
7+
8+
docker run \
9+
--interactive \
10+
--mount "type=bind,src=${project_dir},dst=/data,readonly=true" \
11+
--name="php56" \
12+
--rm \
13+
--tty \
14+
"php-curl-class/php56" /bin/bash

tests/dockerfiles/php70/1_build.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Build an image.
2+
docker build --tag="php-curl-class/php70" .

0 commit comments

Comments
 (0)