From 9a1cf7e16b9877f7ded0f33a5d0bba1ae04f2c14 Mon Sep 17 00:00:00 2001 From: Alain Schlesser Date: Tue, 9 Feb 2021 11:38:39 +0000 Subject: [PATCH 01/20] Replace PHPUnit 6+ compat code with Yoast PHPUnit polyfills package --- composer.json | 3 ++- tests/bootstrap.php | 7 ------- tests/phpunit6-compat.php | 16 ---------------- 3 files changed, 2 insertions(+), 24 deletions(-) delete mode 100644 tests/phpunit6-compat.php diff --git a/composer.json b/composer.json index 2e051c9e8..20677e5f0 100644 --- a/composer.json +++ b/composer.json @@ -46,7 +46,8 @@ "wp-coding-standards/wpcs": "^2.0", "dealerdirect/phpcodesniffer-composer-installer": "^0.7", "php-parallel-lint/php-parallel-lint": "^1.3", - "php-parallel-lint/php-console-highlighter": "^0.5.0" + "php-parallel-lint/php-console-highlighter": "^0.5.0", + "yoast/phpunit-polyfills": "^0.2.0" }, "type": "library", "autoload": { diff --git a/tests/bootstrap.php b/tests/bootstrap.php index f94a4872f..3f7e293c6 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -1,12 +1,5 @@ =')) { - class_alias('PHPUnit\Framework\TestCase', 'PHPUnit_Framework_TestCase'); - class_alias('PHPUnit\Framework\Exception', 'PHPUnit_Framework_Exception'); - class_alias('PHPUnit\Framework\ExpectationFailedException', 'PHPUnit_Framework_ExpectationFailedException'); - class_alias('PHPUnit\Framework\Error\Notice', 'PHPUnit_Framework_Error_Notice'); - class_alias('PHPUnit\Framework\Error\Warning', 'PHPUnit_Framework_Error_Warning'); - class_alias('PHPUnit\Framework\Test', 'PHPUnit_Framework_Test'); - class_alias('PHPUnit\Framework\Warning', 'PHPUnit_Framework_Warning'); - class_alias('PHPUnit\Framework\AssertionFailedError', 'PHPUnit_Framework_AssertionFailedError'); - class_alias('PHPUnit\Framework\TestSuite', 'PHPUnit_Framework_TestSuite'); - class_alias('PHPUnit\Framework\TestListener', 'PHPUnit_Framework_TestListener'); - class_alias('PHPUnit\Util\GlobalState', 'PHPUnit_Util_GlobalState'); - class_alias('PHPUnit\Util\Getopt', 'PHPUnit_Util_Getopt'); -} From 310024280879f1a847814f0485e97e13526ca7b6 Mon Sep 17 00:00:00 2001 From: Alain Schlesser Date: Tue, 9 Feb 2021 11:41:17 +0000 Subject: [PATCH 02/20] Use polyfilled test case for all tests --- tests/Auth/Basic.php | 2 +- tests/ChunkedEncoding.php | 2 +- tests/Cookies.php | 2 +- tests/Encoding.php | 2 +- tests/IDNAEncoder.php | 2 +- tests/IRI.php | 2 +- tests/Proxy/HTTP.php | 2 +- tests/Requests.php | 2 +- tests/Response/Headers.php | 2 +- tests/SSL.php | 2 +- tests/Session.php | 2 +- tests/Transport/Base.php | 4 ++-- tests/Utility/FilteredIterator.php | 2 +- 13 files changed, 14 insertions(+), 14 deletions(-) diff --git a/tests/Auth/Basic.php b/tests/Auth/Basic.php index eec54cfc1..bc2a14bc3 100644 --- a/tests/Auth/Basic.php +++ b/tests/Auth/Basic.php @@ -1,6 +1,6 @@ transport, 'test'); $supported = call_user_func($callback); diff --git a/tests/Utility/FilteredIterator.php b/tests/Utility/FilteredIterator.php index 812ed087f..01f9e0a2b 100644 --- a/tests/Utility/FilteredIterator.php +++ b/tests/Utility/FilteredIterator.php @@ -1,6 +1,6 @@ Date: Tue, 9 Feb 2021 11:42:07 +0000 Subject: [PATCH 03/20] Replace isInternalType() with isArray() --- tests/Cookies.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Cookies.php b/tests/Cookies.php index 86ba8d73a..5186593bb 100644 --- a/tests/Cookies.php +++ b/tests/Cookies.php @@ -111,7 +111,7 @@ protected function setCookieRequest($cookies) { $response = Requests::get(httpbin('/cookies/set'), array(), $options); $data = json_decode($response->body, true); - $this->assertInternalType('array', $data); + $this->assertIsArray($data); $this->assertArrayHasKey('cookies', $data); return $data['cookies']; } From 53a590f5f4ce425eb909813176c1e2b8602371ce Mon Sep 17 00:00:00 2001 From: Alain Schlesser Date: Tue, 9 Feb 2021 11:42:34 +0000 Subject: [PATCH 04/20] Use assertStringContainsString() instead of assertContains() --- tests/Transport/fsockopen.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Transport/fsockopen.php b/tests/Transport/fsockopen.php index 21113e6bf..3347f91d4 100644 --- a/tests/Transport/fsockopen.php +++ b/tests/Transport/fsockopen.php @@ -50,6 +50,6 @@ public function testContentLengthHeader() { * Issue #248. */ public function checkContentLengthHeader($headers) { - $this->assertContains('Content-Length: 0', $headers); + $this->assertStringContainsString('Content-Length: 0', $headers); } } From 7268e31f474d112fa4aedb5cf90443dc76f562e0 Mon Sep 17 00:00:00 2001 From: Alain Schlesser Date: Tue, 9 Feb 2021 11:45:06 +0000 Subject: [PATCH 05/20] Remove exception assertion compat code --- tests/Transport/Base.php | 23 ----------------------- 1 file changed, 23 deletions(-) diff --git a/tests/Transport/Base.php b/tests/Transport/Base.php index d5c34d39d..a4dc794f3 100644 --- a/tests/Transport/Base.php +++ b/tests/Transport/Base.php @@ -17,29 +17,6 @@ public function set_up() { } protected $skip_https = false; - /** - * PHPUnit 6+ compatibility shim. - * - * @param mixed $exception - * @param string $message - * @param int|string $code - */ - public function setExpectedException($exception, $message = '', $code = null) { - if (method_exists('PHPUnit_Framework_TestCase', 'setExpectedException')) { - parent::setExpectedException($exception, $message, $code); - } - else { - $this->expectException($exception); - if ($message !== null) { - $this->expectExceptionMessage($message); - } - if ($code !== null) { - $this->expectExceptionCode($code); - } - } - } - - protected function getOptions($other = array()) { $options = array( 'transport' => $this->transport, From 346a13b18cece22ee80e90e12a708cf7430cd515 Mon Sep 17 00:00:00 2001 From: Alain Schlesser Date: Tue, 9 Feb 2021 11:46:27 +0000 Subject: [PATCH 06/20] Replace exception annotations with exception assertions --- tests/Auth/Basic.php | 6 ++--- tests/Cookies.php | 6 ++--- tests/IDNAEncoder.php | 48 ++++++++++++----------------------- tests/IRI.php | 4 +-- tests/Proxy/HTTP.php | 5 ++-- tests/Requests.php | 34 +++++++++++-------------- tests/Response/Headers.php | 6 ++--- tests/Transport/Base.php | 39 ++++++++++------------------ tests/Transport/cURL.php | 23 ++++++----------- tests/Transport/fsockopen.php | 21 +++++---------- 10 files changed, 68 insertions(+), 124 deletions(-) diff --git a/tests/Auth/Basic.php b/tests/Auth/Basic.php index bc2a14bc3..eff132613 100644 --- a/tests/Auth/Basic.php +++ b/tests/Auth/Basic.php @@ -76,11 +76,9 @@ public function testPOSTUsingInstantiation($transport) { $this->assertSame('test', $result->data); } - /** - * @expectedException Requests_Exception - * @expectedExceptionMessage Invalid number of arguments - */ public function testMissingPassword() { + $this->expectException('Requests_Exception'); + $this->expectExceptionMessage('Invalid number of arguments'); new Requests_Auth_Basic(array('user')); } diff --git a/tests/Cookies.php b/tests/Cookies.php index 5186593bb..e2c031b3b 100644 --- a/tests/Cookies.php +++ b/tests/Cookies.php @@ -57,11 +57,9 @@ public function testCookieJarUnsetter() { $this->assertFalse(isset($jar['requests-testcookie'])); } - /** - * @expectedException Requests_Exception - * @expectedExceptionMessage Object is a dictionary, not a list - */ public function testCookieJarAsList() { + $this->expectException('Requests_Exception'); + $this->expectExceptionMessage('Object is a dictionary, not a list'); $cookies = new Requests_Cookie_Jar(); $cookies[] = 'requests-testcookie1=testvalue1'; } diff --git a/tests/IDNAEncoder.php b/tests/IDNAEncoder.php index e71123740..277fc5e9d 100644 --- a/tests/IDNAEncoder.php +++ b/tests/IDNAEncoder.php @@ -22,29 +22,23 @@ public function testEncoding($data, $expected) { $this->assertSame($expected, $result); } - /** - * @expectedException Requests_Exception - * @expectedExceptionMessage Provided string is too long - */ public function testASCIITooLong() { + $this->expectException('Requests_Exception'); + $this->expectExceptionMessage('Provided string is too long'); $data = str_repeat('abcd', 20); Requests_IDNAEncoder::encode($data); } - /** - * @expectedException Requests_Exception - * @expectedExceptionMessage Encoded string is too long - */ public function testEncodedTooLong() { + $this->expectException('Requests_Exception'); + $this->expectExceptionMessage('Encoded string is too long'); $data = str_repeat("\xe4\xbb\x96", 60); Requests_IDNAEncoder::encode($data); } - /** - * @expectedException Requests_Exception - * @expectedExceptionMessage Provided string begins with ACE prefix - */ public function testAlreadyPrefixed() { + $this->expectException('Requests_Exception'); + $this->expectExceptionMessage('Provided string begins with ACE prefix'); Requests_IDNAEncoder::encode("xn--\xe4\xbb\x96"); } @@ -68,43 +62,33 @@ public function testFourByteCharacter() { $this->assertSame('xn--ww6j', $result); } - /** - * @expectedException Requests_Exception - * @expectedExceptionMessage Invalid Unicode codepoint - */ public function testFiveByteCharacter() { + $this->expectException('Requests_Exception'); + $this->expectExceptionMessage('Invalid Unicode codepoint'); Requests_IDNAEncoder::encode("\xfb\xb6\xb6\xb6\xb6"); } - /** - * @expectedException Requests_Exception - * @expectedExceptionMessage Invalid Unicode codepoint - */ public function testSixByteCharacter() { + $this->expectException('Requests_Exception'); + $this->expectExceptionMessage('Invalid Unicode codepoint'); Requests_IDNAEncoder::encode("\xfd\xb6\xb6\xb6\xb6\xb6"); } - /** - * @expectedException Requests_Exception - * @expectedExceptionMessage Invalid Unicode codepoint - */ public function testInvalidASCIICharacterWithMultibyte() { + $this->expectException('Requests_Exception'); + $this->expectExceptionMessage('Invalid Unicode codepoint'); Requests_IDNAEncoder::encode("\0\xc2\xb6"); } - /** - * @expectedException Requests_Exception - * @expectedExceptionMessage Invalid Unicode codepoint - */ public function testUnfinishedMultibyte() { + $this->expectException('Requests_Exception'); + $this->expectExceptionMessage('Invalid Unicode codepoint'); Requests_IDNAEncoder::encode("\xc2"); } - /** - * @expectedException Requests_Exception - * @expectedExceptionMessage Invalid Unicode codepoint - */ public function testPartialMultibyte() { + $this->expectException('Requests_Exception'); + $this->expectExceptionMessage('Invalid Unicode codepoint'); Requests_IDNAEncoder::encode("\xc2\xc2\xb6"); } } diff --git a/tests/IRI.php b/tests/IRI.php index 8db8eff6c..cef75078f 100644 --- a/tests/IRI.php +++ b/tests/IRI.php @@ -384,11 +384,9 @@ public function testWriteAliased() $this->assertSame('test', $iri->fragment); } - /** - * @expectedException PHPUnit_Framework_Error_Notice - */ public function testNonexistantProperty() { + $this->expectNotice('Undefined property: Requests_IRI::nonexistant_prop'); $iri = new Requests_IRI(); $this->assertFalse(isset($iri->nonexistant_prop)); $should_fail = $iri->nonexistant_prop; diff --git a/tests/Proxy/HTTP.php b/tests/Proxy/HTTP.php index f97fbe6a2..a6de95deb 100644 --- a/tests/Proxy/HTTP.php +++ b/tests/Proxy/HTTP.php @@ -60,9 +60,6 @@ public function testConnectWithArray($transport) { /** * @dataProvider transportProvider - * - * @expectedException Requests_Exception - * @expectedExceptionMessage Invalid number of arguments */ public function testConnectInvalidParameters($transport) { $this->checkProxyAvailable(); @@ -71,6 +68,8 @@ public function testConnectInvalidParameters($transport) { 'proxy' => array(REQUESTS_HTTP_PROXY, 'testuser', 'password', 'something'), 'transport' => $transport, ); + $this->expectException('Requests_Exception'); + $this->expectExceptionMessage('Invalid number of arguments'); Requests::get(httpbin('/get'), array(), $options); } diff --git a/tests/Requests.php b/tests/Requests.php index 29ab671f9..b0950fe71 100644 --- a/tests/Requests.php +++ b/tests/Requests.php @@ -1,11 +1,10 @@ expectException('Requests_Exception'); + $this->expectExceptionMessage('Only HTTP(S) requests are handled'); Requests::request('ftp://128.0.0.1/'); } @@ -100,9 +99,6 @@ public function testHeaderOnlyLF() { * * We do not support HTTP/0.9. If this is really an issue for you, file a * new issue, and update your server/proxy to support a proper protocol. - * - * @expectedException Requests_Exception - * @expectedExceptionMessage Response could not be parsed */ public function testInvalidProtocolVersion() { $transport = new RequestsTest_Mock_RawTransport(); @@ -111,14 +107,14 @@ public function testInvalidProtocolVersion() { $options = array( 'transport' => $transport, ); + + $this->expectException('Requests_Exception'); + $this->expectExceptionMessage('Response could not be parsed'); Requests::get('http://example.com/', array(), $options); } /** - * HTTP/0.9 also appears to use a single CRLF instead of two - * - * @expectedException Requests_Exception - * @expectedExceptionMessage Missing header/body separator + * HTTP/0.9 also appears to use a single CRLF instead of two4 */ public function testSingleCRLFSeparator() { $transport = new RequestsTest_Mock_RawTransport(); @@ -127,13 +123,12 @@ public function testSingleCRLFSeparator() { $options = array( 'transport' => $transport, ); + + $this->expectException('Requests_Exception'); + $this->expectExceptionMessage('Missing header/body separator'); Requests::get('http://example.com/', array(), $options); } - /** - * @expectedException Requests_Exception - * @expectedExceptionMessage Response could not be parsed - */ public function testInvalidStatus() { $transport = new RequestsTest_Mock_RawTransport(); $transport->data = "HTTP/1.1 OK\r\nTest: value\nAnother-Test: value\r\n\r\nTest"; @@ -141,6 +136,9 @@ public function testInvalidStatus() { $options = array( 'transport' => $transport, ); + + $this->expectException('Requests_Exception'); + $this->expectExceptionMessage('Response could not be parsed'); Requests::get('http://example.com/', array(), $options); } @@ -156,12 +154,10 @@ public function test30xWithoutLocation() { $this->assertSame(0, $response->redirects); } - /** - * @expectedException Requests_Exception - * @expectedExceptionMessage timed out - */ public function testTimeoutException() { $options = array('timeout' => 0.5); + $this->expectException('Requests_Exception'); + $this->expectExceptionMessage('timed out'); Requests::get(httpbin('/delay/3'), array(), $options); } } diff --git a/tests/Response/Headers.php b/tests/Response/Headers.php index 177200169..65f2b838b 100644 --- a/tests/Response/Headers.php +++ b/tests/Response/Headers.php @@ -37,11 +37,9 @@ public function testIteration() { } } - /** - * @expectedException Requests_Exception - * @expectedExceptionMessage Object is a dictionary, not a list - */ public function testInvalidKey() { + $this->expectException('Requests_Exception'); + $this->expectExceptionMessage('Object is a dictionary, not a list'); $headers = new Requests_Response_Headers(); $headers[] = 'text/plain'; } diff --git a/tests/Transport/Base.php b/tests/Transport/Base.php index a4dc794f3..57553f5ce 100644 --- a/tests/Transport/Base.php +++ b/tests/Transport/Base.php @@ -321,14 +321,12 @@ public function testRelativeRedirects() { $this->assertSame(6, $request->redirects); } - /** - * @expectedException Requests_Exception - * @expectedExceptionMessage Too many redirects - */ public function testTooManyRedirects() { $options = array( 'redirects' => 10, // default, but force just in case ); + $this->expectException('Requests_Exception'); + $this->expectExceptionMessage('Too many redirects'); Requests::get(httpbin('/redirect/11'), array(), $this->getOptions($options)); } @@ -414,10 +412,10 @@ public function testStatusCodeThrow($code, $success) { if (!$success) { if ($code >= 400) { - $this->setExpectedException('Requests_Exception_HTTP_' . $code, null, $code); + $this->expectException('Requests_Exception_HTTP_' . $code, null, $code); } elseif ($code >= 300 && $code < 400) { - $this->setExpectedException('Requests_Exception', null); + $this->expectException('Requests_Exception', null); } } @@ -443,7 +441,7 @@ public function testStatusCodeThrowAllowRedirects($code, $success) { if (!$success) { if ($code >= 400 || $code === 304 || $code === 305 || $code === 306) { - $this->setExpectedException('Requests_Exception_HTTP_' . $code, null, $code); + $this->expectException('Requests_Exception_HTTP_' . $code, null, $code); } } @@ -467,10 +465,6 @@ public function testStatusCodeUnknown() { $this->assertFalse($request->success); } - /** - * @expectedException Requests_Exception_HTTP_Unknown - * @expectedExceptionMessage 599 Unknown - */ public function testStatusCodeThrowUnknown() { $transport = new RequestsTest_Mock_Transport(); $transport->code = 599; @@ -480,6 +474,8 @@ public function testStatusCodeThrowUnknown() { ); $request = Requests::get(httpbin('/status/599'), array(), $options); + $this->expectException('Requests_Exception_HTTP_Unknown'); + $this->expectExceptionMessage('599 Unknown'); $request->throw_for_status(true); } @@ -539,10 +535,8 @@ public function testNonblocking() { $this->assertEquals($empty, $request); } - /** - * @expectedException Requests_Exception - */ public function testBadIP() { + $this->expectException('Requests_Exception'); Requests::get('http://256.256.256.0/', array(), $this->getOptions()); } @@ -559,34 +553,28 @@ public function testHTTPS() { $this->assertEmpty($result['args']); } - /** - * @expectedException Requests_Exception - */ public function testExpiredHTTPS() { if ($this->skip_https) { $this->markTestSkipped('SSL support is not available.'); return; } + $this->expectException('Requests_Exception'); Requests::get('https://testssl-expire.disig.sk/index.en.html', array(), $this->getOptions()); } - /** - * @expectedException Requests_Exception - */ public function testRevokedHTTPS() { if ($this->skip_https) { $this->markTestSkipped('SSL support is not available.'); return; } + $this->expectException('Requests_Exception'); Requests::get('https://testssl-revoked.disig.sk/index.en.html', array(), $this->getOptions()); } /** * Test that SSL fails with a bad certificate - * - * @expectedException Requests_Exception */ public function testBadDomain() { if ($this->skip_https) { @@ -594,6 +582,7 @@ public function testBadDomain() { return; } + $this->expectException('Requests_Exception'); Requests::head('https://wrong.host.badssl.com/', array(), $this->getOptions()); } @@ -640,14 +629,12 @@ public function testSNISupport() { $this->assertSame(200, $request->status_code); } - /** - * @expectedException Requests_Exception - * @expectedExceptionMessage timed out - */ public function testTimeout() { $options = array( 'timeout' => 1, ); + $this->expectException('Requests_Exception'); + $this->expectExceptionMessage('timed out'); Requests::get(httpbin('/delay/10'), array(), $this->getOptions($options)); } diff --git a/tests/Transport/cURL.php b/tests/Transport/cURL.php index 0690d7b4b..7f7c41774 100644 --- a/tests/Transport/cURL.php +++ b/tests/Transport/cURL.php @@ -3,37 +3,30 @@ class RequestsTest_Transport_cURL extends RequestsTest_Transport_Base { protected $transport = 'Requests_Transport_cURL'; - /** - * @expectedException Requests_Exception - * @expectedExceptionMessage t resolve host - */ public function testBadIP() { + $this->expectException('Requests_Exception'); + $this->expectExceptionMessage('t resolve host'); parent::testBadIP(); } - /** - * @expectedException Requests_Exception - * @expectedExceptionMessage certificate subject name - */ public function testExpiredHTTPS() { + $this->expectException('Requests_Exception'); + $this->expectExceptionMessage('certificate subject name'); parent::testExpiredHTTPS(); } - /** - * @expectedException Requests_Exception - * @expectedExceptionMessage certificate subject name - */ public function testRevokedHTTPS() { + $this->expectException('Requests_Exception'); + $this->expectExceptionMessage('certificate subject name'); parent::testRevokedHTTPS(); } /** * Test that SSL fails with a bad certificate - * - * @expectedException Requests_Exception - * @expectedExceptionMessage certificate subject name */ public function testBadDomain() { + $this->expectException('Requests_Exception'); + $this->expectExceptionMessage('certificate subject name'); parent::testBadDomain(); } diff --git a/tests/Transport/fsockopen.php b/tests/Transport/fsockopen.php index 3347f91d4..f77c154a1 100644 --- a/tests/Transport/fsockopen.php +++ b/tests/Transport/fsockopen.php @@ -3,36 +3,29 @@ class RequestsTest_Transport_fsockopen extends RequestsTest_Transport_Base { protected $transport = 'Requests_Transport_fsockopen'; - /** - * @expectedException Requests_Exception - */ public function testBadIP() { + $this->expectException('Requests_Exception'); parent::testBadIP(); } - /** - * @expectedException Requests_Exception - * @expectedExceptionMessage SSL certificate did not match the requested domain name - */ public function testExpiredHTTPS() { + $this->expectException('Requests_Exception'); + $this->expectExceptionMessage('SSL certificate did not match the requested domain name'); parent::testExpiredHTTPS(); } - /** - * @expectedException Requests_Exception - * @expectedExceptionMessage SSL certificate did not match the requested domain name - */ public function testRevokedHTTPS() { + $this->expectException('Requests_Exception'); + $this->expectExceptionMessage('SSL certificate did not match the requested domain name'); parent::testRevokedHTTPS(); } /** * Test that SSL fails with a bad certificate - * - * @expectedException Requests_Exception - * @expectedExceptionMessage SSL certificate did not match the requested domain name */ public function testBadDomain() { + $this->expectException('Requests_Exception'); + $this->expectExceptionMessage('SSL certificate did not match the requested domain name'); parent::testBadDomain(); } From 0e9d322b9a8300077203ad73b8750ddb9f44b20b Mon Sep 17 00:00:00 2001 From: Alain Schlesser Date: Tue, 9 Feb 2021 11:46:41 +0000 Subject: [PATCH 07/20] Include previously skipped tests --- tests/Transport/Base.php | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/tests/Transport/Base.php b/tests/Transport/Base.php index 57553f5ce..4218cb4fd 100644 --- a/tests/Transport/Base.php +++ b/tests/Transport/Base.php @@ -814,13 +814,6 @@ public function testAlternatePort() { $this->assertSame('8080', $matches[1]); } - /** - * This test will be skipped on PHP 8 as it would fail due to the use of an incompatible - * PHPUnit version. Once the test suite is compatible with PHPUnit 9, this "requires" can - * be removed. - * - * @requires PHP < 8 - */ public function testProgressCallback() { $mock = $this->getMockBuilder('stdClass')->setMethods(array('progress'))->getMock(); $mock->expects($this->atLeastOnce())->method('progress'); @@ -834,13 +827,6 @@ public function testProgressCallback() { Requests::get(httpbin('/get'), array(), $options); } - /** - * This test will be skipped on PHP 8 as it would fail due to the use of an incompatible - * PHPUnit version. Once the test suite is compatible with PHPUnit 9, this "requires" can - * be removed. - * - * @requires PHP < 8 - */ public function testAfterRequestCallback() { $mock = $this->getMockBuilder('stdClass') ->setMethods(array('after_request')) From 456ce4486957fbf1a82c490a6def49a910195679 Mon Sep 17 00:00:00 2001 From: Alain Schlesser Date: Fri, 18 Jun 2021 08:34:59 +0200 Subject: [PATCH 08/20] Fix typo Co-authored-by: Juliette <663378+jrfnl@users.noreply.github.com> --- tests/Requests.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Requests.php b/tests/Requests.php index b0950fe71..8e04e1465 100644 --- a/tests/Requests.php +++ b/tests/Requests.php @@ -114,7 +114,7 @@ public function testInvalidProtocolVersion() { } /** - * HTTP/0.9 also appears to use a single CRLF instead of two4 + * HTTP/0.9 also appears to use a single CRLF instead of two. */ public function testSingleCRLFSeparator() { $transport = new RequestsTest_Mock_RawTransport(); From 07f6c9ac72cfff3846fe2e3cb08880a96fb68b1e Mon Sep 17 00:00:00 2001 From: Alain Schlesser Date: Fri, 18 Jun 2021 08:36:00 +0200 Subject: [PATCH 09/20] Use class constant instead of hardcoded string Co-authored-by: Juliette <663378+jrfnl@users.noreply.github.com> --- tests/Cookies.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Cookies.php b/tests/Cookies.php index e2c031b3b..03c6aa5ea 100644 --- a/tests/Cookies.php +++ b/tests/Cookies.php @@ -58,7 +58,7 @@ public function testCookieJarUnsetter() { } public function testCookieJarAsList() { - $this->expectException('Requests_Exception'); + $this->expectException(Requests_Exception::class); $this->expectExceptionMessage('Object is a dictionary, not a list'); $cookies = new Requests_Cookie_Jar(); $cookies[] = 'requests-testcookie1=testvalue1'; From 2b6b7f49b6cb083f0a4b42abfba6f3958429209e Mon Sep 17 00:00:00 2001 From: Alain Schlesser Date: Fri, 18 Jun 2021 08:36:52 +0200 Subject: [PATCH 10/20] Adapt expectException() syntax Co-authored-by: Juliette <663378+jrfnl@users.noreply.github.com> --- tests/Transport/Base.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tests/Transport/Base.php b/tests/Transport/Base.php index 4218cb4fd..066c5ff5a 100644 --- a/tests/Transport/Base.php +++ b/tests/Transport/Base.php @@ -412,10 +412,11 @@ public function testStatusCodeThrow($code, $success) { if (!$success) { if ($code >= 400) { - $this->expectException('Requests_Exception_HTTP_' . $code, null, $code); + $this->expectException('Requests_Exception_HTTP_' . $code); + $this->expectExceptionCode($code); } elseif ($code >= 300 && $code < 400) { - $this->expectException('Requests_Exception', null); + $this->expectException('Requests_Exception'); } } @@ -441,7 +442,8 @@ public function testStatusCodeThrowAllowRedirects($code, $success) { if (!$success) { if ($code >= 400 || $code === 304 || $code === 305 || $code === 306) { - $this->expectException('Requests_Exception_HTTP_' . $code, null, $code); + $this->expectException('Requests_Exception_HTTP_' . $code); + $this->expectExceptionCode($code); } } From be7bbd12826565fdfe1e4774a5ac34c08f3167e0 Mon Sep 17 00:00:00 2001 From: Alain Schlesser Date: Fri, 18 Jun 2021 08:39:57 +0200 Subject: [PATCH 11/20] Add PHPUnit results cache file to .gitignore --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index f252a70c5..a641a47d9 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,6 @@ tests/coverage/* # Ignore local overrides of the PHPCS config file. .phpcs.xml phpcs.xml + +# Ignore PHPUnit results cache file. +.phpunit.result.cache \ No newline at end of file From 10c35fc510956f1919ecee7e5c69f1c60e29fb39 Mon Sep 17 00:00:00 2001 From: Alain Schlesser Date: Fri, 18 Jun 2021 08:46:40 +0200 Subject: [PATCH 12/20] Add missing TestCase file --- tests/TestCase.php | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 tests/TestCase.php diff --git a/tests/TestCase.php b/tests/TestCase.php new file mode 100644 index 000000000..b2a904e4f --- /dev/null +++ b/tests/TestCase.php @@ -0,0 +1,7 @@ + Date: Fri, 18 Jun 2021 08:48:14 +0200 Subject: [PATCH 13/20] Add missing newline to TestCase file --- tests/TestCase.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/TestCase.php b/tests/TestCase.php index b2a904e4f..f464f86ed 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -4,4 +4,4 @@ class RequestsTest_TestCase extends TestCase { -} \ No newline at end of file +} From d0a93484d5a3aeb90c3675ca060b63716bce6c55 Mon Sep 17 00:00:00 2001 From: Alain Schlesser Date: Fri, 18 Jun 2021 08:49:02 +0200 Subject: [PATCH 14/20] Remove hardcoded PHPUnit versions and let the Yoast polyfills handle that --- composer.json | 1 - 1 file changed, 1 deletion(-) diff --git a/composer.json b/composer.json index 20677e5f0..a2cb8cea9 100644 --- a/composer.json +++ b/composer.json @@ -40,7 +40,6 @@ }, "require-dev": { "requests/test-server": "dev-master", - "phpunit/phpunit": "^5.7 || ^6.5 || ^7.5", "squizlabs/php_codesniffer": "^3.5", "phpcompatibility/php-compatibility": "^9.0", "wp-coding-standards/wpcs": "^2.0", From 80efbc86630f9308eda4a31398267201023fa364 Mon Sep 17 00:00:00 2001 From: Alain Schlesser Date: Fri, 18 Jun 2021 08:51:58 +0200 Subject: [PATCH 15/20] Remove unused RequestsTest_Encoding::bin2hex() method --- tests/Encoding.php | 7 ------- 1 file changed, 7 deletions(-) diff --git a/tests/Encoding.php b/tests/Encoding.php index 0864bc756..800fddcf9 100644 --- a/tests/Encoding.php +++ b/tests/Encoding.php @@ -84,11 +84,4 @@ public function testCompatibleInflate($original, $encoded) { $decoded = Requests::compatible_gzinflate($encoded); $this->assertSame($original, $decoded); } - - protected function bin2hex($field) { - $field = bin2hex($field); - $field = chunk_split($field, 2, "\\x"); - $field = "\\x" . substr($field, 0, -2); - return $field; - } } From 3953026aa034c38d098dae419bd1d6d4cb8cd1c3 Mon Sep 17 00:00:00 2001 From: Alain Schlesser Date: Fri, 18 Jun 2021 08:53:52 +0200 Subject: [PATCH 16/20] Add missing newline to .gitignore file --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index a641a47d9..535811fa5 100644 --- a/.gitignore +++ b/.gitignore @@ -10,4 +10,4 @@ tests/coverage/* phpcs.xml # Ignore PHPUnit results cache file. -.phpunit.result.cache \ No newline at end of file +.phpunit.result.cache From 07b71f09fe3f0bb8e96cbddb15598cb4e11ea357 Mon Sep 17 00:00:00 2001 From: Alain Schlesser Date: Fri, 18 Jun 2021 13:06:26 +0200 Subject: [PATCH 17/20] Make sure the Composer autoloader gets included --- composer.json | 5 +++++ phpunit.xml.dist | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index a2cb8cea9..55f1d55a8 100644 --- a/composer.json +++ b/composer.json @@ -54,6 +54,11 @@ "Requests": "library/" } }, + "autoload-dev": { + "files": [ + "tests/bootstrap.php" + ] + }, "scripts": { "lint": [ "@php ./vendor/php-parallel-lint/php-parallel-lint/parallel-lint . -e php --exclude vendor --exclude .git" diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 48856b5eb..3e5613446 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -3,7 +3,7 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/7.5/phpunit.xsd" backupGlobals="true" - bootstrap="tests/bootstrap.php" + bootstrap="vendor/autoload.php" colors="true" verbose="true" > From 3bd072940cc5d50bd73b112fc655fd0851c1be1e Mon Sep 17 00:00:00 2001 From: jrfnl Date: Fri, 18 Jun 2021 13:54:40 +0200 Subject: [PATCH 18/20] Tests: fix running against a Phar file --- composer.json | 5 ----- phpunit.xml.dist | 2 +- tests/bootstrap.php | 8 ++++++++ 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/composer.json b/composer.json index 55f1d55a8..a2cb8cea9 100644 --- a/composer.json +++ b/composer.json @@ -54,11 +54,6 @@ "Requests": "library/" } }, - "autoload-dev": { - "files": [ - "tests/bootstrap.php" - ] - }, "scripts": { "lint": [ "@php ./vendor/php-parallel-lint/php-parallel-lint/parallel-lint . -e php --exclude vendor --exclude .git" diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 3e5613446..48856b5eb 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -3,7 +3,7 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/7.5/phpunit.xsd" backupGlobals="true" - bootstrap="vendor/autoload.php" + bootstrap="tests/bootstrap.php" colors="true" verbose="true" > diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 3f7e293c6..a634655c2 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -24,6 +24,14 @@ function define_from_env($name, $default = false) { require_once dirname(dirname(__FILE__)) . '/library/Requests.php'; Requests::register_autoloader(); +$polyfill_autoloader = dirname(__DIR__) . '/vendor/yoast/phpunit-polyfills/phpunitpolyfills-autoload.php'; +if (file_exists($polyfill_autoloader)) { + require_once $polyfill_autoloader; +} else { + echo 'Please run `composer install` before attempting to run the tests.', PHP_EOL; + die(1); +} + function autoload_tests($class) { if (strpos($class, 'RequestsTest_') !== 0) { return; From 9ad8af4d1c961fd543ed16717d42ea74acb6f724 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Fri, 18 Jun 2021 13:55:06 +0200 Subject: [PATCH 19/20] Tests bootstrap: minor PHP modernation tweaks --- tests/bootstrap.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/bootstrap.php b/tests/bootstrap.php index a634655c2..10aa38155 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -21,7 +21,7 @@ function define_from_env($name, $default = false) { define_from_env('REQUESTS_HTTP_PROXY_AUTH_USER'); define_from_env('REQUESTS_HTTP_PROXY_AUTH_PASS'); -require_once dirname(dirname(__FILE__)) . '/library/Requests.php'; +require_once dirname(__DIR__) . '/library/Requests.php'; Requests::register_autoloader(); $polyfill_autoloader = dirname(__DIR__) . '/vendor/yoast/phpunit-polyfills/phpunitpolyfills-autoload.php'; @@ -39,8 +39,8 @@ function autoload_tests($class) { $class = substr($class, 13); $file = str_replace('_', '/', $class); - if (file_exists(dirname(__FILE__) . '/' . $file . '.php')) { - require_once dirname(__FILE__) . '/' . $file . '.php'; + if (file_exists(__DIR__ . '/' . $file . '.php')) { + require_once __DIR__ . '/' . $file . '.php'; } } From e94cc193901f56385a3c36180e5cdb23abd10480 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Mon, 21 Jun 2021 16:49:05 +0200 Subject: [PATCH 20/20] Composer: use PHPUnit Polyfills at version ^1.0.0 PHPUnit Polyfills 1.0.0 have been released. Ref: https://github.com/Yoast/PHPUnit-Polyfills/releases/tag/1.0.0 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index a2cb8cea9..1b61196b2 100644 --- a/composer.json +++ b/composer.json @@ -46,7 +46,7 @@ "dealerdirect/phpcodesniffer-composer-installer": "^0.7", "php-parallel-lint/php-parallel-lint": "^1.3", "php-parallel-lint/php-console-highlighter": "^0.5.0", - "yoast/phpunit-polyfills": "^0.2.0" + "yoast/phpunit-polyfills": "^1.0.0" }, "type": "library", "autoload": {