From 31ef16ba5085c1e6a580817c0665435e785f4eaf Mon Sep 17 00:00:00 2001 From: CJ Campbell Date: Tue, 10 Jan 2023 09:48:26 -0700 Subject: [PATCH] Make it easier to run the unit tests --- .gitignore | 1 + README.md | 3 +++ phpunit.xml | 5 +++++ test.Dockerfile | 16 ++++++++++++++++ test.sh | 25 +++++++++++++++++++++++++ 5 files changed, 50 insertions(+) create mode 100644 test.Dockerfile create mode 100755 test.sh diff --git a/.gitignore b/.gitignore index 987e2a2..e96516b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ composer.lock vendor +.phpunit.result.cache diff --git a/README.md b/README.md index 916bcbb..e276bad 100644 --- a/README.md +++ b/README.md @@ -58,6 +58,9 @@ register_shutdown_function(function() { }) ``` +## Testing +Have docker installed, and run `./test.sh` + ## Instrumentation for Tracing Since this tracer is fully compliant with the OpenTracing API 1.0, all code instrumentation should only use the API itself, as descriped in the [opentracing-php](https://github.com/opentracing/opentracing-php) documentation. diff --git a/phpunit.xml b/phpunit.xml index 52c4f08..f5473d3 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -19,4 +19,9 @@ timeoutForMediumTests="10" timeoutForLargeTests="60" verbose="false"> + + + ./tests + + \ No newline at end of file diff --git a/test.Dockerfile b/test.Dockerfile new file mode 100644 index 0000000..a3d4808 --- /dev/null +++ b/test.Dockerfile @@ -0,0 +1,16 @@ +FROM php:8.0.26-alpine3.16 + +WORKDIR /bin + +# install the sockets php extension +RUN docker-php-ext-install sockets + +# install composer +RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" && \ + php -r "if (hash_file('sha384', 'composer-setup.php') === '55ce33d7678c5a611085589f1f3ddf8b3c52d662cd01d4ba75c0ee0459970c2200a51f492d557530c71c15d8dba01eae') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;" && \ + php composer-setup.php && \ + php -r "unlink('composer-setup.php');" + +WORKDIR /app + +ENTRYPOINT ["php", "/bin/composer.phar"] \ No newline at end of file diff --git a/test.sh b/test.sh new file mode 100755 index 0000000..ffdb8a6 --- /dev/null +++ b/test.sh @@ -0,0 +1,25 @@ +#!/bin/sh + +set -e # Fail fast + +LOCAL_DIR=$(cd "$(dirname "$BASH_SOURCE")" && pwd) +BUILDER_IMAGE=jaeger-client-php-tester + +if [[ "$(docker images -q $BUILDER_IMAGE 2> /dev/null)" == "" ]]; then + echo "--Creating builder image" + docker build --no-cache --file test.Dockerfile --tag $BUILDER_IMAGE . +fi + +if [ ! -d "$LOCAL_DIR/vendor" ]; then + echo "--No vendor directory detected. Running a composer install" + docker run --rm \ + --volume $LOCAL_DIR:/app \ + $BUILDER_IMAGE \ + install +fi + +echo "--Running tests" +docker run --rm \ + --volume $LOCAL_DIR:/app \ + $BUILDER_IMAGE \ + test