Skip to content

Commit

Permalink
Update to require PHP 7.1+
Browse files Browse the repository at this point in the history
  • Loading branch information
clue committed May 27, 2024
1 parent da8ee09 commit acd2e14
Show file tree
Hide file tree
Showing 22 changed files with 23 additions and 181 deletions.
21 changes: 0 additions & 21 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,6 @@ jobs:
- 7.3
- 7.2
- 7.1
- 7.0
- 5.6
- 5.5
- 5.4
- 5.3
steps:
- uses: actions/checkout@v4
- uses: shivammathur/setup-php@v2
Expand All @@ -36,19 +31,3 @@ jobs:
if: ${{ matrix.php >= 7.3 }}
- run: vendor/bin/phpunit --coverage-text -c phpunit.xml.legacy
if: ${{ matrix.php < 7.3 }}

PHPUnit-hhvm:
name: PHPUnit (HHVM)
runs-on: ubuntu-22.04
continue-on-error: true
steps:
- uses: actions/checkout@v4
- run: cp "$(which composer)" composer.phar && ./composer.phar self-update --2.2 # downgrade Composer for HHVM
- name: Run hhvm composer.phar install
uses: docker://hhvm/hhvm:3.30-lts-latest
with:
args: hhvm composer.phar install
- name: Run hhvm vendor/bin/phpunit
uses: docker://hhvm/hhvm:3.30-lts-latest
with:
args: hhvm vendor/bin/phpunit
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2990,8 +2990,7 @@ composer require react/http:^3@dev
See also the [CHANGELOG](CHANGELOG.md) for details about version upgrades.

This project aims to run on any platform and thus does not require any PHP
extensions and supports running on legacy PHP 5.3 through current PHP 8+ and
HHVM.
extensions and supports running on PHP 7.1 through current PHP 8+.
It's *highly recommended to use the latest supported PHP version* for this project.

## Tests
Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
}
],
"require": {
"php": ">=5.3.0",
"php": ">=7.1",
"evenement/evenement": "^3.0 || ^2.0 || ^1.0",
"fig/http-message-util": "^1.1",
"psr/http-message": "^1.0",
Expand All @@ -39,8 +39,8 @@
"clue/http-proxy-react": "^1.8",
"clue/reactphp-ssh-proxy": "^1.4",
"clue/socks-react": "^1.4",
"phpunit/phpunit": "^9.6 || ^5.7 || ^4.8.36",
"react/async": "^4 || ^3 || ^2",
"phpunit/phpunit": "^9.6 || ^5.7",
"react/async": "^4 || ^3",
"react/promise-stream": "^1.4",
"react/promise-timer": "^1.9"
},
Expand Down
2 changes: 1 addition & 1 deletion phpunit.xml.legacy
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<!-- PHPUnit configuration file with old format for legacy PHPUnit -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/4.8/phpunit.xsd"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/5.7/phpunit.xsd"
bootstrap="vendor/autoload.php"
colors="true">
<testsuites>
Expand Down
3 changes: 1 addition & 2 deletions src/Io/ClientRequestStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@ private function writeHead()
}
}

