diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000000000000000000000000000000000000..73427dc38cd0e2ef1cf31b59a92bfd3eb1c83f5a --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,18 @@ +# Changelog + +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## [2.0.0] - 2023-10-21 + +- Require PHP 8.x and PHPUnit 10.x #47 + +## [1.1.0] - 2023-10-21 + +- Final release that supports PHP 7.x. + +## [1.0.0] - 2023-10-10 + +- Add tests for streams #39 diff --git a/composer.json b/composer.json index 4d77920b748c593793f31c453f457f8424840140..2e628e70183f38696f98ed197c4da6f367b3c782 100644 --- a/composer.json +++ b/composer.json @@ -12,13 +12,13 @@ "authors": [ { "name": "PHP-FIG", - "homepage": "http://www.php-fig.org/" + "homepage": "https://www.php-fig.org/" } ], "require": { - "php": "^7.1 || ^8.0", + "php": "^8.0", "psr/http-factory": "^1.0", - "phpunit/phpunit": "^6.5 || ^7.0 || ^8.0 || ^9.0" + "phpunit/phpunit": "^10.0" }, "autoload": { "psr-4": { diff --git a/test/RequestFactoryTestCase.php b/test/RequestFactoryTestCase.php index 9a9f4a9a83b5215c64c368f816fe7d09adda0340..7e3690592339444f14e6391e5f7c11e4a9513c8d 100644 --- a/test/RequestFactoryTestCase.php +++ b/test/RequestFactoryTestCase.php @@ -38,7 +38,7 @@ abstract class RequestFactoryTestCase extends TestCase $this->assertSame($uri, (string) $request->getUri()); } - public function dataMethods() + public static function dataMethods() { return [ ['GET'], diff --git a/test/ResponseFactoryTestCase.php b/test/ResponseFactoryTestCase.php index d7e2c11c99c953a289b63fd6c5c1f669cb447d61..e61875288677350bda1ee10bb1d18ef6af96b1d6 100644 --- a/test/ResponseFactoryTestCase.php +++ b/test/ResponseFactoryTestCase.php @@ -29,7 +29,7 @@ abstract class ResponseFactoryTestCase extends TestCase $this->assertSame($code, $response->getStatusCode()); } - public function dataCodes() + public static function dataCodes() { return [ [200], diff --git a/test/ServerRequestFactoryTestCase.php b/test/ServerRequestFactoryTestCase.php index 30846970a2257a1ff1dae1aa0997740354de0a0f..b19bc66427e72f2d4210ff663829270bbcb9cb52 100644 --- a/test/ServerRequestFactoryTestCase.php +++ b/test/ServerRequestFactoryTestCase.php @@ -38,7 +38,7 @@ abstract class ServerRequestFactoryTestCase extends TestCase $this->assertSame($uri, (string) $request->getUri()); } - public function dataMethods() + public static function dataMethods() { return [ ['GET'], @@ -50,11 +50,11 @@ abstract class ServerRequestFactoryTestCase extends TestCase ]; } - public function dataServer() + public static function dataServer() { $data = []; - foreach ($this->dataMethods() as $methodData) { + foreach (static::dataMethods() as $methodData) { $data[] = [ [ 'REQUEST_METHOD' => $methodData[0], diff --git a/test/StreamFactoryTestCase.php b/test/StreamFactoryTestCase.php index ce899e540c1e9270a9d0ce11a3b0b44a1b0194ae..cc0a869cd4b19278fb0750eeac64b0cf9f4514f7 100644 --- a/test/StreamFactoryTestCase.php +++ b/test/StreamFactoryTestCase.php @@ -68,6 +68,17 @@ abstract class StreamFactoryTestCase extends TestCase $this->assertStream($stream, $string); } + public function testCreateStreamCursorPosition() + { + $this->markTestIncomplete('This behaviour has not been specified by PHP-FIG yet.'); + + $string = 'would you like some crumpets?'; + + $stream = $this->factory->createStream($string); + + $this->assertSame(strlen($string), $stream->tell()); + } + public function testCreateStreamFromFile() { $string = 'would you like some crumpets?'; @@ -132,6 +143,22 @@ abstract class StreamFactoryTestCase extends TestCase $stream = $this->factory->createStreamFromFile($filename, "\u{2620}"); } + public function testCreateStreamFromFileCursorPosition() + { + $string = 'would you like some crumpets?'; + $filename = $this->createTemporaryFile(); + + file_put_contents($filename, $string); + + $resource = fopen($filename, 'r'); + $fopenTell = ftell($resource); + fclose($resource); + + $stream = $this->factory->createStreamFromFile($filename); + + $this->assertSame($fopenTell, $stream->tell()); + } + public function testCreateStreamFromResource() { $string = 'would you like some crumpets?'; @@ -141,4 +168,24 @@ abstract class StreamFactoryTestCase extends TestCase $this->assertStream($stream, $string); } + + public function testCreateStreamFromResourceCursorPosition() + { + $string = 'would you like some crumpets?'; + + $resource1 = $this->createTemporaryResource($string); + fseek($resource1, 0, SEEK_SET); + $stream1 = $this->factory->createStreamFromResource($resource1); + $this->assertSame(0, $stream1->tell()); + + $resource2 = $this->createTemporaryResource($string); + fseek($resource2, 0, SEEK_END); + $stream2 = $this->factory->createStreamFromResource($resource2); + $this->assertSame(strlen($string), $stream2->tell()); + + $resource3 = $this->createTemporaryResource($string); + fseek($resource3, 15, SEEK_SET); + $stream3 = $this->factory->createStreamFromResource($resource3); + $this->assertSame(15, $stream3->tell()); + } }