From 6252e91831b94d3d9ca0cbf4ca48d8543d9a8423 Mon Sep 17 00:00:00 2001 From: Anatoly Nekhay Date: Sat, 13 May 2023 02:44:10 +0200 Subject: [PATCH] Improve tests --- tests/BaseMessageTest.php | 8 +++---- tests/BaseRequestTest.php | 2 +- .../UploadedFileIntegrationTest.php | 7 ++++++ tests/RequestFactoryTest.php | 2 +- tests/ServerRequestFactoryTest.php | 8 +++---- tests/StreamFactoryTest.php | 2 +- tests/StreamTest.php | 24 +++++++++---------- tests/UploadedFileTest.php | 7 +++--- tests/UriTest.php | 2 +- 9 files changed, 35 insertions(+), 27 deletions(-) diff --git a/tests/BaseMessageTest.php b/tests/BaseMessageTest.php index 2b75e1f..af6d133 100644 --- a/tests/BaseMessageTest.php +++ b/tests/BaseMessageTest.php @@ -70,7 +70,7 @@ public function testSetProtocolVersion($protocolVersion): void public function testSetProtocolVersionAsNull(): void { $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('Invalid or unsupported HTTP version'); + $this->expectExceptionMessage('Unallowed HTTP version'); $this->createSubject()->withProtocolVersion(null); } @@ -78,7 +78,7 @@ public function testSetProtocolVersionAsNull(): void public function testSetProtocolVersionAsNumber(): void { $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('Invalid or unsupported HTTP version'); + $this->expectExceptionMessage('Unallowed HTTP version'); $this->createSubject()->withProtocolVersion(1.1); } @@ -89,7 +89,7 @@ public function testSetProtocolVersionAsNumber(): void public function testSetInvalidProtocolVersion($protocolVersion): void { $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('Invalid or unsupported HTTP version'); + $this->expectExceptionMessage('Unallowed HTTP version'); $this->createSubject()->withProtocolVersion($protocolVersion); } @@ -645,7 +645,7 @@ public function testConstructorWithProtocolVersion(string $protocolVersion): voi public function testConstructorWithInvalidProtocolVersion(string $protocolVersion): void { $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('Invalid or unsupported HTTP version'); + $this->expectExceptionMessage('Unallowed HTTP version'); $subject = $this->createSubjectWithProtocolVersion($protocolVersion); diff --git a/tests/BaseRequestTest.php b/tests/BaseRequestTest.php index 326ab3a..8d9f6bf 100644 --- a/tests/BaseRequestTest.php +++ b/tests/BaseRequestTest.php @@ -398,7 +398,7 @@ public function testConstructorWithStringUri(): void public function testConstructorWithInvalidUri(): void { $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('Unable to parse URI'); + $this->expectExceptionMessage('Invalid URI'); $subject = $this->createSubjectWithUri(':'); diff --git a/tests/Integration/UploadedFileIntegrationTest.php b/tests/Integration/UploadedFileIntegrationTest.php index 900b3ea..fe5a859 100644 --- a/tests/Integration/UploadedFileIntegrationTest.php +++ b/tests/Integration/UploadedFileIntegrationTest.php @@ -12,6 +12,13 @@ class UploadedFileIntegrationTest extends BaseUploadedFileIntegrationTest { + /** + * {@inheritdoc} + */ + protected $skippedTests = [ + 'testGetSize' => 'The test does not conform to the required behavior described in PSR-7', + ]; + /** * {@inheritdoc} */ diff --git a/tests/RequestFactoryTest.php b/tests/RequestFactoryTest.php index 8672209..c1cde0b 100644 --- a/tests/RequestFactoryTest.php +++ b/tests/RequestFactoryTest.php @@ -70,7 +70,7 @@ public function testCreateRequestWithStringUri(): void public function testCreateRequestWithInvalidUri(): void { $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('Unable to parse URI'); + $this->expectExceptionMessage('Invalid URI'); (new RequestFactory)->createRequest('GET', ':'); } diff --git a/tests/ServerRequestFactoryTest.php b/tests/ServerRequestFactoryTest.php index c3f2b71..ad89982 100644 --- a/tests/ServerRequestFactoryTest.php +++ b/tests/ServerRequestFactoryTest.php @@ -74,7 +74,7 @@ public function testCreateServerRequestWithStringUri(): void public function testCreateServerRequestWithInvalidUri(): void { $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('Unable to parse URI'); + $this->expectExceptionMessage('Invalid URI'); (new ServerRequestFactory)->createServerRequest('GET', ':'); } @@ -101,7 +101,7 @@ public function testCreateServerRequestWithServerParamsWithProtocolVersion( public function testCreateServerRequestWithServerParamsWithUnsupportedProtocolVersion(): void { $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('Invalid or unsupported HTTP version'); + $this->expectExceptionMessage('Unallowed HTTP version'); (new ServerRequestFactory)->createServerRequest('GET', new Uri(), ['SERVER_PROTOCOL' => 'HTTP/3']); } @@ -195,7 +195,7 @@ public function testCreateServerRequestFromGlobalsWithUnsupportedProtocolVersion $_SERVER = ['SERVER_PROTOCOL' => 'HTTP/3']; $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('Invalid or unsupported HTTP version'); + $this->expectExceptionMessage('Unallowed HTTP version'); ServerRequestFactory::fromGlobals(); } @@ -267,7 +267,7 @@ public function testCreateServerRequestFromGlobalsWithInvalidUri(): void $_SERVER = ['HTTP_HOST' => 'localhost:65536']; $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('Unable to parse URI'); + $this->expectExceptionMessage('Invalid URI'); ServerRequestFactory::fromGlobals(); } diff --git a/tests/StreamFactoryTest.php b/tests/StreamFactoryTest.php index a9d4e24..78bda08 100644 --- a/tests/StreamFactoryTest.php +++ b/tests/StreamFactoryTest.php @@ -55,7 +55,7 @@ public function testCreateStreamFromFileWithMode(): void public function testCreateStreamFromInvalidFile(): void { - $this->expectException(RuntimeException::class); + $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage( 'Unable to open the file "/55EF8096-7A6A-4C85-9BCD-6A5958376AB8" in the mode "r"' ); diff --git a/tests/StreamTest.php b/tests/StreamTest.php index 37fd891..f3f968b 100644 --- a/tests/StreamTest.php +++ b/tests/StreamTest.php @@ -149,7 +149,7 @@ public function testTellAfterDetach(): void $this->testStream->detach(); $this->expectException(RuntimeException::class); - $this->expectExceptionMessage('The stream does not have a resource, so the operation is not possible'); + $this->expectExceptionMessage('Stream has no resource'); $this->testStream->tell(); } @@ -159,7 +159,7 @@ public function testTellAfterClose(): void $this->testStream->close(); $this->expectException(RuntimeException::class); - $this->expectExceptionMessage('The stream does not have a resource, so the operation is not possible'); + $this->expectExceptionMessage('Stream has no resource'); $this->testStream->tell(); } @@ -210,7 +210,7 @@ public function testRewindAfterDetach(): void $this->testStream->detach(); $this->expectException(RuntimeException::class); - $this->expectExceptionMessage('The stream does not have a resource, so the operation is not possible'); + $this->expectExceptionMessage('Stream has no resource'); $this->testStream->rewind(); } @@ -220,7 +220,7 @@ public function testRewindAfterClose(): void $this->testStream->close(); $this->expectException(RuntimeException::class); - $this->expectExceptionMessage('The stream does not have a resource, so the operation is not possible'); + $this->expectExceptionMessage('Stream has no resource'); $this->testStream->rewind(); } @@ -247,7 +247,7 @@ public function testSeekAfterDetach(): void $this->testStream->detach(); $this->expectException(RuntimeException::class); - $this->expectExceptionMessage('The stream does not have a resource, so the operation is not possible'); + $this->expectExceptionMessage('Stream has no resource'); $this->testStream->seek(0); } @@ -257,7 +257,7 @@ public function testSeekAfterClose(): void $this->testStream->close(); $this->expectException(RuntimeException::class); - $this->expectExceptionMessage('The stream does not have a resource, so the operation is not possible'); + $this->expectExceptionMessage('Stream has no resource'); $this->testStream->seek(0); } @@ -315,7 +315,7 @@ public function testWriteAfterDetach(): void $this->testStream->detach(); $this->expectException(RuntimeException::class); - $this->expectExceptionMessage('The stream does not have a resource, so the operation is not possible'); + $this->expectExceptionMessage('Stream has no resource'); $this->testStream->write('foo'); } @@ -325,7 +325,7 @@ public function testWriteAfterClose(): void $this->testStream->close(); $this->expectException(RuntimeException::class); - $this->expectExceptionMessage('The stream does not have a resource, so the operation is not possible'); + $this->expectExceptionMessage('Stream has no resource'); $this->testStream->write('foo'); } @@ -375,7 +375,7 @@ public function testReadAfterDetach(): void $this->testStream->detach(); $this->expectException(RuntimeException::class); - $this->expectExceptionMessage('The stream does not have a resource, so the operation is not possible'); + $this->expectExceptionMessage('Stream has no resource'); $this->testStream->read(1); } @@ -385,7 +385,7 @@ public function testReadAfterClose(): void $this->testStream->close(); $this->expectException(RuntimeException::class); - $this->expectExceptionMessage('The stream does not have a resource, so the operation is not possible'); + $this->expectExceptionMessage('Stream has no resource'); $this->testStream->read(1); } @@ -412,7 +412,7 @@ public function testGetContentsAfterDetach(): void $this->testStream->detach(); $this->expectException(RuntimeException::class); - $this->expectExceptionMessage('The stream does not have a resource, so the operation is not possible'); + $this->expectExceptionMessage('Stream has no resource'); $this->testStream->getContents(); } @@ -422,7 +422,7 @@ public function testGetContentsAfterClose(): void $this->testStream->close(); $this->expectException(RuntimeException::class); - $this->expectExceptionMessage('The stream does not have a resource, so the operation is not possible'); + $this->expectExceptionMessage('Stream has no resource'); $this->testStream->getContents(); } diff --git a/tests/UploadedFileTest.php b/tests/UploadedFileTest.php index ba0c0f3..1a3adc4 100644 --- a/tests/UploadedFileTest.php +++ b/tests/UploadedFileTest.php @@ -6,6 +6,7 @@ use PHPUnit\Framework\TestCase; use Psr\Http\Message\UploadedFileInterface; +use Sunrise\Http\Message\Exception\InvalidArgumentException; use Sunrise\Http\Message\Exception\RuntimeException; use Sunrise\Http\Message\Stream\FileStream; use Sunrise\Http\Message\Stream\PhpTempStream; @@ -159,10 +160,10 @@ public function testMoveUnwritableDirectory(): void { $file = new UploadedFile(new PhpTempStream()); - $this->expectException(RuntimeException::class); + $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage( - 'Uploaded file cannot be moved because ' . - 'the directory "/4c32dad5-181f-46b7-a86a-15568e11fdf9" is not writable' + 'Uploaded file cannot be moved due to the error: ' . + 'Unable to open the file "/4c32dad5-181f-46b7-a86a-15568e11fdf9/foo" in the mode "wb"' ); $file->moveTo('/4c32dad5-181f-46b7-a86a-15568e11fdf9/foo'); diff --git a/tests/UriTest.php b/tests/UriTest.php index 9fe42ff..7cf3461 100644 --- a/tests/UriTest.php +++ b/tests/UriTest.php @@ -48,7 +48,7 @@ public function testConstructorWithEmptyUri(): void public function testConstructorWithInvalidUri(): void { $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('Unable to parse URI'); + $this->expectExceptionMessage('Invalid URI'); new Uri(':'); }