Skip to content

Commit

Permalink
increase code coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
Art4 committed Aug 29, 2023
1 parent 57dbee7 commit b1feab2
Show file tree
Hide file tree
Showing 11 changed files with 70 additions and 48 deletions.
4 changes: 0 additions & 4 deletions src/Psr/StringBasedStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -235,10 +235,6 @@ public function getContents(): string
*/
public function getMetadata(?string $key = null)
{
if (func_num_args() > 0 && !is_string($key)) {
throw InvalidArgument::create(1, '$key', 'string', gettype($key));
}

if (is_string($key)) {
return null;
}
Expand Down
2 changes: 2 additions & 0 deletions tests/Psr/Request/WithAddedHeaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ public function testWithAddedHeaderWithoutValueAsStringInArrayThrowsInvalidArgum
* Tests changing the header when using withAddedHeader().
*
* @covers \Art4\Requests\Psr\Request::withAddedHeader
* @covers \Art4\Requests\Psr\Request::updateHeader
*
* @return void
*/
Expand All @@ -125,6 +126,7 @@ public function testWithAddedHeaderChangesTheHeaders()
* Tests changing the header when using withAddedHeader().
*
* @covers \Art4\Requests\Psr\Request::withAddedHeader
* @covers \Art4\Requests\Psr\Request::updateHeader
*
* @return void
*/
Expand Down
3 changes: 3 additions & 0 deletions tests/Psr/Request/WithHeaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ final class WithHeaderTest extends TestCase
* Tests changing the header when using withHeader().
*
* @covers \Art4\Requests\Psr\Request::withHeader
* @covers \Art4\Requests\Psr\Request::updateHeader
*
* @return void
*/
Expand Down Expand Up @@ -107,6 +108,7 @@ public function testWithHeaderWithoutValueAsStringInArrayThrowsInvalidArgumentEx
* Tests changing the header when using withHeader().
*
* @covers \Art4\Requests\Psr\Request::withHeader
* @covers \Art4\Requests\Psr\Request::updateHeader
*
* @return void
*/
Expand All @@ -125,6 +127,7 @@ public function testWithHeaderChangesTheHeaders()
* Tests changing the header when using withHeader().
*
* @covers \Art4\Requests\Psr\Request::withHeader
* @covers \Art4\Requests\Psr\Request::updateHeader
*
* @return void
*/
Expand Down
12 changes: 1 addition & 11 deletions tests/Psr/Request/WithMethodAndUriTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use Art4\Requests\Psr\Request;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\UriInterface;
use WpOrg\Requests\Exception\InvalidArgument;
use Yoast\PHPUnitPolyfills\TestCases\TestCase;
use Art4\Requests\Tests\TypeProviderHelper;

Expand All @@ -17,6 +16,7 @@ final class WithMethodAndUriTest extends TestCase
* Tests receiving a Request instance when using withMethodAndUri().
*
* @covers \Art4\Requests\Psr\Request::withMethodAndUri
* @covers \Art4\Requests\Psr\Request::__construct
*
* @return void
*/
Expand All @@ -30,16 +30,6 @@ public function testWithMethodAndUriReturnsRequest()
);
}

/**
* Data Provider.
*
* @return array<string, mixed>
*/
public function dataInvalidTypeNotString()
{
return TypeProviderHelper::getAllExcept(TypeProviderHelper::GROUP_STRING);
}

/**
* Tests receiving a Request instance when using withMethodAndUri().
*
Expand Down
11 changes: 1 addition & 10 deletions tests/Psr/Request/WithRequestTargetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,22 +41,13 @@ public function testWithRequestTargetReturnsNewInstance()
$this->assertNotSame($request, $request->withRequestTarget('/'));
}

/**
* Data Provider.
*
* @return array<string, mixed>
*/
public function dataInvalidTypeNotString()
{
return TypeProviderHelper::getAllExcept(TypeProviderHelper::GROUP_STRING);
}

