Skip to content

Commit

Permalink
Improve code quality.
Browse files Browse the repository at this point in the history
  • Loading branch information
terrylinooo committed Jun 19, 2020
1 parent f775574 commit fb282f1
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
@@ -1,6 +1,6 @@
# PSR 7, 15, 17 Implementation and Examples

[![Build Status](https://travis-ci.org/terrylinooo/psr-http.svg?branch=master)](https://travis-ci.org/terrylinooo/psr-http) [![codecov](https://img.shields.io/codecov/c/github/terrylinooo/psr-http.svg)](https://codecov.io/gh/terrylinooo/psr-http) [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/terrylinooo/psr-http/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/terrylinooo/psr-http/?branch=master) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![Build Status](https://travis-ci.org/terrylinooo/psr-http.svg?branch=master)](https://travis-ci.org/terrylinooo/psr-http) [![codecov](https://img.shields.io/codecov/c/github/terrylinooo/psr-http.svg)](https://codecov.io/gh/terrylinooo/psr-http) [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/terrylinooo/psr-http/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/terrylinooo/psr-http/?branch=master) [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](https://opensource.org/licenses/MIT)

This library is a PSR HTTP implementation with detailed examples, following up the PSR (PHP Standard Recommendation) documents by one hundred percent.

Expand Down
21 changes: 21 additions & 0 deletions tests/Psr15/RequestHandlerTest.php
Expand Up @@ -53,4 +53,25 @@ public function test_requestHandler_Condition_2()
$this->assertEquals(200, $response->getStatusCode());
$this->assertEquals('e04su3su;6', $response->getBody()->getContents());
}

public function test_requestHandler_Condition_3()
{
// Without a fallback handler...
$app = new RequestHandler();

$app->add(new ApiMiddleware());
$app->add(new StringMiddleware());

$request = ServerRequestFactory::fromGlobal();

$request = $request->withHeader('Content-Type', 'application/json')->
withHeader('key', '23492834234')->
withHeader('secret', '1a163782ee166156294d173fcf8b8e87');


$response = $app->handle($request);

$this->assertEquals(200, $response->getStatusCode());
$this->assertEquals('', $response->getBody()->getContents());
}
}
15 changes: 15 additions & 0 deletions tests/Psr17/StreamFactoryTest.php
Expand Up @@ -13,6 +13,7 @@
use PHPUnit\Framework\TestCase;
use Psr\Http\Message\StreamInterface;
use Shieldon\Psr17\StreamFactory;
use ReflectionObject;
use InvalidArgumentException;
use RuntimeException;

Expand Down Expand Up @@ -80,4 +81,18 @@ public function test_Exception_CreateStreamFromFile_UnableToOpen()
// => Invalid file opening mode "b"
$stream = $streamFactory->createStreamFromFile($sourceFile);
}

public function test_Exception_assertResource()
{
$this->expectException(RuntimeException::class);

$streamFactory = new StreamFactory();
$reflection = new ReflectionObject($streamFactory);
$assertParsedBody = $reflection->getMethod('assertResource');
$assertParsedBody->setAccessible(true);

// Exception:
// => Unable to open "php://temp" resource.
$assertParsedBody->invokeArgs($streamFactory, ['test string']);
}
}

0 comments on commit fb282f1

Please sign in to comment.