diff --git a/composer.json b/composer.json index 1a7446c..7e68dea 100644 --- a/composer.json +++ b/composer.json @@ -12,7 +12,7 @@ } ], "require": { - "php": ">=7.2", + "php": ">=7.3", "psr/http-factory": "~1.0", "psr/http-message": "~1.0", "psr/http-server-handler": "~1.0", diff --git a/composer.lock b/composer.lock index 6f27dbc..6c47046 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "041c27e394aba3e5c3bf6cbe8751f845", + "content-hash": "bc05598d49e39b0082767d94ecb5bd4d", "packages": [ { "name": "psr/http-factory", @@ -4652,7 +4652,7 @@ "prefer-stable": false, "prefer-lowest": false, "platform": { - "php": ">=7.2" + "php": ">=7.3" }, "platform-dev": [], "plugin-api-version": "1.1.0" diff --git a/docker-compose.yml b/docker-compose.yml index 97e3292..7dabe4b 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -25,8 +25,3 @@ services: volumes: - .:/usr/local/src/wellrested - ./docker/nginx/site.conf:/etc/nginx/conf.d/default.conf - - php-fpm: - image: php:7.4-fpm - volumes: - - .:/usr/local/src/wellrested diff --git a/docker/nginx/site.conf b/docker/nginx/site.conf index 453d502..ba76d7e 100644 --- a/docker/nginx/site.conf +++ b/docker/nginx/site.conf @@ -26,7 +26,7 @@ server { # PHP location ~ \.php$ { include fastcgi_params; - fastcgi_pass php-fpm:9000; + fastcgi_pass php:9000; fastcgi_index index.php; fastcgi_buffers 8 8k; fastcgi_buffer_size 16k; diff --git a/docker/php/Dockerfile b/docker/php/Dockerfile index aeae46a..9589150 100644 --- a/docker/php/Dockerfile +++ b/docker/php/Dockerfile @@ -1,4 +1,4 @@ -FROM php:7.4-cli +FROM php:7.3-fpm RUN DEBIAN_FRONTEND=noninteractive \ apt-get update && \ @@ -27,20 +27,18 @@ RUN mkdir /usr/local/src/wellrested && \ chown -R www-data:www-data /usr/local/src/wellrested && \ chown -R www-data:www-data /var/www -COPY ./src /usr/local/src/wellrested/src -COPY ./test /usr/local/src/wellrested/test -COPY ./composer.* /usr/local/src/wellrested/ -COPY ./phpunit.xml.dist /usr/local/src/wellrested/ +# Copy entrypoint script +COPY docker/php/entrypoint /usr/local/bin # Add symlinks for php-cs-fixer, phpunit, and psalm for easier running RUN ln -s /usr/local/src/wellrested/vendor/bin/php-cs-fixer /usr/local/bin/php-cs-fixer RUN ln -s /usr/local/src/wellrested/vendor/bin/phpunit /usr/local/bin/phpunit RUN ln -s /usr/local/src/wellrested/vendor/bin/psalm /usr/local/bin/psalm +ENTRYPOINT ["entrypoint"] + +CMD ["php-fpm"] + WORKDIR /usr/local/src/wellrested -USER www-data - -ENTRYPOINT ["dumb-init", "--"] - -RUN composer install +USER www-data \ No newline at end of file diff --git a/docker/php/entrypoint b/docker/php/entrypoint new file mode 100755 index 0000000..67bca32 --- /dev/null +++ b/docker/php/entrypoint @@ -0,0 +1,10 @@ +#!/usr/bin/env bash + +# Run CLI commands with dumb-init to allow better signal handling. +# Run PHP-FPM as PID 1. +# https://engineeringblog.yelp.com/2016/01/dumb-init-an-init-for-docker.html +if [ "$1" == 'php-fpm' ] ; then + exec php-fpm +else + exec dumb-init -- "$@" +fi diff --git a/tests/Message/StreamTest.php b/tests/Message/StreamTest.php index b70b920..72ef2ef 100644 --- a/tests/Message/StreamTest.php +++ b/tests/Message/StreamTest.php @@ -15,8 +15,9 @@ class StreamTest extends TestCase protected function setUp(): void { $this->resource = fopen('php://memory', 'w+'); - $this->resourceDevNull = fopen('/dev/null', 'r'); + $this->resourceDevNull = fopen('/dev/zero', 'r'); fwrite($this->resource, $this->content); + StreamHelper::$fail = false; } protected function tearDown(): void @@ -105,7 +106,8 @@ class StreamTest extends TestCase public function testTellThrowsRuntimeExceptionWhenUnableToReadStreamPosition(): void { - $stream = new Stream($this->resourceDevNull); + StreamHelper::$fail = true; + $stream = new Stream($this->resource); $this->expectException(RuntimeException::class); $stream->tell(); } @@ -135,7 +137,8 @@ class StreamTest extends TestCase public function testSeekThrowsRuntimeExceptionWhenUnableToSeek(): void { - $stream = new Stream($this->resourceDevNull); + StreamHelper::$fail = true; + $stream = new Stream($this->resource); $this->expectException(RuntimeException::class); $stream->seek(10); } @@ -150,7 +153,8 @@ class StreamTest extends TestCase public function testRewindThrowsRuntimeExceptionWhenUnableToRewind(): void { - $stream = new Stream($this->resourceDevNull); + StreamHelper::$fail = true; + $stream = new Stream($this->resource); $this->expectException(RuntimeException::class); $stream->rewind(); } @@ -384,3 +388,37 @@ class StreamTest extends TestCase $this->assertNull($stream->getMetadata()); } } + +// ----------------------------------------------------------------------------- + +// Declare functions in this namespace so the class under test will use these +// instead of the internal global functions during testing. + +class StreamHelper +{ + public static $fail = false; +} + +function fseek($resource, $offset, $whence = SEEK_SET) +{ + if (StreamHelper::$fail) { + return -1; + } + return \fseek($resource, $offset, $whence); +} + +function ftell($resource) +{ + if (StreamHelper::$fail) { + return false; + } + return \ftell($resource); +} + +function rewind($resource) +{ + if (StreamHelper::$fail) { + return false; + } + return \rewind($resource); +}