/**
* Tests changing the request-target when using withRequestTarget().
*
* @dataProvider dataValidRequestTarget
*
* @covers \Art4\Requests\Psr\Request::withRequestTarget
* @covers \Art4\Requests\Psr\Request::getRequestTarget
*
* @param string $input
* @param string $expected
Expand Down
10 changes: 10 additions & 0 deletions tests/Psr/Request/WithUriTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ public function testWithUriReturnsNewInstance()
* Tests changing the uri when using withUri().
*
* @covers \Art4\Requests\Psr\Request::withUri
* @covers \Art4\Requests\Psr\Request::setUri
* @covers \Art4\Requests\Psr\Request::updateHeader
*
* @return void
*/
Expand All @@ -66,6 +68,8 @@ public function testWithUriChangesTheUri()
* Tests changing the uri when using withUri().
*
* @covers \Art4\Requests\Psr\Request::withUri
* @covers \Art4\Requests\Psr\Request::setUri
* @covers \Art4\Requests\Psr\Request::updateHeader
*
* @return void
*/
Expand All @@ -88,6 +92,8 @@ public function testWithUriChangesTheHostHeader()
* Tests changing the uri when using withUri().
*
* @covers \Art4\Requests\Psr\Request::withUri
* @covers \Art4\Requests\Psr\Request::setUri
* @covers \Art4\Requests\Psr\Request::updateHeader
*
* @return void
*/
Expand All @@ -111,6 +117,8 @@ public function testWithUriChangesTheHostHeaderToFirstPlace()
* Tests changing the uri when using withUri().
*
* @covers \Art4\Requests\Psr\Request::withUri
* @covers \Art4\Requests\Psr\Request::setUri
* @covers \Art4\Requests\Psr\Request::updateHeader
*
* @return void
*/
Expand All @@ -135,6 +143,8 @@ public function testWithUriWithoutHostDoNotChangeTheHostHeader()
* @dataProvider dataPreserveHost
*
* @covers \Art4\Requests\Psr\Request::withUri
* @covers \Art4\Requests\Psr\Request::setUri
* @covers \Art4\Requests\Psr\Request::updateHeader
*
* @param array<string,string[]> $expectedHeaders
*
Expand Down
2 changes: 2 additions & 0 deletions tests/Psr/Request/WithoutHeaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public function dataInvalidTypeNotString()
* Tests removing the header when using withoutHeader().
*
* @covers \Art4\Requests\Psr\Request::withoutHeader
* @covers \Art4\Requests\Psr\Request::updateHeader
*
* @return void
*/
Expand All @@ -74,6 +75,7 @@ public function testWithoutHeaderChangesTheHeaders()
* Tests removing the header when using withoutHeader().
*
* @covers \Art4\Requests\Psr\Request::withoutHeader
* @covers \Art4\Requests\Psr\Request::updateHeader
*
* @return void
*/
Expand Down
12 changes: 1 addition & 11 deletions tests/Psr/StringBasedStream/CreateFromStringTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace Art4\Requests\Tests\Psr\StringBasedStream;

use Psr\Http\Message\StreamInterface;
use WpOrg\Requests\Exception\InvalidArgument;
use Art4\Requests\Psr\StringBasedStream;
use Yoast\PHPUnitPolyfills\TestCases\TestCase;
use Art4\Requests\Tests\TypeProviderHelper;
Expand All @@ -16,6 +15,7 @@ final class CreateFromStringTest extends TestCase
* Tests receiving the stream when using createFromString().
*
* @covers \Art4\Requests\Psr\StringBasedStream::createFromString
* @covers \Art4\Requests\Psr\StringBasedStream::__construct
*
* @return void
*/
Expand All @@ -26,14 +26,4 @@ public function testCreateFromStringReturnsStream()
StringBasedStream::createFromString('')
);
}

/**
* Data Provider.
*
* @return array<string, mixed>
*/
public function dataInvalidTypeNotString()
{
return TypeProviderHelper::getAllExcept(TypeProviderHelper::GROUP_STRING);
}
}
12 changes: 0 additions & 12 deletions tests/Psr/StringBasedStream/GetMetadataTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@

namespace Art4\Requests\Tests\Psr\StringBasedStream;

use InvalidArgumentException;
use Art4\Requests\Psr\StringBasedStream;
use Yoast\PHPUnitPolyfills\TestCases\TestCase;
use Art4\Requests\Tests\TypeProviderHelper;

final class GetMetadataTest extends TestCase
{
Expand Down Expand Up @@ -38,14 +36,4 @@ public function testGetMetadataWithKeyReturnsNull()

$this->assertNull($stream->getMetadata('key'));
}

/**
* Data Provider.
*
* @return array<string, mixed>
*/
public function dataInvalidTypeNotString()
{
return TypeProviderHelper::getAllExcept(TypeProviderHelper::GROUP_STRING);
}
}
25 changes: 25 additions & 0 deletions tests/Psr/StringBasedStream/GetSizeTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

declare(strict_types=1);

namespace Art4\Requests\Tests\Psr\StringBasedStream;

use Art4\Requests\Psr\StringBasedStream;
use Yoast\PHPUnitPolyfills\TestCases\TestCase;

final class GetSizeTest extends TestCase
{
/**
* Tests returns content size when using getSize() method.
*
* @covers \Art4\Requests\Psr\StringBasedStream::getSize
*
* @return void
*/
public function testGetSizeReturnsContentSize()
{
$stream = StringBasedStream::createFromString('full content');

$this->assertSame(12, $stream->getSize());
}
}
25 changes: 25 additions & 0 deletions tests/Psr/StringBasedStream/__ToStringTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

declare(strict_types=1);

namespace Art4\Requests\Tests\Psr\StringBasedStream;

use Art4\Requests\Psr\StringBasedStream;
use Yoast\PHPUnitPolyfills\TestCases\TestCase;

final class __ToStringTest extends TestCase
{
/**
* Tests returns the full content when using __toString() method.
*
* @covers \Art4\Requests\Psr\StringBasedStream::__toString
*
* @return void
*/
public function testToStringReturnsFullContent()
{
$stream = StringBasedStream::createFromString('full content');

$this->assertSame('full content', $stream->__toString());
}
}

0 comments on commit b1feab2

Please sign in to comment.