diff --git a/composer.json b/composer.json index a8d06927a06..f982eb36dce 100644 --- a/composer.json +++ b/composer.json @@ -34,7 +34,7 @@ "monolog/monolog": "^3.8", "nikic/php-parser": "^5.3", "psr/container": "^2.0", - "psr/http-message": "^1", + "psr/http-message": "^2.0", "sebastian/diff": "^6.0", "sensiolabs/ansi-to-html": "^1.2", "silverstripe/config": "^3", diff --git a/tests/php/View/Embed/MockRequest.php b/tests/php/View/Embed/MockRequest.php index c92af57733b..0e3d2cec741 100644 --- a/tests/php/View/Embed/MockRequest.php +++ b/tests/php/View/Embed/MockRequest.php @@ -5,6 +5,7 @@ use Psr\Http\Message\RequestInterface; use Psr\Http\Message\UriInterface; use Psr\Http\Message\StreamInterface; +use Psr\Http\Message\MessageInterface; class MockRequest implements RequestInterface { @@ -17,80 +18,88 @@ public function __construct(EmbedUnitTest $unitTest, MockUri $mockUri) $this->mockUri = $mockUri; } - public function getRequestTarget() + public function getRequestTarget(): string { + return ''; } - public function getMethod() + public function getMethod(): string { + return ''; } - public function getUri() + public function getUri(): UriInterface { $this->unitTest->setFirstRequest(false); return $this->mockUri; } - public function getProtocolVersion() + public function getProtocolVersion(): string { + return ''; } - public function getHeaders() + public function getHeaders(): array { + return []; } - public function getHeader($name) + public function getHeader($name): array { + return []; } - public function getHeaderLine($name) + public function getHeaderLine($name): string { + return ''; } - public function getBody() + public function getBody(): StreamInterface { + return MockUtil::createStreamInterface(''); } - public function hasHeader($name) + public function hasHeader($name): bool { + return false; } - public function withHeader($name, $value) + public function withHeader($name, $value): MessageInterface { return $this; } - public function withAddedHeader($name, $value) + public function withAddedHeader($name, $value): MessageInterface { return $this; } - public function withoutHeader($name) + public function withoutHeader($name): MessageInterface { return $this; } - public function withBody(StreamInterface $body) + public function withBody(StreamInterface $body): MessageInterface { return $this; } - public function withProtocolVersion($version) + public function withProtocolVersion($version): MessageInterface { return $this; } - public function withRequestTarget($requestTarget) + public function withRequestTarget($requestTarget): RequestInterface { return $this; } - public function withMethod($method) + public function withMethod($method): RequestInterface { return $this; } - public function withUri(UriInterface $uri, $preserveHost = false) + public function withUri(UriInterface $uri, $preserveHost = false): RequestInterface { return $this; } diff --git a/tests/php/View/Embed/MockResponse.php b/tests/php/View/Embed/MockResponse.php index 65785047afd..477ba360eeb 100644 --- a/tests/php/View/Embed/MockResponse.php +++ b/tests/php/View/Embed/MockResponse.php @@ -4,6 +4,7 @@ use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\StreamInterface; +use Psr\Http\Message\MessageInterface; class MockResponse implements ResponseInterface { @@ -18,78 +19,78 @@ public function __construct(EmbedUnitTest $unitTest, string $firstResponse, stri $this->secondResponse = $secondResponse; } - public function getStatusCode() + public function getStatusCode(): int { return 200; } - public function getBody() + public function getBody(): StreamInterface { // first request is to the video HTML to get to find the oembed link // second request is to the oembed endpoint to fetch JSON if ($this->unitTest->getFirstRequest()) { - return $this->firstResponse; + return MockUtil::createStreamInterface($this->firstResponse); } else { - return $this->secondResponse; + return MockUtil::createStreamInterface($this->secondResponse); } } - public function getReasonPhrase() + public function getReasonPhrase(): string { return ''; } - public function getProtocolVersion() + public function getProtocolVersion(): string { return ''; } - public function getHeaders() + public function getHeaders(): array { return []; } - public function getHeader($name) + public function getHeader($name): array { - return ''; + return []; } - public function getHeaderLine($name) + public function getHeaderLine($name): string { return ''; } - public function hasHeader($name) + public function hasHeader($name): bool { return false; } - public function withHeader($name, $value) + public function withHeader($name, $value): MessageInterface { return $this; } - public function withAddedHeader($name, $value) + public function withAddedHeader($name, $value): MessageInterface { return $this; } - public function withBody(StreamInterface $body) + public function withBody(StreamInterface $body): MessageInterface { return $this; } - public function withoutHeader($name) + public function withoutHeader($name): MessageInterface { return $this; } - public function withProtocolVersion($version) + public function withProtocolVersion($version): MessageInterface { return $this; } - public function withStatus($code, $reasonPhrase = '') + public function withStatus($code, $reasonPhrase = ''): ResponseInterface { return $this; } diff --git a/tests/php/View/Embed/MockUri.php b/tests/php/View/Embed/MockUri.php index a374d1336d2..e7a692d72cf 100644 --- a/tests/php/View/Embed/MockUri.php +++ b/tests/php/View/Embed/MockUri.php @@ -7,10 +7,10 @@ class MockUri implements UriInterface, Stringable { - private string $scheme; - private string $host; - private string $path; - private string $query; + private string $scheme = ''; + private string $host = ''; + private string $path = ''; + private string $query = ''; public function __construct(string $url) { @@ -21,73 +21,77 @@ public function __construct(string $url) $this->query = $p['query'] ?? ''; } - public function getScheme() + public function getScheme(): string { return $this->scheme; } - public function getHost() + public function getHost(): string { return $this->host; } - public function getPath() + public function getPath(): string { return $this->path; } - public function getQuery() + public function getQuery(): string { return $this->query; } - public function getPort() + public function getPort(): ?int { + return null; } - public function getAuthority() + public function getAuthority(): string { + return ''; } - public function getUserInfo() + public function getUserInfo(): string { + return ''; } - public function getFragment() + public function getFragment(): string { + return ''; } - public function withPath($path) + public function withPath($path): UriInterface { return $this; } - public function withScheme($scheme) + public function withScheme($scheme): UriInterface { return $this; } - public function withUserInfo($user, $password = null) + public function withUserInfo($user, $password = null): UriInterface { return $this; } - public function withHost($host) + public function withHost($host): UriInterface { return $this; } - public function withPort($port) + public function withPort($port): UriInterface { return $this; } - public function withQuery($query) + public function withQuery($query): UriInterface { return $this; } - public function withFragment($fragment) + public function withFragment($fragment): UriInterface { return $this; } diff --git a/tests/php/View/Embed/MockUtil.php b/tests/php/View/Embed/MockUtil.php new file mode 100644 index 00000000000..82000a9f035 --- /dev/null +++ b/tests/php/View/Embed/MockUtil.php @@ -0,0 +1,79 @@ +body = $body; + } + public function __toString(): string + { + return $this->body; + } + public function close(): void + { + return; + } + public function detach() + { + return; + } + public function getSize(): ?int + { + return null; + } + public function tell(): int + { + return 0; + } + public function eof(): bool + { + return false; + } + public function isSeekable(): bool + { + return false; + } + public function seek(int $offset, int $whence = SEEK_SET): void + { + return; + } + public function rewind(): void + { + return; + } + public function isWritable(): bool + { + return false; + } + public function write(string $string): int + { + return 0; + } + public function isReadable(): bool + { + return false; + } + public function read(int $length): string + { + return ''; + } + public function getContents(): string + { + return ''; + } + public function getMetadata(?string $key = null) + { + return; + } + }; + } +}