diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..c498126 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,20 @@ +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 +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"] 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 new file mode 100644 index 0000000..d9b1d59 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,7 @@ +#!/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..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:8080/entrypoint.php'; + $url = 'http://endpoint-test/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 @@