Skip to content

Commit

Permalink
improve code coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
Art4 committed Aug 29, 2023
1 parent a629fae commit 57dbee7
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 18 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/.code-coverage
/.php-cs-fixer.cache
/.phpunit.cache/
/.phpunit.result.cache
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
}
},
"scripts": {
"coverage": "phpunit --coverage-html=.code-coverage",
"phpstan": "phpstan analyze --memory-limit 512M --configuration .phpstan.neon",
"phpunit": "phpunit"
},
Expand Down
8 changes: 4 additions & 4 deletions src/Psr/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ public static function fromResponse(RequestsResponse $response)

$headers = [];

/**
* @var string $name
* @var string[] $value
*/
foreach ($response->headers->getAll() as $name => $value) {
if (!is_array($value)) {
$value = [$value];
}

$headers[$name] = $value;
}

Expand Down
19 changes: 9 additions & 10 deletions src/Psr/Uri.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,21 +162,20 @@ public function getPort(): ?int
$port = $this->iri->port;
$scheme = $this->getScheme();

try {
$portFromScheme = Port::get($scheme);
} catch (RequestsException $th) {
$portFromScheme = null;
}

if ($port === null) {
try {
return Port::get($scheme);
} catch (RequestsException $th) {
return null;
}
return $portFromScheme;
}

$port = intval($port);

try {
if ($port === Port::get($scheme)) {
return null;
}
} catch (RequestsException $th) {
if ($port === $portFromScheme) {
return null;
}

return $port;
Expand Down
1 change: 1 addition & 0 deletions tests/Psr/Response/FromResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ final class FromResponseTest extends TestCase
* Tests receiving a Response instance when using fromResponse().
*
* @covers \Art4\Requests\Psr\Response::fromResponse
* @covers \Art4\Requests\Psr\Response::__construct
*
* @return void
*/
Expand Down
4 changes: 2 additions & 2 deletions tests/Psr/Response/GetBodyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ final class GetBodyTest extends TestCase
/**
* Tests receiving the stream when using getBody().
*
* @covers \Art4\Requests\Psr\Request::getBody
* @covers \Art4\Requests\Psr\Response::getBody
*
* @return void
*/
Expand All @@ -30,7 +30,7 @@ public function testGetBodyReturnsStreamInterface()
/**
* Tests receiving the stream when using getBody().
*
* @covers \Art4\Requests\Psr\Request::getBody
* @covers \Art4\Requests\Psr\Response::getBody
*
* @return void
*/
Expand Down
2 changes: 2 additions & 0 deletions tests/Psr/Response/GetHeadersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ final class GetHeadersTest extends TestCase
/**
* Tests receiving the headers when using getHeaders().
*
* @covers \Art4\Requests\Psr\Response::fromResponse
* @covers \Art4\Requests\Psr\Response::getHeaders
*
* @return void
Expand All @@ -27,6 +28,7 @@ public function _testGetHeadersReturnsEmptyArray()
/**
* Tests receiving the headers when using getHeaders().
*
* @covers \Art4\Requests\Psr\Response::fromResponse
* @covers \Art4\Requests\Psr\Response::getHeaders
*
* @return void
Expand Down
5 changes: 3 additions & 2 deletions tests/Psr/Response/GetProtocolVersionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ final class GetProtocolVersionTest extends TestCase
/**
* Tests receiving the protocol version when using getProtocolVersion().
*
* @covers \Art4\Requests\Psr\Request::getProtocolVersion
* @covers \Art4\Requests\Psr\Response::fromResponse
* @covers \Art4\Requests\Psr\Response::getProtocolVersion
*
* @return void
*/
Expand All @@ -30,7 +31,7 @@ public function testGetProtocolVersionWithFloatReturnsString()
/**
* Tests receiving the protocol version when using getProtocolVersion().
*
* @covers \Art4\Requests\Psr\Request::getProtocolVersion
* @covers \Art4\Requests\Psr\Response::getProtocolVersion
*
* @return void
*/
Expand Down
1 change: 1 addition & 0 deletions tests/Psr/Response/WithStatusTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public function dataInvalidTypeNotString()
* @dataProvider dataWithStatus
*
* @covers \Art4\Requests\Psr\Response::withStatus
* @covers \Art4\Requests\Psr\Response::getReasonPhrase
*
* @return void
*/
Expand Down

0 comments on commit 57dbee7

Please sign in to comment.