From 9a07ee283264a2709c314ff5d5ddde56aab71d8a Mon Sep 17 00:00:00 2001 From: Daniel Opitz Date: Sun, 7 Jul 2024 14:19:24 +0200 Subject: [PATCH 1/4] Fix tests for PHP 8.3 --- tests/AppTest.php | 21 +++++++++++++++++++-- tests/Mocks/SlowPokeStream.php | 28 ++++++++++++++-------------- tests/Mocks/SmallChunksStream.php | 28 ++++++++++++++-------------- tests/Routing/RouteTest.php | 4 ++-- 4 files changed, 49 insertions(+), 32 deletions(-) diff --git a/tests/AppTest.php b/tests/AppTest.php index fd142fd76..3b0cbf465 100644 --- a/tests/AppTest.php +++ b/tests/AppTest.php @@ -1143,6 +1143,7 @@ public function testInvokeWithMatchingRouteWithSetArgument(): void $body = $this->reveal()->__toString(); $body .= $args[0]; $this->__toString()->willReturn($body); + return 0; }); $responseProphecy = $this->prophesize(ResponseInterface::class); @@ -1183,6 +1184,7 @@ public function testInvokeWithMatchingRouteWithSetArguments(): void $body = $this->reveal()->__toString(); $body .= $args[0]; $this->__toString()->willReturn($body); + return 0; }); $responseProphecy = $this->prophesize(ResponseInterface::class); @@ -1223,6 +1225,7 @@ public function testInvokeWithMatchingRouteWithNamedParameterRequestResponseStra $body = $this->reveal()->__toString(); $body .= $args[0]; $this->__toString()->willReturn($body); + return 0; }); $responseProphecy = $this->prophesize(ResponseInterface::class); @@ -1263,6 +1266,7 @@ public function testInvokeWithMatchingRouteWithNamedParameterRequestResponseArgS $body = $this->reveal()->__toString(); $body .= $args[0]; $this->__toString()->willReturn($body); + return 0; }); $responseProphecy = $this->prophesize(ResponseInterface::class); @@ -1308,6 +1312,7 @@ public function testInvokeWithMatchingRouteWithNamedParameterRequestResponseName $body = $this->reveal()->__toString(); $body .= $args[0]; $this->__toString()->willReturn($body); + return 0; }); $responseProphecy = $this->prophesize(ResponseInterface::class); @@ -1352,6 +1357,7 @@ public function testInvokeWithMatchingRouteWithNamedParameterOverwritesSetArgume $body = $this->reveal()->__toString(); $body .= $args[0]; $this->__toString()->willReturn($body); + return 0; }); $responseProphecy = $this->prophesize(ResponseInterface::class); @@ -1494,6 +1500,7 @@ public function testInvokeWithCallableInContainerViaCallMagicMethod(): void $body = $this->reveal()->__toString(); $body .= $args[0]; $this->__toString()->willReturn($body); + return 0; }); $responseProphecy = $this->prophesize(ResponseInterface::class); @@ -1538,6 +1545,7 @@ public function testInvokeFunctionName(): void $body = $this->reveal()->__toString(); $body .= $args[0]; $this->__toString()->willReturn($body); + return 0; }); $responseProphecy = $this->prophesize(ResponseInterface::class); @@ -1584,6 +1592,7 @@ public function testCurrentRequestAttributesAreNotLostWhenAddingRouteArguments() $body = $this->reveal()->__toString(); $body .= $args[0]; $this->__toString()->willReturn($body); + return 0; }); $responseProphecy = $this->prophesize(ResponseInterface::class); @@ -1624,6 +1633,7 @@ public function testCurrentRequestAttributesAreNotLostWhenAddingRouteArgumentsRe $body = $this->reveal()->__toString(); $body .= $args[0]; $this->__toString()->willReturn($body); + return 0; }); $responseProphecy = $this->prophesize(ResponseInterface::class); @@ -1665,6 +1675,7 @@ public function testRun(): void $body = $this->reveal()->__toString(); $body .= $args[0]; $this->__toString()->willReturn($body); + return 0; }); $streamProphecy->read(1)->willReturn('_'); $streamProphecy->read('11')->will(function () { @@ -1673,7 +1684,7 @@ public function testRun(): void }); $streamProphecy->eof()->willReturn(false); $streamProphecy->isSeekable()->willReturn(true); - $streamProphecy->rewind()->willReturn(true); + $streamProphecy->rewind(); $responseProphecy = $this->prophesize(ResponseInterface::class); $responseProphecy->getBody()->willReturn($streamProphecy->reveal()); @@ -1717,6 +1728,7 @@ public function testRunWithoutPassingInServerRequest(): void $body = $this->reveal()->__toString(); $body .= $args[0]; $this->__toString()->willReturn($body); + return 0; }); $streamProphecy->read(1)->willReturn('_'); $streamProphecy->read('11')->will(function () { @@ -1725,7 +1737,7 @@ public function testRunWithoutPassingInServerRequest(): void }); $streamProphecy->eof()->willReturn(false); $streamProphecy->isSeekable()->willReturn(true); - $streamProphecy->rewind()->willReturn(true); + $streamProphecy->rewind(); $responseProphecy = $this->prophesize(ResponseInterface::class); $responseProphecy->getBody()->willReturn($streamProphecy->reveal()); @@ -1757,6 +1769,7 @@ public function testHandleReturnsEmptyResponseBodyWithHeadRequestMethod(): void $body = $this->reveal()->__toString(); $body .= $args[0]; $this->__toString()->willReturn($body); + return 0; }); $responseProphecy = $this->prophesize(ResponseInterface::class); @@ -1813,6 +1826,7 @@ public function testCanBeReExecutedRecursivelyDuringDispatch(): void $body = $this->reveal()->__toString(); $body .= $args[0]; $this->__toString()->willReturn($body); + return 0; }); $responseHeaders = []; @@ -1978,6 +1992,7 @@ public function testInvokeSequentialProcessToAPathWithOptionalArgsAndWithoutOpti $body = $this->reveal()->__toString(); $body .= $args[0]; $this->__toString()->willReturn($body); + return 0; }); $responseProphecy = $this->prophesize(ResponseInterface::class); @@ -2032,6 +2047,7 @@ public function testInvokeSequentialProcessToAPathWithOptionalArgsAndWithoutOpti $body = $this->reveal()->__toString(); $body .= $args[0]; $this->__toString()->willReturn($body); + return 0; }); $responseProphecy = $this->prophesize(ResponseInterface::class); @@ -2086,6 +2102,7 @@ public function testInvokeSequentialProcessAfterAddingAnotherRouteArgument(): vo $body = $this->reveal()->__toString(); $body .= $args[0]; $this->__toString()->willReturn($body); + return 0; }); $responseProphecy = $this->prophesize(ResponseInterface::class); diff --git a/tests/Mocks/SlowPokeStream.php b/tests/Mocks/SlowPokeStream.php index b5547b295..2e6c0776f 100644 --- a/tests/Mocks/SlowPokeStream.php +++ b/tests/Mocks/SlowPokeStream.php @@ -34,7 +34,7 @@ public function __construct() $this->amountToRead = self::SIZE; } - public function __toString() + public function __toString(): string { $content = ''; while (!$this->eof()) { @@ -43,7 +43,7 @@ public function __toString() return $content; } - public function close() + public function close(): void { } @@ -52,12 +52,12 @@ public function detach() throw new Exception('not implemented'); } - public function eof() + public function eof(): bool { return $this->amountToRead === 0; } - public function getContents() + public function getContents(): string { throw new Exception('not implemented'); } @@ -67,27 +67,27 @@ public function getMetadata($key = null) throw new Exception('not implemented'); } - public function getSize() + public function getSize(): ?int { return null; } - public function isReadable() + public function isReadable(): bool { return true; } - public function isSeekable() + public function isSeekable(): bool { return false; } - public function isWritable() + public function isWritable(): bool { return false; } - public function read($length) + public function read($length): string { usleep(1); $size = min($this->amountToRead, self::CHUNK_SIZE, $length); @@ -95,23 +95,23 @@ public function read($length) return str_repeat('.', $size); } - public function rewind() + public function rewind(): void { throw new Exception('not implemented'); } - public function seek($offset, $whence = SEEK_SET) + public function seek($offset, $whence = SEEK_SET): void { throw new Exception('not implemented'); } - public function tell() + public function tell(): int { throw new Exception('not implemented'); } - public function write($string) + public function write($string): int { - return $string; + return strlen($string); } } diff --git a/tests/Mocks/SmallChunksStream.php b/tests/Mocks/SmallChunksStream.php index b136c7f37..c4b0169db 100644 --- a/tests/Mocks/SmallChunksStream.php +++ b/tests/Mocks/SmallChunksStream.php @@ -33,12 +33,12 @@ public function __construct() $this->amountToRead = self::SIZE; } - public function __toString() + public function __toString(): string { return str_repeat('.', self::SIZE); } - public function close() + public function close(): void { } @@ -47,12 +47,12 @@ public function detach() throw new Exception('not implemented'); } - public function eof() + public function eof(): bool { return $this->amountToRead === 0; } - public function getContents() + public function getContents(): string { throw new Exception('not implemented'); } @@ -62,27 +62,27 @@ public function getMetadata($key = null) throw new Exception('not implemented'); } - public function getSize() + public function getSize(): ?int { return self::SIZE; } - public function isReadable() + public function isReadable(): bool { return true; } - public function isSeekable() + public function isSeekable(): bool { return false; } - public function isWritable() + public function isWritable(): bool { return false; } - public function read($length) + public function read($length): string { $size = min($this->amountToRead, self::CHUNK_SIZE, $length); $this->amountToRead -= $size; @@ -90,23 +90,23 @@ public function read($length) return str_repeat('.', min($length, $size)); } - public function rewind() + public function rewind(): void { throw new Exception('not implemented'); } - public function seek($offset, $whence = SEEK_SET) + public function seek($offset, $whence = SEEK_SET): void { throw new Exception('not implemented'); } - public function tell() + public function tell(): int { throw new Exception('not implemented'); } - public function write($string) + public function write($string): int { - return $string; + return strlen($string); } } diff --git a/tests/Routing/RouteTest.php b/tests/Routing/RouteTest.php index 01fd2ab36..3022613f4 100644 --- a/tests/Routing/RouteTest.php +++ b/tests/Routing/RouteTest.php @@ -72,7 +72,7 @@ public function createRoute($methods = 'GET', string $pattern = '/', $callable = ->will(function ($args) use ($value) { $value .= $args[0]; $this->__toString()->willReturn($value); - return $this->reveal(); + return 0; }); $streamProphecy @@ -821,7 +821,7 @@ public function testRouteCallableIsResolvedUsingContainerWhenCallableResolverIsP ->will(function ($args) use ($value) { $value .= $args[0]; $this->__toString()->willReturn($value); - return $this->reveal(); + return 0; }); $streamProphecy From 5eeaa199ef47a580336de75d813a4a22967531c6 Mon Sep 17 00:00:00 2001 From: Daniel Opitz Date: Sun, 7 Jul 2024 14:33:40 +0200 Subject: [PATCH 2/4] Fix tests for PHP 8.3 --- tests/Routing/RouteTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Routing/RouteTest.php b/tests/Routing/RouteTest.php index 3022613f4..9198df15b 100644 --- a/tests/Routing/RouteTest.php +++ b/tests/Routing/RouteTest.php @@ -72,7 +72,7 @@ public function createRoute($methods = 'GET', string $pattern = '/', $callable = ->will(function ($args) use ($value) { $value .= $args[0]; $this->__toString()->willReturn($value); - return 0; + return strlen($value); }); $streamProphecy @@ -821,7 +821,7 @@ public function testRouteCallableIsResolvedUsingContainerWhenCallableResolverIsP ->will(function ($args) use ($value) { $value .= $args[0]; $this->__toString()->willReturn($value); - return 0; + return strlen($value); }); $streamProphecy From addacc166a23f73b571c06b985da7b2f102836c2 Mon Sep 17 00:00:00 2001 From: Daniel Opitz Date: Sun, 7 Jul 2024 14:43:59 +0200 Subject: [PATCH 3/4] Fix tests for PHP 8.3 --- tests/AppTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/AppTest.php b/tests/AppTest.php index 3b0cbf465..6b593a8ba 100644 --- a/tests/AppTest.php +++ b/tests/AppTest.php @@ -1684,7 +1684,7 @@ public function testRun(): void }); $streamProphecy->eof()->willReturn(false); $streamProphecy->isSeekable()->willReturn(true); - $streamProphecy->rewind(); + $streamProphecy->rewind()->shouldBeCalled(); $responseProphecy = $this->prophesize(ResponseInterface::class); $responseProphecy->getBody()->willReturn($streamProphecy->reveal()); @@ -1731,13 +1731,13 @@ public function testRunWithoutPassingInServerRequest(): void return 0; }); $streamProphecy->read(1)->willReturn('_'); - $streamProphecy->read('11')->will(function () { + $streamProphecy->read(11)->will(function () { $this->eof()->willReturn(true); return $this->reveal()->__toString(); }); $streamProphecy->eof()->willReturn(false); $streamProphecy->isSeekable()->willReturn(true); - $streamProphecy->rewind(); + $streamProphecy->rewind()->shouldBeCalled();; $responseProphecy = $this->prophesize(ResponseInterface::class); $responseProphecy->getBody()->willReturn($streamProphecy->reveal()); From af2b5ac18d1ffd4d341a1fd1e79f1792c6cffec6 Mon Sep 17 00:00:00 2001 From: Daniel Opitz Date: Sun, 7 Jul 2024 14:45:47 +0200 Subject: [PATCH 4/4] Fix tests for PHP 8.3 --- tests/AppTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/AppTest.php b/tests/AppTest.php index 6b593a8ba..cd18bfd16 100644 --- a/tests/AppTest.php +++ b/tests/AppTest.php @@ -1737,7 +1737,7 @@ public function testRunWithoutPassingInServerRequest(): void }); $streamProphecy->eof()->willReturn(false); $streamProphecy->isSeekable()->willReturn(true); - $streamProphecy->rewind()->shouldBeCalled();; + $streamProphecy->rewind()->shouldBeCalled(); $responseProphecy = $this->prophesize(ResponseInterface::class); $responseProphecy->getBody()->willReturn($streamProphecy->reveal());