Skip to content

Commit

Permalink
Avoid using deprecated functions from clue/reactphp-block
Browse files Browse the repository at this point in the history
  • Loading branch information
clue committed Aug 9, 2022
1 parent 90413fb commit a2ae0f1
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 32 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@
"clue/http-proxy-react": "^1.7",
"clue/reactphp-ssh-proxy": "^1.3",
"clue/socks-react": "^1.3",
"phpunit/phpunit": "^9.3 || ^5.7 || ^4.8.35"
"phpunit/phpunit": "^9.3 || ^5.7 || ^4.8.35",
"react/promise-timer": "^1.9"
},
"autoload": {
"psr-4": { "React\\Http\\": "src" }
Expand Down
10 changes: 5 additions & 5 deletions tests/Client/FunctionalIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function testRequestToLocalhostEmitsSingleRemoteConnection()
$promise = Stream\first($request, 'close');
$request->end();

Block\await($promise, null, self::TIMEOUT_LOCAL);
Block\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT_LOCAL));
}

public function testRequestLegacyHttpServerWithOnlyLineFeedReturnsSuccessfulResponse()
Expand All @@ -73,7 +73,7 @@ public function testRequestLegacyHttpServerWithOnlyLineFeedReturnsSuccessfulResp
$promise = Stream\first($request, 'close');
$request->end();

Block\await($promise, null, self::TIMEOUT_LOCAL);
Block\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT_LOCAL));
}

/** @group internet */
Expand All @@ -94,7 +94,7 @@ public function testSuccessfulResponseEmitsEnd()
$promise = Stream\first($request, 'close');
$request->end();

Block\await($promise, null, self::TIMEOUT_REMOTE);
Block\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT_REMOTE));
}

/** @group internet */
Expand Down Expand Up @@ -122,7 +122,7 @@ public function testPostDataReturnsData()

$request->end($data);

$buffer = Block\await($deferred->promise(), null, self::TIMEOUT_REMOTE);
$buffer = Block\await(\React\Promise\Timer\timeout($deferred->promise(), self::TIMEOUT_REMOTE));

$this->assertNotEquals('', $buffer);

Expand Down Expand Up @@ -154,7 +154,7 @@ public function testPostJsonReturnsData()

$request->end($data);

$buffer = Block\await($deferred->promise(), null, self::TIMEOUT_REMOTE);
$buffer = Block\await(\React\Promise\Timer\timeout($deferred->promise(), self::TIMEOUT_REMOTE));

$this->assertNotEquals('', $buffer);

Expand Down
2 changes: 1 addition & 1 deletion tests/FunctionalBrowserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ public function testReceiveStreamAndExplicitlyCloseConnectionEvenWhenServerKeeps
$response = Block\await($this->browser->get($this->base . 'get', array()));
$this->assertEquals('hello', (string)$response->getBody());

$ret = Block\await($closed->promise(), null, 0.1);
$ret = Block\await(\React\Promise\Timer\timeout($closed->promise(), 0.1));
$this->assertTrue($ret);

$socket->close();
Expand Down
46 changes: 23 additions & 23 deletions tests/FunctionalHttpServerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function testPlainHttpOnRandomPort()
return Stream\buffer($conn);
});

$response = Block\await($result, null, 1.0);
$response = Block\await(\React\Promise\Timer\timeout($result, 1.0));

$this->assertContainsString("HTTP/1.0 200 OK", $response);
$this->assertContainsString('http://' . noScheme($socket->getAddress()) . '/', $response);
Expand All @@ -64,7 +64,7 @@ function () {
return Stream\buffer($conn);
});

$response = Block\await($result, null, 1.0);
$response = Block\await(\React\Promise\Timer\timeout($result, 1.0));

$this->assertContainsString("HTTP/1.0 404 Not Found", $response);

Expand All @@ -88,7 +88,7 @@ public function testPlainHttpOnRandomPortWithoutHostHeaderUsesSocketUri()
return Stream\buffer($conn);
});

$response = Block\await($result, null, 1.0);
$response = Block\await(\React\Promise\Timer\timeout($result, 1.0));

$this->assertContainsString("HTTP/1.0 200 OK", $response);
$this->assertContainsString('http://' . noScheme($socket->getAddress()) . '/', $response);
Expand All @@ -113,7 +113,7 @@ public function testPlainHttpOnRandomPortWithOtherHostHeaderTakesPrecedence()
return Stream\buffer($conn);
});

$response = Block\await($result, null, 1.0);
$response = Block\await(\React\Promise\Timer\timeout($result, 1.0));

