diff --git a/composer.json b/composer.json
index eccff7ec..154e70a5 100644
--- a/composer.json
+++ b/composer.json
@@ -19,6 +19,9 @@
"forum": "https://discourse.laminas.dev"
},
"config": {
+ "allow-plugins": {
+ "dealerdirect/phpcodesniffer-composer-installer": true
+ },
"sort-packages": true,
"platform": {
"php": "7.3.99"
diff --git a/psalm-baseline.xml b/psalm-baseline.xml
index 6b595c35..896c059a 100644
--- a/psalm-baseline.xml
+++ b/psalm-baseline.xml
@@ -14,6 +14,22 @@
$previous->getCode()
+
+
+ $code
+
+
+ $code
+
+
+
+
+ $code
+
+
+ $code
+
+
! is_string($name)
@@ -329,18 +345,9 @@
-
- laminas_createUploadedFile(...func_get_args())
-
-
- UploadedFile
-
func_get_args()
-
- UploadedFile
-
@@ -386,18 +393,9 @@
-
- laminas_marshalUriFromSapi(...func_get_args())
-
-
- Uri
-
func_get_args()
-
- Uri
-
@@ -529,19 +527,26 @@
-
- 'UNLOCK' => ['UNLOCK']
-
-
-
-
- testRaisesExceptionforNonStringNonStreamBodyContent
-
+
+ $headers
+
+
+ public function testConstructorRaisesExceptionForHeadersWithCRLFVectors(string $name, $value): void
+
+
+ $ianaCodesReasonPhrases
+
+
+ $value
+
$responseCode
+
+ list<array{numeric-string, non-empty-string}>
+
assertIsInt
@@ -566,6 +571,9 @@
[' THIS WILL NOT WORK ']
+
+ testIsWritableReturnsCorrectFlagForMode
+
$test
diff --git a/src/Exception/InvalidStreamPointerPositionException.php b/src/Exception/InvalidStreamPointerPositionException.php
index acaa7e7f..ae45ca5a 100644
--- a/src/Exception/InvalidStreamPointerPositionException.php
+++ b/src/Exception/InvalidStreamPointerPositionException.php
@@ -9,7 +9,7 @@
class InvalidStreamPointerPositionException extends RuntimeException implements ExceptionInterface
{
- /** @param int $code */
+ /** {@inheritDoc} */
public function __construct(
string $message = 'Invalid pointer position',
$code = 0,
diff --git a/src/Exception/UploadedFileAlreadyMovedException.php b/src/Exception/UploadedFileAlreadyMovedException.php
index 9025c1cb..23182bfc 100644
--- a/src/Exception/UploadedFileAlreadyMovedException.php
+++ b/src/Exception/UploadedFileAlreadyMovedException.php
@@ -9,7 +9,7 @@
class UploadedFileAlreadyMovedException extends RuntimeException implements ExceptionInterface
{
- /** @param int $code */
+ /** {@inheritDoc} */
public function __construct(
string $message = 'Cannot retrieve stream after it has already moved',
$code = 0,
diff --git a/src/MessageTrait.php b/src/MessageTrait.php
index dac56ea8..60f92393 100644
--- a/src/MessageTrait.php
+++ b/src/MessageTrait.php
@@ -303,9 +303,7 @@ public function withBody(StreamInterface $body): MessageInterface
return $new;
}
- /**
- * @param StreamInterface|string|resource $stream
- */
+ /** @param StreamInterface|string|resource $stream */
private function getStream($stream, string $modeIfNotInstance): StreamInterface
{
if ($stream instanceof StreamInterface) {
diff --git a/src/Request/ArraySerializer.php b/src/Request/ArraySerializer.php
index 884b7c2b..e3c10485 100644
--- a/src/Request/ArraySerializer.php
+++ b/src/Request/ArraySerializer.php
@@ -23,6 +23,15 @@ final class ArraySerializer
{
/**
* Serialize a request message to an array.
+ *
+ * @return array{
+ * method: string,
+ * request_target: string,
+ * uri: string,
+ * protocol_version: string,
+ * headers: array>,
+ * body: string
+ * }
*/
public static function toArray(RequestInterface $request): array
{
diff --git a/src/Response/ArraySerializer.php b/src/Response/ArraySerializer.php
index 6667d017..b3ecc111 100644
--- a/src/Response/ArraySerializer.php
+++ b/src/Response/ArraySerializer.php
@@ -23,6 +23,14 @@ final class ArraySerializer
{
/**
* Serialize a response message to an array.
+ *
+ * @return array{
+ * status_code: int,
+ * reason_phrase: string,
+ * protocol_version: string,
+ * headers: array>,
+ * body: string
+ * }
*/
public static function toArray(ResponseInterface $response): array
{
diff --git a/src/functions/create_uploaded_file.legacy.php b/src/functions/create_uploaded_file.legacy.php
index 110101e6..fff753ff 100644
--- a/src/functions/create_uploaded_file.legacy.php
+++ b/src/functions/create_uploaded_file.legacy.php
@@ -4,6 +4,8 @@
namespace Zend\Diactoros;
+use Laminas\Diactoros\UploadedFile;
+
use function func_get_args;
use function Laminas\Diactoros\createUploadedFile as laminas_createUploadedFile;
diff --git a/src/functions/marshal_uri_from_sapi.legacy.php b/src/functions/marshal_uri_from_sapi.legacy.php
index 660ddd4e..43fff2a8 100644
--- a/src/functions/marshal_uri_from_sapi.legacy.php
+++ b/src/functions/marshal_uri_from_sapi.legacy.php
@@ -4,6 +4,8 @@
namespace Zend\Diactoros;
+use Laminas\Diactoros\Uri;
+
use function func_get_args;
use function Laminas\Diactoros\marshalUriFromSapi as laminas_marshalUriFromSapi;
diff --git a/src/functions/parse_cookie_header.legacy.php b/src/functions/parse_cookie_header.legacy.php
index e0e0f6c1..ee4f85ab 100644
--- a/src/functions/parse_cookie_header.legacy.php
+++ b/src/functions/parse_cookie_header.legacy.php
@@ -8,9 +8,10 @@
use function Laminas\Diactoros\parseCookieHeader as laminas_parseCookieHeader;
/**
- * @deprecated Use \Laminas\Diactoros\parseCookieHeader instead
+ * @deprecated Use {@see \Laminas\Diactoros\parseCookieHeader} instead
*
* @param string $cookieHeader A string cookie header value.
+ * @return array key/value cookie pairs.
*/
function parseCookieHeader($cookieHeader): array
{
diff --git a/src/functions/parse_cookie_header.php b/src/functions/parse_cookie_header.php
index 1c7606e5..10cac8fc 100644
--- a/src/functions/parse_cookie_header.php
+++ b/src/functions/parse_cookie_header.php
@@ -16,7 +16,7 @@
* overwriting. Thus, the server request should take the cookies from the request header instead.
*
* @param string $cookieHeader A string cookie header value.
- * @return array key/value cookie pairs.
+ * @return array key/value cookie pairs.
*/
function parseCookieHeader($cookieHeader): array
{
diff --git a/test/CallbackStreamTest.php b/test/CallbackStreamTest.php
index 7cdc4219..3ec9d8d3 100644
--- a/test/CallbackStreamTest.php
+++ b/test/CallbackStreamTest.php
@@ -11,7 +11,7 @@
/**
* @covers \Laminas\Diactoros\CallbackStream
*/
-class CallbackStreamTest extends TestCase
+final class CallbackStreamTest extends TestCase
{
public function testToString(): void
{
@@ -173,7 +173,7 @@ public function testGetMetadata(): void
$this->assertNull($notExists);
}
- /** @return array */
+ /** @return non-empty-array */
public function phpCallbacksForStreams(): array
{
$class = TestAsset\CallbacksForCallbackStreamTest::class;
@@ -190,6 +190,8 @@ public function phpCallbacksForStreams(): array
/**
* @dataProvider phpCallbacksForStreams
+ * @param callable(): string $callback
+ * @param non-empty-string $expected
*/
public function testAllowsArbitraryPhpCallbacks(callable $callback, string $expected): void
{
diff --git a/test/HeaderSecurityTest.php b/test/HeaderSecurityTest.php
index f605f028..100d1bf4 100644
--- a/test/HeaderSecurityTest.php
+++ b/test/HeaderSecurityTest.php
@@ -8,12 +8,12 @@
use Laminas\Diactoros\HeaderSecurity;
use PHPUnit\Framework\TestCase;
-class HeaderSecurityTest extends TestCase
+final class HeaderSecurityTest extends TestCase
{
/**
* Data for filter value
*
- * @return array
+ * @return non-empty-list
*/
public function getFilterValues(): array
{
@@ -34,42 +34,47 @@ public function getFilterValues(): array
/**
* @dataProvider getFilterValues
+ * @group ZF2015-04
+ * @param non-empty-string $value
+ * @param non-empty-string $expected
*/
public function testFiltersValuesPerRfc7230(string $value, string $expected): void
{
$this->assertSame($expected, HeaderSecurity::filter($value));
}
- /** @return array */
+ /** @return non-empty-list */
public function validateValues(): array
{
return [
- ["This is a\n test", 'assertFalse'],
- ["This is a\r test", 'assertFalse'],
- ["This is a\n\r test", 'assertFalse'],
- ["This is a\r\n test", 'assertTrue'],
- ["This is a \r\ntest", 'assertFalse'],
- ["This is a \r\n\n test", 'assertFalse'],
- ["This is a\n\n test", 'assertFalse'],
- ["This is a\r\r test", 'assertFalse'],
- ["This is a \r\r\n test", 'assertFalse'],
- ["This is a \r\n\r\ntest", 'assertFalse'],
- ["This is a \r\n\n\r\n test", 'assertFalse'],
- ["This is a \xFF test", 'assertFalse'],
- ["This is a \x7F test", 'assertFalse'],
- ["This is a \x7E test", 'assertTrue'],
+ ["This is a\n test", false],
+ ["This is a\r test", false],
+ ["This is a\n\r test", false],
+ ["This is a\r\n test", true],
+ ["This is a \r\ntest", false],
+ ["This is a \r\n\n test", false],
+ ["This is a\n\n test", false],
+ ["This is a\r\r test", false],
+ ["This is a \r\r\n test", false],
+ ["This is a \r\n\r\ntest", false],
+ ["This is a \r\n\n\r\n test", false],
+ ["This is a \xFF test", false],
+ ["This is a \x7F test", false],
+ ["This is a \x7E test", true],
];
}
/**
* @dataProvider validateValues
+ * @group ZF2015-04
+ * @param non-empty-string $value
*/
- public function testValidatesValuesPerRfc7230(string $value, string $assertion): void
+ public function testValidatesValuesPerRfc7230(string $value, bool $expected): void
{
- $this->{$assertion}(HeaderSecurity::isValid($value));
+ self::assertSame($expected, HeaderSecurity::isValid($value));
}
- /** @return array */
+ /** @return non-empty-list */
public function assertValues(): array
{
return [
@@ -88,6 +93,8 @@ public function assertValues(): array
/**
* @dataProvider assertValues
+ * @group ZF2015-04
+ * @param non-empty-string $value
*/
public function testAssertValidRaisesExceptionForInvalidValue(string $value): void
{
diff --git a/test/Integration/RequestTest.php b/test/Integration/RequestTest.php
index 29a7e5c7..14804330 100644
--- a/test/Integration/RequestTest.php
+++ b/test/Integration/RequestTest.php
@@ -7,7 +7,7 @@
use Http\Psr7Test\RequestIntegrationTest;
use Laminas\Diactoros\Request;
-class RequestTest extends RequestIntegrationTest
+final class RequestTest extends RequestIntegrationTest
{
public function createSubject(): Request
{
diff --git a/test/Integration/ResponseTest.php b/test/Integration/ResponseTest.php
index ca7eeb12..6fc3861f 100644
--- a/test/Integration/ResponseTest.php
+++ b/test/Integration/ResponseTest.php
@@ -7,7 +7,7 @@
use Http\Psr7Test\ResponseIntegrationTest;
use Laminas\Diactoros\Response;
-class ResponseTest extends ResponseIntegrationTest
+final class ResponseTest extends ResponseIntegrationTest
{
public function createSubject(): Response
{
diff --git a/test/Integration/ServerRequestFactoryTest.php b/test/Integration/ServerRequestFactoryTest.php
index 9ec7a21f..11053881 100644
--- a/test/Integration/ServerRequestFactoryTest.php
+++ b/test/Integration/ServerRequestFactoryTest.php
@@ -8,7 +8,7 @@
use Laminas\Diactoros\ServerRequestFactory;
use Psr\Http\Message\ServerRequestInterface;
-class ServerRequestFactoryTest extends ServerRequestIntegrationTest
+final class ServerRequestFactoryTest extends ServerRequestIntegrationTest
{
public function createSubject(): ServerRequestInterface
{
diff --git a/test/Integration/ServerRequestTest.php b/test/Integration/ServerRequestTest.php
index 1bdc1a0a..1e2953b8 100644
--- a/test/Integration/ServerRequestTest.php
+++ b/test/Integration/ServerRequestTest.php
@@ -7,7 +7,7 @@
use Http\Psr7Test\ServerRequestIntegrationTest;
use Laminas\Diactoros\ServerRequest;
-class ServerRequestTest extends ServerRequestIntegrationTest
+final class ServerRequestTest extends ServerRequestIntegrationTest
{
public function createSubject(): ServerRequest
{
diff --git a/test/Integration/StreamTest.php b/test/Integration/StreamTest.php
index bfe1b167..96732641 100644
--- a/test/Integration/StreamTest.php
+++ b/test/Integration/StreamTest.php
@@ -8,11 +8,9 @@
use Laminas\Diactoros\Stream;
use Psr\Http\Message\StreamInterface;
-class StreamTest extends StreamIntegrationTest
+final class StreamTest extends StreamIntegrationTest
{
- /**
- * @param string|resource|StreamInterface $data
- */
+ /** {@inheritDoc} */
public function createStream($data): StreamInterface
{
if ($data instanceof StreamInterface) {
diff --git a/test/Integration/UploadedFileTest.php b/test/Integration/UploadedFileTest.php
index 67a4cfcf..70a15391 100644
--- a/test/Integration/UploadedFileTest.php
+++ b/test/Integration/UploadedFileTest.php
@@ -10,7 +10,7 @@
use const UPLOAD_ERR_OK;
-class UploadedFileTest extends UploadedFileIntegrationTest
+final class UploadedFileTest extends UploadedFileIntegrationTest
{
public function createSubject(): UploadedFile
{
diff --git a/test/Integration/UriTest.php b/test/Integration/UriTest.php
index 09f33d64..a119b728 100644
--- a/test/Integration/UriTest.php
+++ b/test/Integration/UriTest.php
@@ -7,11 +7,9 @@
use Http\Psr7Test\UriIntegrationTest;
use Laminas\Diactoros\Uri;
-class UriTest extends UriIntegrationTest
+final class UriTest extends UriIntegrationTest
{
- /**
- * @param string $uri
- */
+ /** {@inheritDoc} */
public function createUri($uri): Uri
{
return new Uri($uri);
diff --git a/test/MessageTraitTest.php b/test/MessageTraitTest.php
index 58c51cb1..cb6bebc5 100644
--- a/test/MessageTraitTest.php
+++ b/test/MessageTraitTest.php
@@ -422,6 +422,7 @@ public function invalidArrayHeaderValues(): array
/**
* @dataProvider invalidArrayHeaderValues
+ * @group 99
* @param mixed $value
*/
public function testWithHeaderShouldRaiseExceptionForInvalidHeaderValuesInArrays($value): void
@@ -435,6 +436,7 @@ public function testWithHeaderShouldRaiseExceptionForInvalidHeaderValuesInArrays
/**
* @dataProvider invalidHeaderValueTypes
+ * @group 99
* @param mixed $value
*/
public function testWithHeaderShouldRaiseExceptionForInvalidHeaderScalarValues($value): void
diff --git a/test/PhpInputStreamTest.php b/test/PhpInputStreamTest.php
index 7a440fff..5a939979 100644
--- a/test/PhpInputStreamTest.php
+++ b/test/PhpInputStreamTest.php
@@ -10,7 +10,7 @@
use function file_get_contents;
use function substr;
-class PhpInputStreamTest extends TestCase
+final class PhpInputStreamTest extends TestCase
{
/** @var string */
protected $file;
diff --git a/test/Request/SerializerTest.php b/test/Request/SerializerTest.php
index 6d181a72..f408afec 100644
--- a/test/Request/SerializerTest.php
+++ b/test/Request/SerializerTest.php
@@ -65,7 +65,7 @@ public function testSerializesMultipleHeadersCorrectly(): void
$this->assertStringContainsString("X-Foo-Bar: Bat", $message);
}
- /** @return array}> */
+ /** @return non-empty-array}> */
public function originForms(): array
{
return [
@@ -84,7 +84,9 @@ public function originForms(): array
/**
* @dataProvider originForms
- * @param array $expectations
+ * @param non-empty-string $line
+ * @param non-empty-string $requestTarget
+ * @param array $expectations
*/
public function testCanDeserializeRequestWithOriginForm(
string $line,
@@ -103,7 +105,23 @@ public function testCanDeserializeRequestWithOriginForm(
}
}
- /** @return array}> */
+ /**
+ * @return non-empty-array<
+ * non-empty-string,
+ * array{
+ * non-empty-string,
+ * non-empty-string,
+ * array{
+ * getScheme?: non-empty-string,
+ * getUserInfo?: non-empty-string,
+ * getHost?: non-empty-string,
+ * getPort?: positive-int,
+ * getPath?: non-empty-string,
+ * getQuery?: non-empty-string
+ * }
+ * }
+ * >
+ */
public function absoluteForms(): array
{
return [
@@ -152,15 +170,19 @@ public function absoluteForms(): array
];
}
+ // @codingStandardsIgnoreStart if we split these line, phpcs can't associate parameter name and docblock anymore (phpcs limitation)
/**
* @dataProvider absoluteForms
- * @param array $expectations
+ * @param non-empty-string $line
+ * @param non-empty-string $requestTarget
+ * @param array{getScheme?: non-empty-string, getUserInfo?: non-empty-string, getHost?: non-empty-string, getPort?: positive-int, getPath?: non-empty-string, getQuery?: non-empty-string} $expectations
*/
public function testCanDeserializeRequestWithAbsoluteForm(
string $line,
string $requestTarget,
array $expectations
): void {
+ // @codingStandardsIgnoreEnd
$message = $line . "\r\nX-Foo-Bar: Baz\r\n\r\nContent";
$request = Serializer::fromString($message);
@@ -200,7 +222,7 @@ public function testCanDeserializeRequestWithAsteriskForm(): void
$this->assertSame('www.example.com', $request->getHeaderLine('Host'));
}
- /** @return array */
+ /** @return non-empty-array */
public function invalidRequestLines(): array
{
return [
@@ -213,6 +235,7 @@ public function invalidRequestLines(): array
/**
* @dataProvider invalidRequestLines
+ * @param non-empty-string $line
*/
public function testRaisesExceptionDuringDeserializationForInvalidRequestLine(string $line): void
{
@@ -236,7 +259,7 @@ public function testCanDeserializeRequestWithMultipleHeadersOfSameName(): void
$this->assertSame(['Baz', 'Bat'], $values);
}
- /** @return array */
+ /** @return non-empty-array */
public function headersWithContinuationLines(): array
{
return [
@@ -247,6 +270,7 @@ public function headersWithContinuationLines(): array
/**
* @dataProvider headersWithContinuationLines
+ * @param non-empty-string $text
*/
public function testCanDeserializeRequestWithHeaderContinuations(string $text): void
{
@@ -283,7 +307,7 @@ public function testDeserializationRemovesWhitespaceAroundValues(string $text):
$this->assertSame('Baz', $request->getHeaderLine('X-Foo-Bar'));
}
- /** @return array */
+ /** @return non-empty-array */
public function messagesWithInvalidHeaders(): array
{
return [
@@ -304,6 +328,8 @@ public function messagesWithInvalidHeaders(): array
/**
* @dataProvider messagesWithInvalidHeaders
+ * @param non-empty-string $message
+ * @param non-empty-string $exceptionMessage
*/
public function testDeserializationRaisesExceptionForMalformedHeaders(
string $message,
diff --git a/test/RequestTest.php b/test/RequestTest.php
index e7e134e6..30f32a17 100644
--- a/test/RequestTest.php
+++ b/test/RequestTest.php
@@ -12,7 +12,7 @@
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\UriInterface;
-class RequestTest extends TestCase
+final class RequestTest extends TestCase
{
/** @var Request */
protected $request;
@@ -34,8 +34,8 @@ public function testMethodMutatorReturnsCloneWithChangedMethod(): void
$this->assertEquals('POST', $request->getMethod());
}
- /** @return array */
- public function invalidMethod(): array
+ /** @return non-empty-list */
+ public function invalidMethod()
{
return [
[null],
@@ -118,7 +118,7 @@ public function testDefaultStreamIsWritable(): void
$this->assertSame("test", (string) $request->getBody());
}
- /** @return array */
+ /** @return non-empty-array */
public function invalidRequestUri(): array
{
return [
@@ -144,7 +144,7 @@ public function testConstructorRaisesExceptionForInvalidUri($uri): void
new Request($uri);
}
- /** @return array */
+ /** @return non-empty-array */
public function invalidRequestMethod(): array
{
return [
@@ -154,6 +154,7 @@ public function invalidRequestMethod(): array
/**
* @dataProvider invalidRequestMethod
+ * @param non-empty-string $method
*/
public function testConstructorRaisesExceptionForInvalidMethod(string $method): void
{
@@ -163,7 +164,7 @@ public function testConstructorRaisesExceptionForInvalidMethod(string $method):
new Request(null, $method);
}
- /** @return array */
+ /** @return non-empty-array */
public function customRequestMethods(): array
{
return [
@@ -176,7 +177,6 @@ public function customRequestMethods(): array
'MOVE' => ['MOVE'],
'LOCK' => ['LOCK'],
'UNLOCK' => ['UNLOCK'],
- 'UNLOCK' => ['UNLOCK'],
/* Arbitrary methods */
'#!ALPHA-1234&%' => ['#!ALPHA-1234&%'],
];
@@ -184,6 +184,8 @@ public function customRequestMethods(): array
/**
* @dataProvider customRequestMethods
+ * @group 29
+ * @param non-empty-string $method
*/
public function testAllowsCustomRequestMethodsThatFollowSpec(string $method): void
{
@@ -191,7 +193,7 @@ public function testAllowsCustomRequestMethodsThatFollowSpec(string $method): vo
$this->assertSame($method, $request->getMethod());
}
- /** @return array */
+ /** @return non-empty-array */
public function invalidRequestBody(): array
{
return [
@@ -217,7 +219,7 @@ public function testConstructorRaisesExceptionForInvalidBody($body): void
new Request(null, null, $body);
}
- /** @return array */
+ /** @return non-empty-array */
public function invalidHeaderTypes(): array
{
return [
@@ -231,10 +233,12 @@ public function invalidHeaderTypes(): array
/**
* @dataProvider invalidHeaderTypes
- * @param mixed[] $headers
+ * @group 99
+ * @param mixed $headers
+ * @param non-empty-string $contains
*/
public function testConstructorRaisesExceptionForInvalidHeaders(
- array $headers,
+ $headers,
string $contains = 'header value type'
): void {
$this->expectException(InvalidArgumentException::class);
@@ -256,7 +260,7 @@ public function testRequestTargetIsSlashWhenUriHasNoPathOrQuery(): void
$this->assertSame('/', $request->getRequestTarget());
}
- /** @return array */
+ /** @return non-empty-array */
public function requestsWithUri(): array
{
return [
@@ -289,13 +293,14 @@ public function requestsWithUri(): array
/**
* @dataProvider requestsWithUri
+ * @param non-empty-string $expected
*/
public function testReturnsRequestTargetWhenUriIsPresent(RequestInterface $request, string $expected): void
{
$this->assertSame($expected, $request->getRequestTarget());
}
- /** @return array */
+ /** @return non-empty-array */
public function validRequestTargets(): array
{
return [
@@ -310,6 +315,7 @@ public function validRequestTargets(): array
/**
* @dataProvider validRequestTargets
+ * @param non-empty-string $requestTarget
*/
public function testCanProvideARequestTarget(string $requestTarget): void
{
@@ -343,6 +349,9 @@ public function testSettingNewUriResetsRequestTarget(): void
$this->assertNotSame($request->getRequestTarget(), $newRequest->getRequestTarget());
}
+ /**
+ * @group 39
+ */
public function testGetHeadersContainsHostHeaderIfUriWithHostIsPresent(): void
{
$request = new Request('http://example.com');
@@ -351,6 +360,9 @@ public function testGetHeadersContainsHostHeaderIfUriWithHostIsPresent(): void
$this->assertStringContainsString('example.com', $headers['Host'][0]);
}
+ /**
+ * @group 39
+ */
public function testGetHeadersContainsHostHeaderIfUriWithHostIsDeleted(): void
{
$request = (new Request('http://example.com'))->withoutHeader('host');
@@ -359,6 +371,9 @@ public function testGetHeadersContainsHostHeaderIfUriWithHostIsDeleted(): void
$this->assertContains('example.com', $headers['Host']);
}
+ /**
+ * @group 39
+ */
public function testGetHeadersContainsNoHostHeaderIfNoUriPresent(): void
{
$request = new Request();
@@ -366,6 +381,9 @@ public function testGetHeadersContainsNoHostHeaderIfNoUriPresent(): void
$this->assertArrayNotHasKey('Host', $headers);
}
+ /**
+ * @group 39
+ */
public function testGetHeadersContainsNoHostHeaderIfUriDoesNotContainHost(): void
{
$request = new Request(new Uri());
@@ -373,6 +391,9 @@ public function testGetHeadersContainsNoHostHeaderIfUriDoesNotContainHost(): voi
$this->assertArrayNotHasKey('Host', $headers);
}
+ /**
+ * @group 39
+ */
public function testGetHostHeaderReturnsUriHostWhenPresent(): void
{
$request = new Request('http://example.com');
@@ -380,6 +401,9 @@ public function testGetHostHeaderReturnsUriHostWhenPresent(): void
$this->assertSame(['example.com'], $header);
}
+ /**
+ * @group 39
+ */
public function testGetHostHeaderReturnsUriHostWhenHostHeaderDeleted(): void
{
$request = (new Request('http://example.com'))->withoutHeader('host');
@@ -387,18 +411,27 @@ public function testGetHostHeaderReturnsUriHostWhenHostHeaderDeleted(): void
$this->assertSame(['example.com'], $header);
}
+ /**
+ * @group 39
+ */
public function testGetHostHeaderReturnsEmptyArrayIfNoUriPresent(): void
{
$request = new Request();
$this->assertSame([], $request->getHeader('host'));
}
+ /**
+ * @group 39
+ */
public function testGetHostHeaderReturnsEmptyArrayIfUriDoesNotContainHost(): void
{
$request = new Request(new Uri());
$this->assertSame([], $request->getHeader('host'));
}
+ /**
+ * @group 39
+ */
public function testGetHostHeaderLineReturnsUriHostWhenPresent(): void
{
$request = new Request('http://example.com');
@@ -406,12 +439,18 @@ public function testGetHostHeaderLineReturnsUriHostWhenPresent(): void
$this->assertStringContainsString('example.com', $header);
}
+ /**
+ * @group 39
+ */
public function testGetHostHeaderLineReturnsEmptyStringIfNoUriPresent(): void
{
$request = new Request();
$this->assertEmpty($request->getHeaderLine('host'));
}
+ /**
+ * @group 39
+ */
public function testGetHostHeaderLineReturnsEmptyStringIfUriDoesNotContainHost(): void
{
$request = new Request(new Uri());
@@ -466,7 +505,7 @@ public function testHostHeaderUpdatesToUriHostAndPortWhenPreserveHostDisabledAnd
$this->assertSame('www.example.com:10081', $new->getHeaderLine('Host'));
}
- /** @return array}> */
+ /** @return non-empty-array */
public function headersWithInjectionVectors(): array
{
return [
@@ -487,7 +526,8 @@ public function headersWithInjectionVectors(): array
/**
* @dataProvider headersWithInjectionVectors
- * @param string|list $value
+ * @param non-empty-string $name,
+ * @param non-empty-string|array{non-empty-string} $value
*/
public function testConstructorRaisesExceptionForHeadersWithCRLFVectors(string $name, $value): void
{
@@ -496,7 +536,7 @@ public function testConstructorRaisesExceptionForHeadersWithCRLFVectors(string $
new Request(null, null, 'php://memory', [$name => $value]);
}
- /** @return array */
+ /** @return non-empty-array */
public function hostHeaderKeys(): array
{
return [
@@ -521,6 +561,7 @@ public function hostHeaderKeys(): array
/**
* @dataProvider hostHeaderKeys
+ * @param non-empty-string $hostKey
*/
public function testWithUriAndNoPreserveHostWillOverwriteHostHeaderRegardlessOfOriginalCase(string $hostKey): void
{
diff --git a/test/Response/ArraySerializerTest.php b/test/Response/ArraySerializerTest.php
index 2d032960..4014126f 100644
--- a/test/Response/ArraySerializerTest.php
+++ b/test/Response/ArraySerializerTest.php
@@ -56,6 +56,15 @@ private function createResponse(): Response
->withBody($stream);
}
+ /**
+ * @return array{
+ * status_code: positive-int,
+ * reason_phrase: non-empty-string,
+ * protocol_version: non-empty-string,
+ * headers: array>,
+ * body: string,
+ * }
+ */
private function createSerializedResponse(): array
{
return [
diff --git a/test/Response/HtmlResponseTest.php b/test/Response/HtmlResponseTest.php
index 63cccca1..a794ae2a 100644
--- a/test/Response/HtmlResponseTest.php
+++ b/test/Response/HtmlResponseTest.php
@@ -56,7 +56,7 @@ public function testAllowsStreamsForResponseBody(): void
$this->assertSame($body, $response->getBody());
}
- /** @return array */
+ /** @return array */
public function invalidHtmlContent(): array
{
return [
diff --git a/test/Response/JsonResponseTest.php b/test/Response/JsonResponseTest.php
index 383ddf71..7acf5e76 100644
--- a/test/Response/JsonResponseTest.php
+++ b/test/Response/JsonResponseTest.php
@@ -40,7 +40,7 @@ public function testConstructorAcceptsDataAndCreatesJsonEncodedMessageBody(): vo
$this->assertSame($json, (string) $response->getBody());
}
- /** @return array */
+ /** @return non-empty-array */
public function scalarValuesForJSON()
{
return [
@@ -104,7 +104,7 @@ public function testJsonErrorHandlingOfBadEmbeddedData(): void
new JsonResponse($data);
}
- /** @return array */
+ /** @return non-empty-array */
public function valuesToJsonEncode(): array
{
return [
@@ -116,6 +116,8 @@ public function valuesToJsonEncode(): array
/**
* @dataProvider valuesToJsonEncode
+ * @param non-empty-string $value
+ * @param non-empty-string $key
*/
public function testUsesSaneDefaultJsonEncodingFlags(string $value, string $key): void
{
diff --git a/test/Response/RedirectResponseTest.php b/test/Response/RedirectResponseTest.php
index 76903da1..f695348a 100644
--- a/test/Response/RedirectResponseTest.php
+++ b/test/Response/RedirectResponseTest.php
@@ -46,7 +46,7 @@ public function testConstructorAllowsSpecifyingHeaders(): void
$this->assertSame('Bar', $response->getHeaderLine('X-Foo'));
}
- /** @return array */
+ /** @return non-empty-array */
public function invalidUris(): array
{
return [
diff --git a/test/Response/SerializerTest.php b/test/Response/SerializerTest.php
index f4389d3a..f038c0da 100644
--- a/test/Response/SerializerTest.php
+++ b/test/Response/SerializerTest.php
@@ -12,7 +12,7 @@
use Psr\Http\Message\StreamInterface;
use UnexpectedValueException;
-class SerializerTest extends TestCase
+final class SerializerTest extends TestCase
{
public function testSerializesBasicResponse(): void
{
@@ -99,7 +99,7 @@ public function testCanDeserializeResponseWithMultipleHeadersOfSameName(): void
$this->assertSame(['Baz', 'Bat'], $values);
}
- /** @return array */
+ /** @return non-empty-array */
public function headersWithContinuationLines(): array
{
return [
@@ -110,6 +110,7 @@ public function headersWithContinuationLines(): array
/**
* @dataProvider headersWithContinuationLines
+ * @param non-empty-string $text
*/
public function testCanDeserializeResponseWithHeaderContinuations(string $text): void
{
@@ -197,7 +198,7 @@ public function testDeserializationRaisesExceptionForInvalidStatusLine(): void
Serializer::fromString($text);
}
- /** @return array */
+ /** @return non-empty-array */
public function messagesWithInvalidHeaders(): array
{
return [
@@ -218,6 +219,8 @@ public function messagesWithInvalidHeaders(): array
/**
* @dataProvider messagesWithInvalidHeaders
+ * @param non-empty-string $message
+ * @param non-empty-string $exceptionMessage
*/
public function testDeserializationRaisesExceptionForMalformedHeaders(
string $message,
@@ -259,6 +262,9 @@ public function testFromStreamThrowsExceptionWhenStreamIsNotSeekable(): void
Serializer::fromStream($stream);
}
+ /**
+ * @group 113
+ */
public function testDeserializeCorrectlyCastsStatusCodeToInteger(): void
{
$response = Response\Serializer::fromString('HTTP/1.0 204');
diff --git a/test/Response/TextResponseTest.php b/test/Response/TextResponseTest.php
index 6d2a7314..7baf1c1f 100644
--- a/test/Response/TextResponseTest.php
+++ b/test/Response/TextResponseTest.php
@@ -7,13 +7,10 @@
use InvalidArgumentException;
use Laminas\Diactoros\Response\TextResponse;
use PHPUnit\Framework\TestCase;
-use Prophecy\PhpUnit\ProphecyTrait;
use Psr\Http\Message\StreamInterface;
class TextResponseTest extends TestCase
{
- use ProphecyTrait;
-
public function testConstructorAcceptsBodyAsString(): void
{
$body = 'Uh oh not found';
@@ -50,13 +47,12 @@ public function testConstructorAllowsPassingHeaders(): void
public function testAllowsStreamsForResponseBody(): void
{
- $stream = $this->prophesize(StreamInterface::class);
- $body = $stream->reveal();
+ $body = $this->createMock(StreamInterface::class);
$response = new TextResponse($body);
$this->assertSame($body, $response->getBody());
}
- /** @return array */
+ /** @return non-empty-array */
public function invalidContent(): array
{
return [
@@ -84,6 +80,9 @@ public function testRaisesExceptionForNonStringNonStreamBodyContent($body): void
new TextResponse($body);
}
+ /**
+ * @group 115
+ */
public function testConstructorRewindsBodyStream(): void
{
$text = 'test data';
diff --git a/test/Response/XmlResponseTest.php b/test/Response/XmlResponseTest.php
index 39a12d29..8ba501a6 100644
--- a/test/Response/XmlResponseTest.php
+++ b/test/Response/XmlResponseTest.php
@@ -7,15 +7,12 @@
use InvalidArgumentException;
use Laminas\Diactoros\Response\XmlResponse;
use PHPUnit\Framework\TestCase;
-use Prophecy\PhpUnit\ProphecyTrait;
use Psr\Http\Message\StreamInterface;
use const PHP_EOL;
class XmlResponseTest extends TestCase
{
- use ProphecyTrait;
-
public function testConstructorAcceptsBodyAsString(): void
{
$body = 'Super valid XML';
@@ -52,13 +49,12 @@ public function testConstructorAllowsPassingHeaders(): void
public function testAllowsStreamsForResponseBody(): void
{
- $stream = $this->prophesize(StreamInterface::class);
- $body = $stream->reveal();
+ $body = $this->createMock(StreamInterface::class);
$response = new XmlResponse($body);
$this->assertSame($body, $response->getBody());
}
- /** @return array */
+ /** @return non-empty-array */
public function invalidContent(): array
{
return [
@@ -78,7 +74,7 @@ public function invalidContent(): array
* @dataProvider invalidContent
* @param mixed $body
*/
- public function testRaisesExceptionforNonStringNonStreamBodyContent($body)
+ public function testRaisesExceptionforNonStringNonStreamBodyContent($body): void
{
$this->expectException(InvalidArgumentException::class);
@@ -86,6 +82,9 @@ public function testRaisesExceptionforNonStringNonStreamBodyContent($body)
new XmlResponse($body);
}
+ /**
+ * @group 115
+ */
public function testConstructorRewindsBodyStream(): void
{
$body = '' . PHP_EOL . 'Valid XML';
diff --git a/test/ResponseTest.php b/test/ResponseTest.php
index 1836a405..3e417cb2 100644
--- a/test/ResponseTest.php
+++ b/test/ResponseTest.php
@@ -33,7 +33,7 @@
use const CURLOPT_USERAGENT;
use const LOCK_EX;
-class ResponseTest extends TestCase
+final class ResponseTest extends TestCase
{
/** @var Response */
protected $response;
@@ -119,7 +119,7 @@ private function fetchIanaStatusCodes(): DOMDocument
self::fail('Unable to retrieve IANA response status codes due to timeout or invalid XML');
}
- /** @return list */
+ /** @return list */
public function ianaCodesReasonPhrasesProvider(): array
{
$ianaHttpStatusCodes = $this->fetchIanaStatusCodes();
@@ -153,9 +153,10 @@ public function ianaCodesReasonPhrasesProvider(): array
/**
* @dataProvider ianaCodesReasonPhrasesProvider
- * @param string|numeric $code
+ * @param numeric-string $code
+ * @param non-empty-string $reasonPhrase
*/
- public function testReasonPhraseDefaultsAgainstIana($code, string $reasonPhrase): void
+ public function testReasonPhraseDefaultsAgainstIana(string $code, string $reasonPhrase): void
{
/** @psalm-suppress InvalidScalarArgument */
$response = $this->response->withStatus($code);
@@ -168,7 +169,7 @@ public function testCanSetCustomReasonPhrase(): void
$this->assertSame('Foo Bar!', $response->getReasonPhrase());
}
- /** @return array */
+ /** @return non-empty-array */
public function invalidReasonPhrases(): array
{
return [
@@ -218,7 +219,7 @@ public function testConstructorCanAcceptAllMessageParts(): void
/**
* @dataProvider validStatusCodes
- * @param numeric $code
+ * @param int|numeric-string $code
*/
public function testCreateWithValidStatusCodes($code): void
{
@@ -231,7 +232,7 @@ public function testCreateWithValidStatusCodes($code): void
$this->assertIsInt($result);
}
- /** @return array */
+ /** @return non-empty-array */
public function validStatusCodes(): array
{
return [
@@ -254,7 +255,7 @@ public function testCannotSetInvalidStatusCode($code): void
$this->response->withStatus($code);
}
- /** @return array */
+ /** @return non-empty-array */
public function invalidStatusCodes(): array
{
return [
@@ -270,7 +271,7 @@ public function invalidStatusCodes(): array
];
}
- /** @return array */
+ /** @return non-empty-array */
public function invalidResponseBody(): array
{
return [
@@ -296,7 +297,7 @@ public function testConstructorRaisesExceptionForInvalidBody($body): void
new Response($body);
}
- /** @return array */
+ /** @return non-empty-array, 1?: non-empty-string}> */
public function invalidHeaderTypes(): array
{
return [
@@ -310,6 +311,9 @@ public function invalidHeaderTypes(): array
/**
* @dataProvider invalidHeaderTypes
+ * @group 99
+ * @param array $headers
+ * @param non-empty-string $contains
*/
public function testConstructorRaisesExceptionForInvalidHeaders(
array $headers,
@@ -328,7 +332,7 @@ public function testReasonPhraseCanBeEmpty(): void
$this->assertEmpty($response->getReasonPhrase());
}
- /** @return array}> */
+ /** @return non-empty-array}> */
public function headersWithInjectionVectors(): array
{
return [
@@ -350,6 +354,7 @@ public function headersWithInjectionVectors(): array
/**
* @param string|list $value
* @dataProvider headersWithInjectionVectors
+ * @param string|non-empty-list $value
*/
public function testConstructorRaisesExceptionForHeadersWithCRLFVectors(string $name, $value): void
{
diff --git a/test/ServerRequestFactoryTest.php b/test/ServerRequestFactoryTest.php
index 290db389..1a9290e6 100644
--- a/test/ServerRequestFactoryTest.php
+++ b/test/ServerRequestFactoryTest.php
@@ -4,7 +4,6 @@
namespace LaminasTest\Diactoros;
-use Generator;
use Laminas\Diactoros\ServerRequest;
use Laminas\Diactoros\ServerRequestFactory;
use Laminas\Diactoros\ServerRequestFilter\DoNotFilter;
@@ -26,7 +25,7 @@
use function strpos;
use function strtolower;
-class ServerRequestFactoryTest extends TestCase
+final class ServerRequestFactoryTest extends TestCase
{
public function testReturnsServerValueUnchangedIfHttpAuthorizationHeaderIsPresent(): void
{
@@ -255,9 +254,7 @@ public function testMarshalHostAndPortWillDetectPortInIpv6StyleHost(): void
$this->assertNull($uri->getPort());
}
- /**
- * @return array
- */
+ /** @return non-empty-array */
public function httpsParamProvider(): array
{
return [
@@ -268,6 +265,7 @@ public function httpsParamProvider(): array
/**
* @dataProvider httpsParamProvider
+ * @param non-empty-string $param
*/
public function testMarshalUriDetectsHttpsSchemeFromServerValue(string $param): void
{
@@ -285,10 +283,8 @@ public function testMarshalUriDetectsHttpsSchemeFromServerValue(string $param):
$this->assertSame('https', $uri->getScheme());
}
- /**
- * @return Generator
- */
- public function httpsDisableParamProvider(): Generator
+ /** @return iterable */
+ public function httpsDisableParamProvider(): iterable
{
foreach ($this->httpsParamProvider() as $key => $data) {
$param = array_shift($data);
@@ -302,6 +298,8 @@ public function httpsDisableParamProvider(): Generator
/**
* @dataProvider httpsDisableParamProvider
+ * @param non-empty-string $param
+ * @param 'off'|'OFF' $value
*/
public function testMarshalUriUsesHttpSchemeIfHttpsServerValueEqualsOff(string $param, string $value): void
{
@@ -321,6 +319,7 @@ public function testMarshalUriUsesHttpSchemeIfHttpsServerValueEqualsOff(string $
/**
* @dataProvider httpsParamProvider
+ * @param non-empty-string $xForwardedProto
*/
public function testMarshalUriDetectsHttpsSchemeFromXForwardedProtoValue(string $xForwardedProto): void
{
@@ -481,7 +480,7 @@ public function testFromGlobalsUsesCookieSuperGlobalWhenCookieHeaderIsNotSet():
$this->assertSame(['foo_bar' => 'bat'], $request->getCookieParams());
}
- /** @return array */
+ /** @return non-empty-array}> */
public function cookieHeaderValues(): array
{
return [
@@ -514,7 +513,8 @@ public function cookieHeaderValues(): array
/**
* @dataProvider cookieHeaderValues
- * @param array $expectedCookies
+ * @param non-empty-string $cookieHeader
+ * @param array $expectedCookies
*/
public function testCookieHeaderVariations(string $cookieHeader, array $expectedCookies): void
{
@@ -555,6 +555,10 @@ public function testNormalizeServerReturnsArrayUnalteredIfApacheHeadersDoNotCont
$this->assertSame($expected, $server);
}
+ /**
+ * @group 57
+ * @group 56
+ */
public function testNormalizeFilesReturnsOnlyActualFilesWhenOriginalFilesContainsNestedAssociativeArrays(): void
{
$files = [
@@ -586,6 +590,8 @@ public function testMarshalProtocolReturnsDefaultValueIfHeaderIsNotPresent(): vo
/**
* @dataProvider marshalProtocolVersionProvider
+ * @param non-empty-string $protocol
+ * @param non-empty-string $expected
*/
public function testMarshalProtocolVersionReturnsHttpVersions(string $protocol, string $expected): void
{
@@ -593,7 +599,7 @@ public function testMarshalProtocolVersionReturnsHttpVersions(string $protocol,
$this->assertSame($expected, $version);
}
- /** @return array */
+ /** @return non-empty-array */
public function marshalProtocolVersionProvider(): array
{
return [
diff --git a/test/ServerRequestTest.php b/test/ServerRequestTest.php
index c80e0f3f..b3216217 100644
--- a/test/ServerRequestTest.php
+++ b/test/ServerRequestTest.php
@@ -11,7 +11,7 @@
use PHPUnit\Framework\TestCase;
use ReflectionProperty;
-class ServerRequestTest extends TestCase
+final class ServerRequestTest extends TestCase
{
/** @var ServerRequest */
protected $request;
@@ -101,7 +101,7 @@ public function testRemovingAttributeReturnsCloneWithoutAttribute(ServerRequest
$this->assertNull($new->getAttribute('foo', null));
}
- /** @return array */
+ /** @return non-empty-array */
public function provideMethods(): array
{
return [
@@ -113,6 +113,8 @@ public function provideMethods(): array
/**
* @dataProvider provideMethods
+ * @param non-empty-string|null $parameterMethod
+ * @param non-empty-string $methodReturned
*/
public function testUsesProvidedConstructorArguments(?string $parameterMethod, string $methodReturned): void
{
@@ -171,6 +173,9 @@ public function testUsesProvidedConstructorArguments(?string $parameterMethod, s
$this->assertSame('php://memory', $stream);
}
+ /**
+ * @group 46
+ */
public function testCookieParamsAreAnEmptyArrayAtInitialization(): void
{
$request = new ServerRequest();
@@ -178,6 +183,9 @@ public function testCookieParamsAreAnEmptyArrayAtInitialization(): void
$this->assertCount(0, $request->getCookieParams());
}
+ /**
+ * @group 46
+ */
public function testQueryParamsAreAnEmptyArrayAtInitialization(): void
{
$request = new ServerRequest();
@@ -185,6 +193,9 @@ public function testQueryParamsAreAnEmptyArrayAtInitialization(): void
$this->assertCount(0, $request->getQueryParams());
}
+ /**
+ * @group 46
+ */
public function testParsedBodyIsNullAtInitialization(): void
{
$request = new ServerRequest();
diff --git a/test/StreamTest.php b/test/StreamTest.php
index 2b150cf6..e86e6e4e 100644
--- a/test/StreamTest.php
+++ b/test/StreamTest.php
@@ -32,10 +32,10 @@
use const DIRECTORY_SEPARATOR;
-class StreamTest extends TestCase
+final class StreamTest extends TestCase
{
- /** @var string|null */
- public $tmpnam;
+ /** @var string|null|false */
+ private $tmpnam;
/** @var Stream */
protected $stream;
@@ -146,6 +146,9 @@ public function testCloseDoesNothingAfterDetach(): void
$this->assertSame($resource, $detached);
}
+ /**
+ * @group 42
+ */
public function testSizeReportsNullWhenNoResourcePresent(): void
{
$this->stream->detach();
@@ -286,7 +289,7 @@ public function testIsWritableReturnsTrueForWritableMemoryStream(): void
$this->assertTrue($stream->isWritable());
}
- /** @return array */
+ /** @return non-empty-list */
public function provideDataForIsWritable(): array
{
return [
@@ -316,19 +319,18 @@ public function provideDataForIsWritable(): array
private function findNonExistentTempName(): string
{
- while (true) {
+ do {
$tmpnam = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'diac' . uniqid();
- if (! file_exists(sys_get_temp_dir() . $tmpnam)) {
- break;
- }
- }
+ } while (file_exists(sys_get_temp_dir() . $tmpnam));
+
return $tmpnam;
}
/**
* @dataProvider provideDataForIsWritable
+ * @param non-empty-string $mode
*/
- public function testIsWritableReturnsCorrectFlagForMode(string $mode, bool $fileShouldExist, bool $flag): void
+ public function testIsWritableReturnsCorrectFlagForMode(string $mode, bool $fileShouldExist, bool $flag)
{
if ($fileShouldExist) {
$this->tmpnam = tempnam(sys_get_temp_dir(), 'diac');
@@ -342,7 +344,7 @@ public function testIsWritableReturnsCorrectFlagForMode(string $mode, bool $file
$this->assertSame($flag, $stream->isWritable());
}
- /** @return array */
+ /** @return non-empty-list */
public function provideDataForIsReadable(): array
{
return [
@@ -372,6 +374,7 @@ public function provideDataForIsReadable(): array
/**
* @dataProvider provideDataForIsReadable
+ * @param non-empty-string $mode
*/
public function testIsReadableReturnsCorrectFlagForMode(string $mode, bool $fileShouldExist, bool $flag): void
{
@@ -460,7 +463,7 @@ public function testGetContentsRisesExceptionIfStreamIsNotReadable(): void
$stream->getContents();
}
- /** @return array */
+ /** @return non-empty-array */
public function invalidResources(): array
{
$this->tmpnam = tempnam(sys_get_temp_dir(), 'diac');
@@ -584,6 +587,9 @@ public function testGetMetadataReturnsNullIfNoDataExistsForKey(): void
$this->assertNull($this->stream->getMetadata('TOTALLY_MADE_UP'));
}
+ /**
+ * @group 42
+ */
public function testGetSizeReturnsStreamSize(): void
{
$resource = fopen(__FILE__, 'r');
@@ -592,6 +598,9 @@ public function testGetSizeReturnsStreamSize(): void
$this->assertSame($expected['size'], $stream->getSize());
}
+ /**
+ * @group 67
+ */
public function testRaisesExceptionOnConstructionForNonStreamResources(): void
{
$resource = $this->getResourceFor67();
@@ -606,6 +615,9 @@ public function testRaisesExceptionOnConstructionForNonStreamResources(): void
new Stream($resource);
}
+ /**
+ * @group 67
+ */
public function testRaisesExceptionOnAttachForNonStreamResources(): void
{
$resource = $this->getResourceFor67();
@@ -657,6 +669,9 @@ public function testCanReadContentFromNotSeekableResource(): void
$this->assertSame('FOO BAR', $stream->__toString());
}
+ /**
+ * @group 42
+ */
public function testSizeReportsNullForPhpInputStreams(): void
{
$resource = fopen('php://input', 'r');
diff --git a/test/UriTest.php b/test/UriTest.php
index 1adb0eec..e53303d1 100644
--- a/test/UriTest.php
+++ b/test/UriTest.php
@@ -87,7 +87,7 @@ public function testWithUserInfoReturnsSameInstanceIfUserAndPasswordAreSameAsBef
$this->assertSame('https://user:pass@local.example.com:3001/foo?bar=baz#quz', (string) $new);
}
- /** @return array */
+ /** @return non-empty-array */
public function userInfoProvider(): array
{
// @codingStandardsIgnoreStart
@@ -105,6 +105,9 @@ public function userInfoProvider(): array
/**
* @dataProvider userInfoProvider
+ * @param non-empty-string $user
+ * @param non-empty-string $credential
+ * @param non-empty-string $expected
*/
public function testWithUserInfoEncodesUsernameAndPassword(string $user, string $credential, string $expected): void
{
@@ -132,7 +135,7 @@ public function testWithHostReturnsSameInstanceWithProvidedHostIsSameAsBefore():
$this->assertSame('https://user:pass@local.example.com:3001/foo?bar=baz#quz', (string) $new);
}
- /** @return array */
+ /** @return non-empty-array */
public function validPorts(): array
{
return [
@@ -144,7 +147,7 @@ public function validPorts(): array
/**
* @dataProvider validPorts
- * @param numeric|null $port
+ * @param null|positive-int|numeric-string $port
*/
public function testWithPortReturnsNewInstanceWithProvidedPort($port): void
{
@@ -168,7 +171,7 @@ public function testWithPortReturnsSameInstanceWithProvidedPortIsSameAsBefore():
$this->assertSame(3001, $new->getPort());
}
- /** @return array */
+ /** @return non-empty-array */
public function invalidPorts(): array
{
return [
@@ -217,7 +220,7 @@ public function testWithPathReturnsSameInstanceWithProvidedPathSameAsBefore(): v
$this->assertSame('https://user:pass@local.example.com:3001/foo?bar=baz#quz', (string) $new);
}
- /** @return array */
+ /** @return non-empty-array */
public function invalidPaths(): array
{
return [
@@ -255,7 +258,7 @@ public function testWithQueryReturnsNewInstanceWithProvidedQuery(): void
$this->assertSame('https://user:pass@local.example.com:3001/foo?baz=bat#quz', (string) $new);
}
- /** @return array */
+ /** @return non-empty-array */
public function invalidQueryStrings(): array
{
return [
@@ -301,7 +304,7 @@ public function testWithFragmentReturnsSameInstanceWithProvidedFragmentSameAsBef
$this->assertSame('https://user:pass@local.example.com:3001/foo?bar=baz#quz', (string) $new);
}
- /** @return array */
+ /** @return non-empty-array */
public function authorityInfo(): array
{
return [
@@ -314,6 +317,8 @@ public function authorityInfo(): array
/**
* @dataProvider authorityInfo
+ * @param non-empty-string $url
+ * @param non-empty-string $expected
*/
public function testRetrievingAuthorityReturnsExpectedValues(string $url, string $expected): void
{
@@ -374,7 +379,7 @@ public function testESchemeStripsOffDelimiter(): void
$this->assertSame('', $new->getScheme());
}
- /** @return array */
+ /** @return non-empty-array */
public function invalidSchemes(): array
{
return [
@@ -388,6 +393,7 @@ public function invalidSchemes(): array
/**
* @dataProvider invalidSchemes
+ * @param non-empty-string $scheme
*/
public function testConstructWithUnsupportedSchemeRaisesAnException(string $scheme): void
{
@@ -399,6 +405,7 @@ public function testConstructWithUnsupportedSchemeRaisesAnException(string $sche
/**
* @dataProvider invalidSchemes
+ * @param non-empty-string $scheme
*/
public function testMutatingWithUnsupportedSchemeRaisesAnException(string $scheme): void
{
@@ -438,7 +445,7 @@ public function testEncodeFragmentPrefixIfPresent(): void
$this->assertSame('%23/foo/bar', $new->getFragment());
}
- /** @return array */
+ /** @return non-empty-array */
public function standardSchemePortCombinations(): array
{
return [
@@ -449,6 +456,8 @@ public function standardSchemePortCombinations(): array
/**
* @dataProvider standardSchemePortCombinations
+ * @param non-empty-string $scheme
+ * @param positive-int $port
*/
public function testAuthorityOmitsPortForStandardSchemePortCombinations(string $scheme, int $port): void
{
@@ -459,7 +468,7 @@ public function testAuthorityOmitsPortForStandardSchemePortCombinations(string $
$this->assertSame('example.com', $uri->getAuthority());
}
- /** @return array */
+ /** @return non-empty-array */
public function mutations(): array
{
return [
@@ -475,7 +484,8 @@ public function mutations(): array
/**
* @dataProvider mutations
- * @param string|int $value
+ * @param 'withScheme'|'withUserInfo'|'withHost'|'withPort'|'withPath'|'withQuery'|'withFragment' $method
+ * @param non-empty-string|positive-int $value
*/
public function testMutationResetsUriStringPropertyInClone(string $method, $value): void
{
@@ -496,6 +506,9 @@ public function testMutationResetsUriStringPropertyInClone(string $method, $valu
$this->assertSame($string, $p->getValue($uri));
}
+ /**
+ * @group 40
+ */
public function testPathIsProperlyEncoded(): void
{
$uri = (new Uri())->withPath('/foo^bar');
@@ -510,7 +523,7 @@ public function testPathDoesNotBecomeDoubleEncoded(): void
$this->assertSame($expected, $uri->getPath());
}
- /** @return array */
+ /** @return non-empty-array */
public function queryStringsForEncoding(): array
{
return [
@@ -524,6 +537,8 @@ public function queryStringsForEncoding(): array
/**
* @dataProvider queryStringsForEncoding
+ * @param non-empty-string $query
+ * @param non-empty-string $expected
*/
public function testQueryIsProperlyEncoded(string $query, string $expected): void
{
@@ -533,6 +548,8 @@ public function testQueryIsProperlyEncoded(string $query, string $expected): voi
/**
* @dataProvider queryStringsForEncoding
+ * @param non-empty-string $query
+ * @param non-empty-string $expected
*/
public function testQueryIsNotDoubleEncoded(string $query, string $expected): void
{
@@ -540,6 +557,9 @@ public function testQueryIsNotDoubleEncoded(string $query, string $expected): vo
$this->assertSame($expected, $uri->getQuery());
}
+ /**
+ * @group 40
+ */
public function testFragmentIsProperlyEncoded(): void
{
$uri = (new Uri())->withFragment('/p^th?key^=`bar#b@z');
@@ -547,6 +567,9 @@ public function testFragmentIsProperlyEncoded(): void
$this->assertSame($expected, $uri->getFragment());
}
+ /**
+ * @group 40
+ */
public function testFragmentIsNotDoubleEncoded(): void
{
$expected = '/p%5Eth?key%5E=%60bar%23b@z';
@@ -561,7 +584,7 @@ public function testProperlyTrimsLeadingSlashesToPreventXSS(): void
$this->assertSame('http://example.org/zend.com', (string) $uri);
}
- /** @return array */
+ /** @return non-empty-array */
public function invalidStringComponentValues(): array
{
$methods = [
@@ -598,6 +621,7 @@ public function invalidStringComponentValues(): array
/**
* @dataProvider invalidStringComponentValues
+ * @param 'withScheme'|'withUserInfo'|'withHost'|'withPath'|'withQuery'|'withFragment' $method
* @param mixed $value
*/
public function testPassingInvalidValueToWithMethodRaisesException(string $method, $value): void
@@ -618,6 +642,8 @@ public function testUtf8Uri(): void
/**
* @dataProvider utf8PathsDataProvider
+ * @param non-empty-string $url
+ * @param non-empty-string $result
*/
public function testUtf8Path(string $url, string $result): void
{
@@ -626,7 +652,7 @@ public function testUtf8Path(string $url, string $result): void
$this->assertSame($result, $uri->getPath());
}
- /** @return array */
+ /** @return non-empty-list */
public function utf8PathsDataProvider(): array
{
return [
@@ -639,6 +665,8 @@ public function utf8PathsDataProvider(): array
/**
* @dataProvider utf8QueryStringsDataProvider
+ * @param non-empty-string $url
+ * @param non-empty-string $result
*/
public function testUtf8Query(string $url, string $result): void
{
@@ -647,7 +675,7 @@ public function testUtf8Query(string $url, string $result): void
$this->assertSame($result, $uri->getQuery());
}
- /** @return array */
+ /** @return non-empty-list */
public function utf8QueryStringsDataProvider(): array
{
return [
diff --git a/test/functions/MarshalUriFromSapiTest.php b/test/functions/MarshalUriFromSapiTest.php
index ee85a3cd..c78d459a 100644
--- a/test/functions/MarshalUriFromSapiTest.php
+++ b/test/functions/MarshalUriFromSapiTest.php
@@ -56,7 +56,7 @@ public function testReturnsUrlWithCorrectHttpSchemeFromArrays(string $httpsValue
self::assertSame($expectedScheme, $url->getScheme());
}
- /** @return array */
+ /** @return array */
public function returnsUrlWithCorrectHttpSchemeFromArraysProvider(): array
{
return [
@@ -83,7 +83,7 @@ public function testReturnsUrlWithCorrectSchemeAndHostFromArrays(
self::assertSame($expectedHost, $uri->getHost());
}
- /** @return array */
+ /** @return array, array}> */
public function returnsUrlWithCorrectSchemeAndHostFromArrays(): array
{
return [