Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added more tests and scrutnizer fixes (#107)
* Added scrutinizer fixes * Removed dead code * Added test for HTTPlug factory * Added test for UploadedFile * bump phpunit version * Adapt to Buzz:1.0 code * Added some more tests for Request * Update UploadedFile.php * Inline function instead * Inline some more functions * Improved PHPStan config * Better run PHP Nightly
- Loading branch information
Showing
12 changed files
with
201 additions
and
135 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,25 @@ | ||
parameters: | ||
level: 3 | ||
paths: | ||
- src | ||
level: 5 | ||
paths: | ||
- src | ||
|
||
ignoreErrors: | ||
- | ||
message: '#Strict comparison using === between false and true will always evaluate to false#' | ||
path: %currentWorkingDirectory%/src/UploadedFile.php | ||
|
||
- | ||
message: '#Strict comparison using === between null and string will always evaluate to false#' | ||
path: %currentWorkingDirectory%/src/Response.php | ||
|
||
- | ||
message: '#Result of && is always false.#' | ||
path: %currentWorkingDirectory%/src/Response.php | ||
|
||
- | ||
message: '#Strict comparison using !== between null and null will always evaluate to false#' | ||
path: %currentWorkingDirectory%/src/ServerRequest.php | ||
|
||
- | ||
message: '#Result of && is always false#' | ||
path: %currentWorkingDirectory%/src/ServerRequest.php |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tests\Nyholm\Psr7\Factory; | ||
|
||
use Nyholm\Psr7\Factory\HttplugFactory; | ||
use PHPUnit\Framework\TestCase; | ||
use Psr\Http\Message\StreamInterface; | ||
use Psr\Http\Message\UriInterface; | ||
|
||
class HttplugFactoryTest extends TestCase | ||
{ | ||
public function testCreateRequest() | ||
{ | ||
$factory = new HttplugFactory(); | ||
$r = $factory->createRequest('POST', 'https://nyholm.tech', ['Content-Type' => 'text/html'], 'foobar', '2.0'); | ||
|
||
$this->assertEquals('POST', $r->getMethod()); | ||
$this->assertEquals('https://nyholm.tech', $r->getUri()->__toString()); | ||
$this->assertEquals('2.0', $r->getProtocolVersion()); | ||
$this->assertEquals('foobar', $r->getBody()->__toString()); | ||
|
||
$headers = $r->getHeaders(); | ||
$this->assertCount(2, $headers); // Including HOST | ||
$this->assertArrayHasKey('Content-Type', $headers); | ||
$this->assertEquals('text/html', $headers['Content-Type'][0]); | ||
} | ||
|
||
public function testCreateResponse() | ||
{ | ||
$factory = new HttplugFactory(); | ||
$r = $factory->createResponse(217, 'Perfect', ['Content-Type' => 'text/html'], 'foobar', '2.0'); | ||
|
||
$this->assertEquals(217, $r->getStatusCode()); | ||
$this->assertEquals('Perfect', $r->getReasonPhrase()); | ||
$this->assertEquals('2.0', $r->getProtocolVersion()); | ||
$this->assertEquals('foobar', $r->getBody()->__toString()); | ||
|
||
$headers = $r->getHeaders(); | ||
$this->assertCount(1, $headers); | ||
$this->assertArrayHasKey('Content-Type', $headers); | ||
$this->assertEquals('text/html', $headers['Content-Type'][0]); | ||
} | ||
|
||
public function testCreateStream() | ||
{ | ||
$factory = new HttplugFactory(); | ||
$stream = $factory->createStream('foobar'); | ||
|
||
$this->assertInstanceOf(StreamInterface::class, $stream); | ||
$this->assertEquals('foobar', $stream->__toString()); | ||
} | ||
|
||
public function testCreateUri() | ||
{ | ||
$factory = new HttplugFactory(); | ||
$uri = $factory->createUri('https://nyholm.tech/foo'); | ||
|
||
$this->assertInstanceOf(UriInterface::class, $uri); | ||
$this->assertEquals('https://nyholm.tech/foo', $uri->__toString()); | ||
} | ||
} |
Oops, something went wrong.