$this->assertContainsString("HTTP/1.0 200 OK", $response);
$this->assertContainsString('http://localhost:1000/', $response);
Expand Down Expand Up @@ -146,7 +146,7 @@ public function testSecureHttpsOnRandomPort()
return Stream\buffer($conn);
});

$response = Block\await($result, null, 1.0);
$response = Block\await(\React\Promise\Timer\timeout($result, 1.0));

$this->assertContainsString("HTTP/1.0 200 OK", $response);
$this->assertContainsString('https://' . noScheme($socket->getAddress()) . '/', $response);
Expand Down Expand Up @@ -183,7 +183,7 @@ public function testSecureHttpsReturnsData()
return Stream\buffer($conn);
});

$response = Block\await($result, null, 1.0);
$response = Block\await(\React\Promise\Timer\timeout($result, 1.0));

$this->assertContainsString("HTTP/1.0 200 OK", $response);
$this->assertContainsString("\r\nContent-Length: 33000\r\n", $response);
Expand Down Expand Up @@ -217,7 +217,7 @@ public function testSecureHttpsOnRandomPortWithoutHostHeaderUsesSocketUri()
return Stream\buffer($conn);
});

$response = Block\await($result, null, 1.0);
$response = Block\await(\React\Promise\Timer\timeout($result, 1.0));

$this->assertContainsString("HTTP/1.0 200 OK", $response);
$this->assertContainsString('https://' . noScheme($socket->getAddress()) . '/', $response);
Expand Down Expand Up @@ -246,7 +246,7 @@ public function testPlainHttpOnStandardPortReturnsUriWithNoPort()
return Stream\buffer($conn);
});

$response = Block\await($result, null, 1.0);
$response = Block\await(\React\Promise\Timer\timeout($result, 1.0));

$this->assertContainsString("HTTP/1.0 200 OK", $response);
$this->assertContainsString('http://127.0.0.1/', $response);
Expand Down Expand Up @@ -275,7 +275,7 @@ public function testPlainHttpOnStandardPortWithoutHostHeaderReturnsUriWithNoPort
return Stream\buffer($conn);
});

$response = Block\await($result, null, 1.0);
$response = Block\await(\React\Promise\Timer\timeout($result, 1.0));

$this->assertContainsString("HTTP/1.0 200 OK", $response);
$this->assertContainsString('http://127.0.0.1/', $response);
Expand Down Expand Up @@ -313,7 +313,7 @@ public function testSecureHttpsOnStandardPortReturnsUriWithNoPort()
return Stream\buffer($conn);
});

$response = Block\await($result, null, 1.0);
$response = Block\await(\React\Promise\Timer\timeout($result, 1.0));

$this->assertContainsString("HTTP/1.0 200 OK", $response);
$this->assertContainsString('https://127.0.0.1/', $response);
Expand Down Expand Up @@ -351,7 +351,7 @@ public function testSecureHttpsOnStandardPortWithoutHostHeaderUsesSocketUri()
return Stream\buffer($conn);
});

$response = Block\await($result, null, 1.0);
$response = Block\await(\React\Promise\Timer\timeout($result, 1.0));

$this->assertContainsString("HTTP/1.0 200 OK", $response);
$this->assertContainsString('https://127.0.0.1/', $response);
Expand Down Expand Up @@ -380,7 +380,7 @@ public function testPlainHttpOnHttpsStandardPortReturnsUriWithPort()
return Stream\buffer($conn);
});

$response = Block\await($result, null, 1.0);
$response = Block\await(\React\Promise\Timer\timeout($result, 1.0));

$this->assertContainsString("HTTP/1.0 200 OK", $response);
$this->assertContainsString('http://127.0.0.1:443/', $response);
Expand Down Expand Up @@ -418,7 +418,7 @@ public function testSecureHttpsOnHttpStandardPortReturnsUriWithPort()
return Stream\buffer($conn);
});

$response = Block\await($result, null, 1.0);
$response = Block\await(\React\Promise\Timer\timeout($result, 1.0));

$this->assertContainsString("HTTP/1.0 200 OK", $response);
$this->assertContainsString('https://127.0.0.1:80/', $response);
Expand Down Expand Up @@ -446,7 +446,7 @@ public function testClosedStreamFromRequestHandlerWillSendEmptyBody()
return Stream\buffer($conn);
});

$response = Block\await($result, null, 1.0);
$response = Block\await(\React\Promise\Timer\timeout($result, 1.0));

$this->assertStringStartsWith("HTTP/1.0 200 OK", $response);
$this->assertStringEndsWith("\r\n\r\n", $response);
Expand Down Expand Up @@ -477,7 +477,7 @@ function (RequestInterface $request) use ($once) {
});
});

