From 144bc623a73f2e4134aaf160d508c5684ba744b2 Mon Sep 17 00:00:00 2001 From: Damiano Improta Date: Tue, 16 Dec 2025 14:00:57 +0100 Subject: [PATCH 1/2] docker file & entrypoint --- Dockerfile | 23 +++++++++++++++++++++ entrypoint.sh | 8 +++++++ tests/EffectivePrimitiveTypeRequestTest.php | 4 ++-- tests/entrypoint.php | 1 + 4 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 Dockerfile create mode 100644 entrypoint.sh diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..1358ba6 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,23 @@ +FROM php:8.4-apache + +RUN apt-get update && apt-get install zip unzip -y + + +COPY --from=composer:2.8 /usr/bin/composer /usr/bin/composer +COPY ./src ./src +COPY ./tests ./tests +COPY composer.* ./ +COPY .php-cs-fixer.dist.php ./ + +RUN composer install --no-interaction --no-scripts --no-autoloader --prefer-dist + + +RUN composer dump-autoload --optimize + +COPY ./entrypoint.sh /usr/local/bin/ +RUN chmod +x /usr/local/bin/entrypoint.sh + +ENTRYPOINT ["entrypoint.sh"] + + +CMD apache2-foreground \ No newline at end of file diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 0000000..cb67365 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,8 @@ +#!/bin/bash + + +composer install + +php vendor/bin/phpunit tests/EffectivePrimitiveTypeTest.php +php vendor/bin/phpunit tests/EffectivePrimitiveTypeRequestTest.php + \ No newline at end of file diff --git a/tests/EffectivePrimitiveTypeRequestTest.php b/tests/EffectivePrimitiveTypeRequestTest.php index f906804..ae3181c 100644 --- a/tests/EffectivePrimitiveTypeRequestTest.php +++ b/tests/EffectivePrimitiveTypeRequestTest.php @@ -54,7 +54,7 @@ private function callEntrypoint(string $httpMethodString, string $inputParameter { $httpMethod = strtoupper($httpMethodString); $ch = curl_init(); - $url = 'http://127.0.0.1:8080/entrypoint.php'; + $url = 'http://127.0.0.1/tests/entrypoint.php'; $options = [ CURLOPT_RETURNTRANSFER => true, @@ -74,6 +74,6 @@ private function callEntrypoint(string $httpMethodString, string $inputParameter curl_setopt_array($ch, $options); $response = curl_exec($ch); - return json_encode($response); + return json_decode($response,true); } } diff --git a/tests/entrypoint.php b/tests/entrypoint.php index bc08f56..6dbd03c 100644 --- a/tests/entrypoint.php +++ b/tests/entrypoint.php @@ -1,5 +1,6 @@ Date: Mon, 22 Dec 2025 15:48:29 +0100 Subject: [PATCH 2/2] add test with docker --- Dockerfile | 7 ++---- README.md | 7 ++++++ docker-compose.yml | 28 +++++++++++++++++++++ entrypoint.sh | 1 - tests/EffectivePrimitiveTypeRequestTest.php | 2 +- 5 files changed, 38 insertions(+), 7 deletions(-) create mode 100644 docker-compose.yml diff --git a/Dockerfile b/Dockerfile index 1358ba6..c498126 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,8 +1,8 @@ -FROM php:8.4-apache +FROM php:8.4-cli RUN apt-get update && apt-get install zip unzip -y - +WORKDIR /app COPY --from=composer:2.8 /usr/bin/composer /usr/bin/composer COPY ./src ./src COPY ./tests ./tests @@ -18,6 +18,3 @@ COPY ./entrypoint.sh /usr/local/bin/ RUN chmod +x /usr/local/bin/entrypoint.sh ENTRYPOINT ["entrypoint.sh"] - - -CMD apache2-foreground \ No newline at end of file diff --git a/README.md b/README.md index 5154add..ed3da0a 100644 --- a/README.md +++ b/README.md @@ -284,9 +284,16 @@ Retrieves and types a value from `$_GET`. ## Testing +If you have a development environment set up with PHP 8.4, set the host file ‘endpoint-test’ to point to 127.0.0.1 and run + ```bash composer test ``` +Otherwise, use the docker found in the project that sets up the environment and runs the test suite, executing + +```bash +docker compose run --rm --remove-orphans --build do-tests && docker compose down +``` ## License diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..4b8c3b7 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,28 @@ +services: + do-tests: + build: + context: . + volumes: + - ./src:/app/src + - ./tests:/app/tests + - ./vendor:/app/vendor + - ./composer.json:/app/composer.json + - ./composer.lock:/app/composer.lock + networks: + - typeidentifier-network + depends_on: + endpoint-test: + condition: service_started + endpoint-test: + image: php:8.4-apache + volumes: + - ./src:/var/www/html/src + - ./tests:/var/www/html/tests + - ./vendor:/var/www/html/vendor + - ./composer.json:/var/www/html/composer.json + - ./composer.lock:/var/www/html/composer.lock + networks: + - typeidentifier-network + +networks: + typeidentifier-network: \ No newline at end of file diff --git a/entrypoint.sh b/entrypoint.sh index cb67365..d9b1d59 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,6 +1,5 @@ #!/bin/bash - composer install php vendor/bin/phpunit tests/EffectivePrimitiveTypeTest.php diff --git a/tests/EffectivePrimitiveTypeRequestTest.php b/tests/EffectivePrimitiveTypeRequestTest.php index ae3181c..8357da3 100644 --- a/tests/EffectivePrimitiveTypeRequestTest.php +++ b/tests/EffectivePrimitiveTypeRequestTest.php @@ -54,7 +54,7 @@ private function callEntrypoint(string $httpMethodString, string $inputParameter { $httpMethod = strtoupper($httpMethodString); $ch = curl_init(); - $url = 'http://127.0.0.1/tests/entrypoint.php'; + $url = 'http://endpoint-test/tests/entrypoint.php'; $options = [ CURLOPT_RETURNTRANSFER => true,