Skip to content

Commit

Permalink
Improve tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fenric committed May 13, 2023
1 parent 59a3266 commit 6252e91
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 27 deletions.
8 changes: 4 additions & 4 deletions tests/BaseMessageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,15 @@ 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);
}

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);
}
Expand All @@ -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);
}
Expand Down Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion tests/BaseRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(':');

Expand Down
7 changes: 7 additions & 0 deletions tests/Integration/UploadedFileIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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}
*/
Expand Down
2 changes: 1 addition & 1 deletion tests/RequestFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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', ':');
}
Expand Down
8 changes: 4 additions & 4 deletions tests/ServerRequestFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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', ':');
}
Expand All @@ -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']);
}
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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();
}
Expand Down
2 changes: 1 addition & 1 deletion tests/StreamFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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"'
);
Expand Down
24 changes: 12 additions & 12 deletions tests/StreamTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand All @@ -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();
}
Expand Down Expand Up @@ -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();
}
Expand All @@ -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();
}
Expand All @@ -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);
}
Expand All @@ -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);
}
Expand Down Expand Up @@ -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');
}
Expand All @@ -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');
}
Expand Down Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -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();
}
Expand All @@ -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();
}
Expand Down
7 changes: 4 additions & 3 deletions tests/UploadedFileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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');
Expand Down
2 changes: 1 addition & 1 deletion tests/UriTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(':');
}
Expand Down

0 comments on commit 6252e91

Please sign in to comment.