Block\sleep(0.1);
\Clue\React\Block\await(\React\Promise\Timer\sleep(0.1));

$socket->close();
}
Expand Down Expand Up @@ -507,7 +507,7 @@ function (RequestInterface $request) use ($stream) {
});

// stream will be closed within 0.1s
$ret = Block\await(Stream\first($stream, 'close'), null, 0.1);
$ret = Block\await(\React\Promise\Timer\timeout(Stream\first($stream, 'close'), 0.1));

$socket->close();

Expand Down Expand Up @@ -536,7 +536,7 @@ public function testStreamFromRequestHandlerWillBeClosedIfConnectionCloses()
});

// await response stream to be closed
$ret = Block\await(Stream\first($stream, 'close'), null, 1.0);
$ret = Block\await(\React\Promise\Timer\timeout(Stream\first($stream, 'close'), 1.0));

$socket->close();

Expand Down Expand Up @@ -571,7 +571,7 @@ public function testUpgradeWithThroughStreamReturnsDataAsGiven()
return Stream\buffer($conn);
});

$response = Block\await($result, null, 1.0);
$response = Block\await(\React\Promise\Timer\timeout($result, 1.0));

$this->assertStringStartsWith("HTTP/1.1 101 Switching Protocols\r\n", $response);
$this->assertStringEndsWith("\r\n\r\nhelloworld", $response);
Expand Down Expand Up @@ -608,7 +608,7 @@ public function testUpgradeWithRequestBodyAndThroughStreamReturnsDataAsGiven()
return Stream\buffer($conn);
});

$response = Block\await($result, null, 1.0);
$response = Block\await(\React\Promise\Timer\timeout($result, 1.0));

$this->assertStringStartsWith("HTTP/1.1 101 Switching Protocols\r\n", $response);
$this->assertStringEndsWith("\r\n\r\nhelloworld", $response);
Expand Down Expand Up @@ -644,7 +644,7 @@ public function testConnectWithThroughStreamReturnsDataAsGiven()
return Stream\buffer($conn);
});

$response = Block\await($result, null, 1.0);
$response = Block\await(\React\Promise\Timer\timeout($result, 1.0));

$this->assertStringStartsWith("HTTP/1.1 200 OK\r\n", $response);
$this->assertStringEndsWith("\r\n\r\nhelloworld", $response);
Expand Down Expand Up @@ -684,7 +684,7 @@ public function testConnectWithThroughStreamReturnedFromPromiseReturnsDataAsGive
return Stream\buffer($conn);
});

$response = Block\await($result, null, 1.0);
$response = Block\await(\React\Promise\Timer\timeout($result, 1.0));

$this->assertStringStartsWith("HTTP/1.1 200 OK\r\n", $response);
$this->assertStringEndsWith("\r\n\r\nhelloworld", $response);
Expand Down Expand Up @@ -717,7 +717,7 @@ public function testConnectWithClosedThroughStreamReturnsNoData()
return Stream\buffer($conn);
});

$response = Block\await($result, null, 1.0);
$response = Block\await(\React\Promise\Timer\timeout($result, 1.0));

$this->assertStringStartsWith("HTTP/1.1 200 OK\r\n", $response);
$this->assertStringEndsWith("\r\n\r\n", $response);
Expand Down Expand Up @@ -760,7 +760,7 @@ function (ServerRequestInterface $request) {
});
}

$responses = Block\await(Promise\all($result), null, 1.0);
$responses = Block\await(\React\Promise\Timer\timeout(Promise\all($result), 1.0));

foreach ($responses as $response) {
$this->assertContainsString("HTTP/1.0 200 OK", $response, $response);
Expand Down
4 changes: 2 additions & 2 deletions tests/Io/TransactionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ public function testReceivingStreamingBodyWithSizeExceedingMaximumResponseBuffer
$promise = $transaction->send($request);

$this->setExpectedException('OverflowException');
Block\await($promise, null, 0.001);
Block\await(\React\Promise\Timer\timeout($promise, 0.001));
}

public function testCancelBufferingResponseWillCloseStreamAndReject()
Expand All @@ -445,7 +445,7 @@ public function testCancelBufferingResponseWillCloseStreamAndReject()
$promise->cancel();

$this->setExpectedException('RuntimeException');
Block\await($promise, null, 0.001);
Block\await(\React\Promise\Timer\timeout($promise, 0.001));
}

public function testReceivingStreamingBodyWillResolveWithStreamingResponseIfStreamingIsEnabled()
Expand Down

0 comments on commit a2ae0f1

Please sign in to comment.