/** @var array $m legacy PHP 5.3 only */
if (!\preg_match('#^\S+ \S+ HTTP/1\.[01]\r\n#m', $headers) || \substr_count($headers, "\n") !== ($expected + 1) || (\PHP_VERSION_ID >= 50400 ? \preg_match_all(AbstractMessage::REGEX_HEADERS, $headers) : \preg_match_all(AbstractMessage::REGEX_HEADERS, $headers, $m)) !== $expected) {
if (!\preg_match('#^\S+ \S+ HTTP/1\.[01]\r\n#m', $headers) || \substr_count($headers, "\n") !== ($expected + 1) || \preg_match_all(AbstractMessage::REGEX_HEADERS, $headers) !== $expected) {
$this->closeError(new \InvalidArgumentException('Unable to send request with invalid request headers'));
return;
}
Expand Down
14 changes: 4 additions & 10 deletions src/Io/MultipartParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ final class MultipartParser
/**
* ini setting "max_input_vars"
*
* Does not exist in PHP < 5.3.9 or HHVM, so assume PHP's default 1000 here.
* Assume PHP' default of 1000 here.
*
* @var int
* @link http://php.net/manual/en/info.configuration.php#ini.max-input-vars
Expand All @@ -46,7 +46,7 @@ final class MultipartParser
/**
* ini setting "max_input_nesting_level"
*
* Does not exist in HHVM, but assumes hard coded to 64 (PHP's default).
* Assume PHP's default of 64 here.
*
* @var int
* @link http://php.net/manual/en/info.configuration.php#ini.max-input-nesting-level
Expand Down Expand Up @@ -81,14 +81,8 @@ final class MultipartParser
*/
public function __construct($uploadMaxFilesize = null, $maxFileUploads = null)
{
$var = \ini_get('max_input_vars');
if ($var !== false) {
$this->maxInputVars = (int)$var;
}
$var = \ini_get('max_input_nesting_level');
if ($var !== false) {
$this->maxInputNestingLevel = (int)$var;
}
$this->maxInputVars = (int) \ini_get('max_input_vars');
$this->maxInputNestingLevel = (int) \ini_get('max_input_nesting_level');

if ($uploadMaxFilesize === null) {
$uploadMaxFilesize = \ini_get('upload_max_filesize');
Expand Down
3 changes: 1 addition & 2 deletions src/Io/StreamingServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -346,8 +346,7 @@ public function handleResponse(ConnectionInterface $connection, ServerRequestInt
}
}

/** @var array $m legacy PHP 5.3 only */
if ($code < 100 || $code > 999 || \substr_count($headers, "\n") !== ($expected + 1) || (\PHP_VERSION_ID >= 50400 ? \preg_match_all(AbstractMessage::REGEX_HEADERS, $headers) : \preg_match_all(AbstractMessage::REGEX_HEADERS, $headers, $m)) !== $expected) {
if ($code < 100 || $code > 999 || \substr_count($headers, "\n") !== ($expected + 1) || \preg_match_all(AbstractMessage::REGEX_HEADERS, $headers) !== $expected) {
$this->emit('error', array(new \InvalidArgumentException('Unable to send response with invalid response headers')));
$this->writeError($connection, Response::STATUS_INTERNAL_SERVER_ERROR, $request);
return;
Expand Down
3 changes: 1 addition & 2 deletions src/Message/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,7 @@ public static function json($data)
(\defined('JSON_PRETTY_PRINT') ? \JSON_PRETTY_PRINT | \JSON_UNESCAPED_SLASHES | \JSON_UNESCAPED_UNICODE : 0) | (\defined('JSON_PRESERVE_ZERO_FRACTION') ? \JSON_PRESERVE_ZERO_FRACTION : 0)
);

// throw on error, now `false` but used to be `(string) "null"` before PHP 5.5
if ($json === false || (\PHP_VERSION_ID < 50500 && \json_last_error() !== \JSON_ERROR_NONE)) {
if ($json === false) {
throw new \InvalidArgumentException(
'Unable to encode given data as JSON' . (\function_exists('json_last_error_msg') ? ': ' . \json_last_error_msg() : ''),
\json_last_error()
Expand Down
11 changes: 1 addition & 10 deletions src/Message/Uri.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,7 @@ final class Uri implements UriInterface
*/
public function __construct($uri)
{
// @codeCoverageIgnoreStart
if (\PHP_VERSION_ID < 50407 && \strpos($uri, '//') === 0) {
// @link https://3v4l.org/UrAQP
$parts = \parse_url('http:' . $uri);
unset($parts['schema']);
} else {
$parts = \parse_url($uri);
}
// @codeCoverageIgnoreEnd

$parts = \parse_url($uri);
if ($parts === false || (isset($parts['scheme']) && !\preg_match('#^[a-z]+$#i', $parts['scheme'])) || (isset($parts['host']) && \preg_match('#[\s_%+]#', $parts['host']))) {
throw new \InvalidArgumentException('Invalid URI given');
}
Expand Down
6 changes: 0 additions & 6 deletions tests/Client/FunctionalIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,6 @@ public function testRequestLegacyHttpServerWithOnlyLineFeedReturnsSuccessfulResp
/** @group internet */
public function testSuccessfulResponseEmitsEnd()
{
// max_nesting_level was set to 100 for PHP Versions < 5.4 which resulted in failing test for legacy PHP
ini_set('xdebug.max_nesting_level', 256);

$client = new Client(new ClientConnectionManager(new Connector(), Loop::get()));

$request = $client->request(new Request('GET', 'http://www.google.com/', array(), '', '1.0'));
Expand All @@ -155,9 +152,6 @@ public function testSuccessfulResponseEmitsEnd()
/** @group internet */
public function testCancelPendingConnectionEmitsClose()
{
// max_nesting_level was set to 100 for PHP Versions < 5.4 which resulted in failing test for legacy PHP
ini_set('xdebug.max_nesting_level', 256);

$client = new Client(new ClientConnectionManager(new Connector(), Loop::get()));

$request = $client->request(new Request('GET', 'http://www.google.com/', array(), '', '1.0'));
Expand Down
12 changes: 0 additions & 12 deletions tests/FunctionalBrowserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -389,10 +389,6 @@ public function testGetRequestWithResponseBufferExceededDuringStreamingRejects()
*/
public function testCanAccessHttps()
{
if (defined('HHVM_VERSION')) {
$this->markTestSkipped('Not supported on HHVM');
}

\React\Async\await($this->browser->get('https://www.google.com/'));
}

Expand All @@ -401,10 +397,6 @@ public function testCanAccessHttps()
*/
public function testVerifyPeerEnabledForBadSslRejects()
{
if (defined('HHVM_VERSION')) {
$this->markTestSkipped('Not supported on HHVM');
}

$connector = new Connector(array(
'tls' => array(
'verify_peer' => true
Expand All @@ -423,10 +415,6 @@ public function testVerifyPeerEnabledForBadSslRejects()
*/
public function testVerifyPeerDisabledForBadSslResolves()
{
if (defined('HHVM_VERSION')) {
$this->markTestSkipped('Not supported on HHVM');
}

$connector = new Connector(array(
'tls' => array(
'verify_peer' => false
Expand Down
28 changes: 0 additions & 28 deletions tests/FunctionalHttpServerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,6 @@ public function testPlainHttpOnRandomPortWithOtherHostHeaderTakesPrecedence()

public function testSecureHttpsOnRandomPort()
{
if (defined('HHVM_VERSION')) {
$this->markTestSkipped('Not supported on HHVM');
}

$connector = new Connector(array(
'tls' => array('verify_peer' => false)
));
Expand Down Expand Up @@ -155,10 +151,6 @@ public function testSecureHttpsOnRandomPort()

public function testSecureHttpsReturnsData()
{
if (defined('HHVM_VERSION')) {
$this->markTestSkipped('Not supported on HHVM');
}

$http = new HttpServer(function (RequestInterface $request) {
return new Response(
200,
Expand Down Expand Up @@ -193,10 +185,6 @@ public function testSecureHttpsReturnsData()

public function testSecureHttpsOnRandomPortWithoutHostHeaderUsesSocketUri()
{
if (defined('HHVM_VERSION')) {
$this->markTestSkipped('Not supported on HHVM');
}

$connector = new Connector(array(
'tls' => array('verify_peer' => false)
));
Expand Down Expand Up @@ -284,10 +272,6 @@ public function testPlainHttpOnStandardPortWithoutHostHeaderReturnsUriWithNoPort

public function testSecureHttpsOnStandardPortReturnsUriWithNoPort()
{
if (defined('HHVM_VERSION')) {
$this->markTestSkipped('Not supported on HHVM');
}

try {
$socket = new SocketServer('tls://127.0.0.1:443', array('tls' => array(
'local_cert' => __DIR__ . '/../examples/localhost.pem'
Expand Down Expand Up @@ -322,10 +306,6 @@ public function testSecureHttpsOnStandardPortReturnsUriWithNoPort()

public function testSecureHttpsOnStandardPortWithoutHostHeaderUsesSocketUri()
{
if (defined('HHVM_VERSION')) {
$this->markTestSkipped('Not supported on HHVM');
}

try {
$socket = new SocketServer('tls://127.0.0.1:443', array('tls' => array(
'local_cert' => __DIR__ . '/../examples/localhost.pem'
Expand Down Expand Up @@ -389,10 +369,6 @@ public function testPlainHttpOnHttpsStandardPortReturnsUriWithPort()

public function testSecureHttpsOnHttpStandardPortReturnsUriWithPort()
{
if (defined('HHVM_VERSION')) {
$this->markTestSkipped('Not supported on HHVM');
}

try {
$socket = new SocketServer('tls://127.0.0.1:80', array('tls' => array(
'local_cert' => __DIR__ . '/../examples/localhost.pem'
Expand Down Expand Up @@ -726,10 +702,6 @@ public function testConnectWithClosedThroughStreamReturnsNoData()

public function testLimitConcurrentRequestsMiddlewareRequestStreamPausing()
{
if (defined('HHVM_VERSION') && !interface_exists('React\Promise\PromisorInterface')) {
$this->markTestSkipped('Not supported on legacy HHVM with Promise v3');
}

$connector = new Connector();

$http = new HttpServer(
Expand Down
3 changes: 0 additions & 3 deletions tests/HttpServerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,6 @@ public function testSimpleRequestCallsRequestHandlerOnce()
$this->assertSame(1, $called);
}

/**
* @requires PHP 5.4
*/
public function testSimpleRequestCallsArrayRequestHandlerOnce()
{
$this->called = null;
Expand Down
3 changes: 0 additions & 3 deletions tests/Io/MiddlewareRunnerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,6 @@ function (ServerRequestInterface $request) {
$middleware($request);
}

/**
* @requires PHP 7
*/
public function testThrowsIfHandlerThrowsThrowable()
{
$middleware = new MiddlewareRunner(array(
Expand Down
4 changes: 0 additions & 4 deletions tests/Io/RequestHeaderParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -776,10 +776,6 @@ public function testServerParamsWillNotSetRemoteAddressForUnixDomainSockets()

public function testServerParamsWontBeSetOnMissingUrls()
{
if (defined('HHVM_VERSION')) {
$this->markTestSkipped('Not supported on HHVM');
}

$request = null;

$clock = $this->getMockBuilder('React\Http\Io\Clock')->disableOriginalConstructor()->getMock();
Expand Down
6 changes: 0 additions & 6 deletions tests/Io/StreamingServerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,6 @@ public function testRequestEventIsEmitted()
$this->connection->emit('data', array($data));
}

/**
* @requires PHP 5.4
*/
public function testRequestEventIsEmittedForArrayCallable()
{
$this->called = null;
Expand Down Expand Up @@ -2845,9 +2842,6 @@ function ($data) use (&$buffer) {
$this->assertEquals('hello', $exception->getPrevious()->getMessage());
}

/**
* @requires PHP 7
*/
public function testResponseThrowableThrowInCallBackFunctionWillResultInErrorMessage()
{
$server = new StreamingServer(Loop::get(), function (ServerRequestInterface $request) {
Expand Down
12 changes: 1 addition & 11 deletions tests/Message/ResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,6 @@ public function testHtmlMethodReturnsHtmlResponse()
$this->assertEquals('<!doctype html><body>Hello wörld!</body>', (string) $response->getBody());
}

/**
* @requires PHP 5.4
*/
public function testJsonMethodReturnsPrettyPrintedJsonResponse()
{
$response = Response::json(array('text' => 'Hello wörld!'));
Expand All @@ -109,9 +106,6 @@ public function testJsonMethodReturnsPrettyPrintedJsonResponse()
$this->assertEquals("{\n \"text\": \"Hello wörld!\"\n}\n", (string) $response->getBody());
}

/**
* @requires PHP 5.6.6
*/
public function testJsonMethodReturnsZeroFractionsInJsonResponse()
{
$response = Response::json(1.0);
Expand All @@ -132,11 +126,7 @@ public function testJsonMethodReturnsJsonTextForSimpleString()

public function testJsonMethodThrowsForInvalidString()
{
if (PHP_VERSION_ID < 50500) {
$this->setExpectedException('InvalidArgumentException', 'Unable to encode given data as JSON');
} else {
$this->setExpectedException('InvalidArgumentException', 'Unable to encode given data as JSON: Malformed UTF-8 characters, possibly incorrectly encoded');
}
$this->setExpectedException('InvalidArgumentException', 'Unable to encode given data as JSON: Malformed UTF-8 characters, possibly incorrectly encoded');
Response::json("Hello w\xF6rld!");
}

Expand Down
5 changes: 0 additions & 5 deletions tests/Message/UriTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,6 @@ public static function provideValidUris()
*/
public function testToStringReturnsOriginalUriGivenToCtor($string)
{
if (PHP_VERSION_ID < 50519 || (PHP_VERSION_ID < 50603 && PHP_VERSION_ID >= 50606)) {
// @link https://3v4l.org/HdoPG
$this->markTestSkipped('Empty password not supported on legacy PHP');
}

$uri = new Uri($string);

$this->assertEquals($string, (string) $uri);
Expand Down
3 changes: 0 additions & 3 deletions tests/Middleware/LimitConcurrentRequestsMiddlewareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,6 @@ public function testThrowsExceptionDirectlyFromMiddlewareWhenBelowLimit()
});
}

/**
* @requires PHP 7
*/
public function testThrowsErrorDirectlyFromMiddlewareWhenBelowLimit()
{
$middleware = new LimitConcurrentRequestsMiddleware(1);
Expand Down
3 changes: 0 additions & 3 deletions tests/Middleware/RequestBodyBufferMiddlewareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -277,9 +277,6 @@ function (ServerRequestInterface $request) {
$this->assertNull($exception->getPrevious());
}

/**
* @requires PHP 7
*/
public function testBufferingRejectsWhenNextHandlerThrowsErrorWhenStreamEnds()
{
$stream = new ThroughStream();
Expand Down
Loading

0 comments on commit acd2e14

Please sign in to comment.