diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..8ed46e5 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,15 @@ +FROM php:8.4-cli + +# zip: ZipArchive in JSignPdfRuntimeService | sockets: donatj/mock-webserver in the tests +ADD https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/ +RUN chmod uga+x /usr/local/bin/install-php-extensions && sync \ + && install-php-extensions \ + sockets \ + zip \ + @composer \ + && rm /usr/local/bin/install-php-extensions + +# PharData exceeds the default 128M just to open the JRE tarball +RUN echo 'memory_limit=512M' > /usr/local/etc/php/conf.d/app.ini + +WORKDIR /app diff --git a/README.md b/README.md index 68dc638..76338a9 100644 --- a/README.md +++ b/README.md @@ -64,5 +64,31 @@ Change parameters of JSignPDF: $param->setJSignParameters("-a -kst PKCS12 -ts https://freetsa.org/tsr"); ``` +## Docker Environment + +The repository ships a minimal Docker setup (`Dockerfile` and `compose.yml`) with the extensions +the test suite needs. + +```bash +docker compose build +docker compose run --rm php composer install +``` + +Checks, the same ones the CI runs: + +```bash +docker compose run --rm php composer run test:unit +docker compose run --rm php composer run cs:check # cs:fix to apply the formatting +docker compose run --rm php composer run psalm +``` + +### Usage example + +To sign a PDF end to end. It downloads the JRE and the JSignPdf jar into `tmp/` on the first run: + +```bash +docker compose run --rm php php example/index.php +``` + ## Credits - [Jeidison Farias](https://github.com/jeidison) diff --git a/compose.yml b/compose.yml new file mode 100644 index 0000000..82c0200 --- /dev/null +++ b/compose.yml @@ -0,0 +1,9 @@ +services: + php: + build: . + # export HOST_UID/HOST_GID if yours are not 1000, so the files it writes are yours (see: id -u; id -g) + user: "${HOST_UID:-1000}:${HOST_GID:-1000}" + environment: + COMPOSER_HOME: ${COMPOSER_HOME:-/tmp/composer} + volumes: + - .:/app diff --git a/tests/Runtime/JavaRuntimeServiceTest.php b/tests/Runtime/JavaRuntimeServiceTest.php index 8f16ba0..a86e88f 100644 --- a/tests/Runtime/JavaRuntimeServiceTest.php +++ b/tests/Runtime/JavaRuntimeServiceTest.php @@ -170,6 +170,7 @@ public function testGetPathWithDownloadUrlWithInvalidVersion(): void $baseUrl = $server->getServerRoot(); $url = $baseUrl . '/OpenJDK21U-jre_x64_linux_hotspot_21.0.8_9.tar.gz'; $jsignParam->setJavaDownloadUrl($url); + $jsignParam->setJavaPath($this->testTmpDir . '/bin/java'); $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessageMatches('/cannot be extracted/');