Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
g105b committed Jun 19, 2019
1 parent 97c4b79 commit ee79f46
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 35 deletions.
2 changes: 1 addition & 1 deletion src/ServerInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function getServerProtocolVersion():float {
FILTER_SANITIZE_NUMBER_FLOAT,
FILTER_FLAG_ALLOW_FRACTION
);
return $version;
return (float)$version;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion test/unit/RequestFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function testCreateServerRequest() {
/** @var MockObject|ServerInfo $serverInfo */
$serverInfo = self::createMock(ServerInfo::class);
$serverInfo->method("getServerProtocolVersion")
->willReturn("123");
->willReturn(123.000);
$serverInfo->method("getRequestMethod")
->willReturn(RequestMethod::METHOD_GET);
/** @var MockObject|Input $input */
Expand Down
4 changes: 2 additions & 2 deletions test/unit/SteamTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class SteamTest extends TestCase {
protected $tmpStream;
protected $tmpFileFull;

public function setUp() {
public function setUp():void {
$this->tmpDir = implode(DIRECTORY_SEPARATOR, [
sys_get_temp_dir(),
"phpgt",
Expand All @@ -27,7 +27,7 @@ public function setUp() {
file_put_contents($this->tmpFileFull, uniqid("data-"));
}

public function tearDown() {
public function tearDown():void {
/** @var SplFileInfo[] $files */
$files = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator(
Expand Down
45 changes: 14 additions & 31 deletions test/unit/UriTest.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
<?php
namespace Gt\Http\Test;

use Gt\Http\PortOutOfBoundsException;
use Gt\Http\Uri;
use Gt\Http\UriFactory;
use Gt\Http\UriParseErrorException;
use PHPUnit\Framework\TestCase;
use TypeError;

class UriTest extends TestCase {
public function testParsesProvidedUri() {
Expand Down Expand Up @@ -83,11 +86,9 @@ public function getValidUris() {
];
}

/**
* @expectedException \Gt\Http\UriParseErrorException
* @dataProvider getInvalidUris
*/
/** @dataProvider getInvalidUris */
public function testInvalidUrisThrowException($invalidUri) {
self::expectException(UriParseErrorException::class);
new Uri($invalidUri);
}

Expand All @@ -101,59 +102,43 @@ public function getInvalidUris() {
];
}

/**
* @expectedException \Gt\Http\PortOutOfBoundsException
*/
public function testPortMustBeValid() {
self::expectException(PortOutOfBoundsException::class);
(new Uri())->withPort(100000);
}

/**
* @expectedException \Gt\Http\PortOutOfBoundsException
*/
public function testWithPortCannotBeZero() {
self::expectException(PortOutOfBoundsException::class);
(new Uri())->withPort(0);
}

/**
* @expectedException \Gt\Http\UriParseErrorException
*/
public function testParseUriPortCannotBeZero() {
self::expectException(UriParseErrorException::class);
new Uri('//example.com:0');
}

/**
* @expectedException \TypeError
*/
public function testSchemeMustHaveCorrectType() {
self::expectException(TypeError::class);
(new Uri())->withScheme([]);
}

/**
* @expectedException \TypeError
*/
public function testHostMustHaveCorrectType() {
self::expectException(TypeError::class);
(new Uri())->withHost([]);
}

/**
* @expectedException \TypeError
*/
public function testPathMustHaveCorrectType() {
self::expectException(TypeError::class);
(new Uri())->withPath([]);
}

/**
* @expectedException \TypeError
*/
public function testQueryMustHaveCorrectType() {
self::expectException(TypeError::class);
(new Uri())->withQuery([]);
}

/**
* @expectedException \TypeError
*/
public function testFragmentMustHaveCorrectType() {
self::expectException(TypeError::class);
(new Uri())->withFragment([]);
}

Expand Down Expand Up @@ -379,10 +364,8 @@ public function testStandardPortIsNullIfSchemeChanges() {
$this->assertNull($uri->getPort());
}

/**
* @expectedException \TypeError
*/
public function testPortPassedAsStringIsCastedToInt() {
self::expectException(TypeError::class);
$uri = (new Uri('//example.com'))->withPort('8080');
}

Expand Down

0 comments on commit ee79f46

Please sign in to comment.