Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
trowski committed Sep 12, 2019
1 parent 26f8467 commit 60eaeb2
Show file tree
Hide file tree
Showing 12 changed files with 224 additions and 243 deletions.
11 changes: 3 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@
"cash/lrucache": "^1"
},
"require-dev": {
"amphp/phpunit-util": "^1",
"amphp/http-client": "dev-master as 4.0",
"amphp/phpunit-util": "^1.1",
"amphp/http-client": "^4",
"amphp/log": "^1",
"amphp/php-cs-fixer-config": "dev-master",
"league/uri-components": "^1.7",
"monolog/monolog": "^1.23",
"phpunit/phpunit": "^7 | ^8",
"phpunit/phpunit": "^8 || ^7",
"infection/infection": "^0.9.2"
},
"suggest": {
Expand All @@ -67,11 +67,6 @@
"Amp\\Http\\Server\\Test\\": "test"
}
},
"config": {
"platform": {
"php": "7.1.0"
}
},
"scripts": {
"test": "@php -dzend.assertions=1 -dassert.exception=1 ./vendor/bin/phpunit",
"code-style": "@php ./vendor/bin/php-cs-fixer fix"
Expand Down
52 changes: 26 additions & 26 deletions test/Driver/Http1DriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class Http1DriverTest extends HttpDriverTest
/**
* @dataProvider provideUnparsableRequests
*/
public function testBadRequestBufferedParse(string $unparsable, int $errCode, string $errMsg, Options $options)
public function testBadRequestBufferedParse(string $unparsable, int $errCode, string $errMsg, Options $options): void
{
$written = "";
$writer = function (string $data) use (&$written): Promise {
Expand Down Expand Up @@ -60,7 +60,7 @@ public function testBadRequestBufferedParse(string $unparsable, int $errCode, st
/**
* @dataProvider provideUnparsableRequests
*/
public function testBadRequestIncrementalParse(string $unparsable, int $errCode, string $errMsg, Options $options)
public function testBadRequestIncrementalParse(string $unparsable, int $errCode, string $errMsg, Options $options): void
{
$written = "";
$writer = function (string $data) use (&$written): Promise {
Expand Down Expand Up @@ -97,7 +97,7 @@ public function testBadRequestIncrementalParse(string $unparsable, int $errCode,
/**
* @dataProvider provideParsableRequests
*/
public function testBufferedRequestParse(string $msg, array $expectations)
public function testBufferedRequestParse(string $msg, array $expectations): \Generator
{
$resultEmitter = function (Request $req) use (&$request) {
$request = $req;
Expand Down Expand Up @@ -125,7 +125,7 @@ public function testBufferedRequestParse(string $msg, array $expectations)
$this->assertInstanceOf(Request::class, $request);

/** @var \Amp\Http\Server\Request $request */
$body = Promise\wait($request->getBody()->buffer());
$body = yield $request->getBody()->buffer();

$this->assertSame($expectations["protocol"], $request->getProtocolVersion(), "protocol mismatch");
$this->assertSame($expectations["method"], $request->getMethod(), "method mismatch");
Expand All @@ -137,7 +137,7 @@ public function testBufferedRequestParse(string $msg, array $expectations)
/**
* @dataProvider provideParsableRequests
*/
public function testIncrementalRequestParse($msg, $expectations)
public function testIncrementalRequestParse(string $msg, array $expectations): \Generator
{
$resultEmitter = function (Request $req) use (&$request) {
$request = $req;
Expand Down Expand Up @@ -166,7 +166,7 @@ public function testIncrementalRequestParse($msg, $expectations)
$this->assertInstanceOf(Request::class, $request);

/** @var \Amp\Http\Server\Request $request */
$body = Promise\wait($request->getBody()->buffer());
$body = yield $request->getBody()->buffer();

$defaultPort = $request->getUri()->getScheme() === "https" ? 443 : 80;
$this->assertSame($expectations["protocol"], $request->getProtocolVersion(), "protocol mismatch");
Expand All @@ -177,7 +177,7 @@ public function testIncrementalRequestParse($msg, $expectations)
$this->assertSame(80, $request->getUri()->getPort() ?: $defaultPort);
}

public function testIdentityBodyParseEmit()
public function testIdentityBodyParseEmit(): \Generator
{
$originalBody = "12345";
$length = \strlen($originalBody);
Expand Down Expand Up @@ -218,12 +218,12 @@ public function testIdentityBodyParseEmit()
$this->assertInstanceOf(Request::class, $request);

/** @var \Amp\Http\Server\Request $request */
$body = Promise\wait($request->getBody()->buffer());
$body = yield $request->getBody()->buffer();

$this->assertSame($originalBody, $body);
}

public function testChunkedBodyParseEmit()
public function testChunkedBodyParseEmit(): \Generator
{
$msg =
"POST https://test.local:1337/post-endpoint HTTP/1.0\r\n" .
Expand Down Expand Up @@ -267,12 +267,12 @@ public function testChunkedBodyParseEmit()
$this->assertInstanceOf(Request::class, $request);

/** @var \Amp\Http\Server\Request $request */
$body = Promise\wait($request->getBody()->buffer());
$body = yield $request->getBody()->buffer();

$this->assertSame($expectedBody, $body);
}

public function provideParsableRequests()
public function provideParsableRequests(): array
{
$return = [];

Expand Down Expand Up @@ -473,7 +473,7 @@ public function provideParsableRequests()
return $return;
}

public function provideUnparsableRequests()
public function provideUnparsableRequests(): array
{
$return = [];

Expand Down Expand Up @@ -606,7 +606,7 @@ public function provideUnparsableRequests()
/**
* @dataProvider provideUpgradeBodySizeData
*/
public function testUpgradeBodySizeContentLength($data, $payload)
public function testUpgradeBodySizeContentLength(string $data, string $payload): \Generator
{
$resultEmitter = function (Request $req) use (&$request) {
$body = $req->getBody();
Expand Down Expand Up @@ -635,7 +635,7 @@ public function testUpgradeBodySizeContentLength($data, $payload)
$this->assertInstanceOf(Request::class, $request);

/** @var \Amp\Http\Server\Request $request */
$body = Promise\wait($request->getBody()->buffer());
$body = yield $request->getBody()->buffer();

$this->assertSame($payload, $body);
}
Expand All @@ -655,7 +655,7 @@ public function provideUpgradeBodySizeData()
return $return;
}

public function testPipelinedRequests()
public function testPipelinedRequests(): void
{
list($payloads, $results) = \array_map(null, ...$this->provideUpgradeBodySizeData());

Expand Down Expand Up @@ -751,7 +751,7 @@ function () {
$this->assertSame(3, $responses);
}

public function verifyWrite(string $input, int $status, array $headers, string $data)
public function verifyWrite(string $input, int $status, array $headers, string $data): void
{
$actualBody = "";
$parser = new Http1Parser(new ClientRequest("/"), static function ($chunk) use (&$actualBody) {
Expand All @@ -768,7 +768,7 @@ public function verifyWrite(string $input, int $status, array $headers, string $
$this->assertEquals($data, $actualBody);
}

public function testWrite()
public function testWrite(): void
{
$headers = ["test" => ["successful"]];
$status = 200;
Expand Down Expand Up @@ -817,7 +817,7 @@ function (string $data, bool $close = false) use (&$buffer, &$fin) {
}

/** @dataProvider provideWriteResponses */
public function testResponseWrite(Request $request, Response $response, string $expectedBuffer, bool $expectedClosed)
public function testResponseWrite(Request $request, Response $response, string $expectedBuffer, bool $expectedClosed): \Generator
{
$driver = new Http1Driver(
(new Options)->withConnectionTimeout(60),
Expand All @@ -843,13 +843,13 @@ function (string $data, bool $close = false) use (&$buffer, &$closed) {
}
);

Promise\wait($driver->write($request, $response));
yield $driver->write($request, $response);

$this->assertSame($buffer, $expectedBuffer);
$this->assertSame($closed, $expectedClosed);
}

public function provideWriteResponses()
public function provideWriteResponses(): array
{
return [
[
Expand All @@ -861,7 +861,7 @@ public function provideWriteResponses()
[
new Request($this->createClientMock(), "GET", Uri\Http::createFromString("/")),
new Response(Status::OK, [], new InMemoryStream, new Trailers(new Success(['test' => 'value']), ['test'])),
"HTTP/1.1 200 OK\r\nconnection: keep-alive\r\nkeep-alive: timeout=60\r\nTrailers: test\r\ndate: \r\ntransfer-encoding: chunked\r\n\r\n0\r\ntest: value\r\n\r\n",
"HTTP/1.1 200 OK\r\nconnection: keep-alive\r\nkeep-alive: timeout=60\r\ndate: \r\ntrailer: test\r\ntransfer-encoding: chunked\r\n\r\n0\r\ntest: value\r\n\r\n",
false,
],
[
Expand All @@ -879,7 +879,7 @@ public function provideWriteResponses()
];
}

public function testWriteAbortAfterHeaders()
public function testWriteAbortAfterHeaders(): void
{
$driver = new Http1Driver(
(new Options)->withStreamThreshold(1), // Set stream threshold to 1 to force immediate writes to client.
Expand Down Expand Up @@ -918,7 +918,7 @@ function (string $data, bool $close = false) use (&$invoked) {
$this->assertTrue($invoked);
}

public function testHttp2Upgrade()
public function testHttp2Upgrade(): void
{
$settings = \strtr(\base64_encode(\pack("nN", 1, 1)), "+/", "-_");
$payload = "GET /path HTTP/1.1\r\n" .
Expand Down Expand Up @@ -969,7 +969,7 @@ function (string $data) use (&$expected) {
$parser->send($payload);
}

public function testNativeHttp2()
public function testNativeHttp2(): void
{
$options = (new Options)->withHttp2Upgrade();

Expand Down Expand Up @@ -1005,7 +1005,7 @@ function (string $data) use ($options) {
$parser->send("PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n");
}

public function testExpect100Continue()
public function testExpect100Continue(): void
{
$received = "";

Expand Down Expand Up @@ -1044,7 +1044,7 @@ function (string $data) use (&$received) {
$this->assertSame("HTTP/1.1 100 Continue\r\n\r\n", $received);
}

public function testTrailerHeaders()
public function testTrailerHeaders(): \Generator
{
$driver = new Http1Driver(
new Options,
Expand Down
14 changes: 7 additions & 7 deletions test/Driver/Http2DriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public static function packHeader(array $headers, bool $continue = false, int $s
/**
* @dataProvider provideSimpleCases
*/
public function testSimpleCases(string $msg, array $expectations)
public function testSimpleCases(string $msg, array $expectations): \Generator
{
$msg = Http2Driver::PREFACE . $msg;

Expand Down Expand Up @@ -258,7 +258,7 @@ public function getPendingRequestCount(): int
return [$driver, $parser];
}

public function testWrite()
public function testWrite(): void
{
$buffer = "";
$options = new Options;
Expand Down Expand Up @@ -320,7 +320,7 @@ function (string $data, bool $close = false) use (&$buffer) {
$this->assertEquals($data, $buffer);
}

public function testWriterAbortAfterHeaders()
public function testWriterAbortAfterHeaders(): void
{
$buffer = "";
$options = new Options;
Expand Down Expand Up @@ -371,7 +371,7 @@ function (string $data, bool $close = false) use (&$buffer) {
$this->assertEquals($data, $buffer);
}

public function testPingPong()
public function testPingPong(): void
{
list($driver, $parser) = $this->setupDriver();

Expand All @@ -383,7 +383,7 @@ public function testPingPong()
$this->assertEquals([["blahbleh", Http2Driver::PING, Http2Driver::ACK, 0]], $driver->frames);
}

public function testFlowControl()
public function testFlowControl(): \Generator
{
list($driver, $parser) = $this->setupDriver(function (Request $read) use (&$request) {
$request = $read;
Expand Down Expand Up @@ -544,7 +544,7 @@ public function testFlowControl()
$this->assertEquals(3, $stream);
}

public function testClosingStreamYieldsFalseFromWriter()
public function testClosingStreamYieldsFalseFromWriter(): \Generator
{
$driver = new Http2Driver(new Options, $this->createMock(TimeReference::class), new NullLogger);

Expand Down Expand Up @@ -589,7 +589,7 @@ function () {
yield $writer; // Will throw if the writer is not complete.
}

public function testPush()
public function testPush(): \Generator
{
$driver = new Http2Driver(new Options, $this->createMock(TimeReference::class), new NullLogger);

Expand Down
Loading

0 comments on commit 60eaeb2

Please sign in to comment.