Skip to content

Commit

Permalink
Fix tests for PHP 8.3
Browse files Browse the repository at this point in the history
  • Loading branch information
odan committed Jul 7, 2024
2 parents b8e7b5c + af2b5ac commit f29badd
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 33 deletions.
23 changes: 20 additions & 3 deletions tests/AppTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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 () {
Expand All @@ -1673,7 +1684,7 @@ public function testRun(): void
});
$streamProphecy->eof()->willReturn(false);
$streamProphecy->isSeekable()->willReturn(true);
$streamProphecy->rewind()->willReturn(true);
$streamProphecy->rewind()->shouldBeCalled();

$responseProphecy = $this->prophesize(ResponseInterface::class);
$responseProphecy->getBody()->willReturn($streamProphecy->reveal());
Expand Down Expand Up @@ -1717,15 +1728,16 @@ 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 () {
$streamProphecy->read(11)->will(function () {
$this->eof()->willReturn(true);
return $this->reveal()->__toString();
});
$streamProphecy->eof()->willReturn(false);
$streamProphecy->isSeekable()->willReturn(true);
$streamProphecy->rewind()->willReturn(true);
$streamProphecy->rewind()->shouldBeCalled();

$responseProphecy = $this->prophesize(ResponseInterface::class);
$responseProphecy->getBody()->willReturn($streamProphecy->reveal());
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -1813,6 +1826,7 @@ public function testCanBeReExecutedRecursivelyDuringDispatch(): void
$body = $this->reveal()->__toString();
$body .= $args[0];
$this->__toString()->willReturn($body);
return 0;
});

$responseHeaders = [];
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
28 changes: 14 additions & 14 deletions tests/Mocks/SlowPokeStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function __construct()
$this->amountToRead = self::SIZE;
}

public function __toString()
public function __toString(): string
{
$content = '';
while (!$this->eof()) {
Expand All @@ -43,7 +43,7 @@ public function __toString()
return $content;
}

public function close()
public function close(): void
{
}

Expand All @@ -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');
}
Expand All @@ -67,51 +67,51 @@ 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);
$this->amountToRead -= $size;
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);
}
}
28 changes: 14 additions & 14 deletions tests/Mocks/SmallChunksStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
}

Expand All @@ -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');
}
Expand All @@ -62,51 +62,51 @@ 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;

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);
}
}
4 changes: 2 additions & 2 deletions tests/Routing/RouteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 strlen($value);
});

$streamProphecy
Expand Down Expand Up @@ -821,7 +821,7 @@ public function testRouteCallableIsResolvedUsingContainerWhenCallableResolverIsP
->will(function ($args) use ($value) {
$value .= $args[0];
$this->__toString()->willReturn($value);
return $this->reveal();
return strlen($value);
});

$streamProphecy
Expand Down

0 comments on commit f29badd

Please sign in to comment.