Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
28 changes: 28 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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:
7 changes: 7 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

composer install

php vendor/bin/phpunit tests/EffectivePrimitiveTypeTest.php
php vendor/bin/phpunit tests/EffectivePrimitiveTypeRequestTest.php

4 changes: 2 additions & 2 deletions tests/EffectivePrimitiveTypeRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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);
}
}
1 change: 1 addition & 0 deletions tests/entrypoint.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

require_once __DIR__.'/../vendor/autoload.php';
header('Content-type:application/json');

$epti = new TypeIdentifier\Service\EffectivePrimitiveTypeIdentifierService();
Expand Down