From 19f1c51980ddcbc09b02968b86e8ba96185de151 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Tue, 6 Jun 2023 22:52:44 +0200 Subject: [PATCH 01/12] Composer: update the PHPUnit Polyfills A PHPUnit 10 compatible version of the PHPUnit Polyfills has been released, so let's start using it. Ref: * https://github.com/Yoast/PHPUnit-Polyfills/releases/tag/2.0.0 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 0c7acc7d7..79b0c3631 100644 --- a/composer.json +++ b/composer.json @@ -48,7 +48,7 @@ "dealerdirect/phpcodesniffer-composer-installer": "^0.7", "php-parallel-lint/php-parallel-lint": "^1.3.2", "php-parallel-lint/php-console-highlighter": "^1.0.0", - "yoast/phpunit-polyfills": "^1.0.0", + "yoast/phpunit-polyfills": "^2.0.0", "roave/security-advisories": "dev-latest" }, "suggest": { From b555585e82a426975a488d87d7b45f4b3cf73cba Mon Sep 17 00:00:00 2001 From: jrfnl Date: Tue, 6 Jun 2023 16:45:14 +0200 Subject: [PATCH 02/12] Transport/BaseTestCase::dataSNISupport(): remove unused and unnecessary method parameter Data providers cannot take arguments, so this `$options` parameter is useless and should never have been declared. PHPUnit 10 will flag it, so let's remove it. --- tests/Transport/BaseTestCase.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Transport/BaseTestCase.php b/tests/Transport/BaseTestCase.php index 7a2b83d85..bc33ead9b 100644 --- a/tests/Transport/BaseTestCase.php +++ b/tests/Transport/BaseTestCase.php @@ -917,7 +917,7 @@ public function testSNISupport($options) { * * @return array */ - public function dataSNISupport($options) { + public function dataSNISupport() { return [ 'Without options' => [ 'options' => [], From f177e1d2c8d34b0688d29e3b351c26621d590172 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Tue, 6 Jun 2023 16:37:36 +0200 Subject: [PATCH 03/12] TestCase::textArrayToDataprovider(): make static This method is used exclusively by data providers and as of PHPUnit 10, data providers should be static methods, so this method needs to be `static` too. --- tests/Cookie/DomainMatchesTest.php | 2 +- tests/Cookie/PathMatchesTest.php | 2 +- tests/Cookie/UriMatchesTest.php | 2 +- tests/TestCase.php | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/Cookie/DomainMatchesTest.php b/tests/Cookie/DomainMatchesTest.php index 9ae5e70b2..35e0267dc 100644 --- a/tests/Cookie/DomainMatchesTest.php +++ b/tests/Cookie/DomainMatchesTest.php @@ -68,7 +68,7 @@ public function dataManuallySetCookie() { 'example.net', ]; - return $this->textArrayToDataprovider($domains); + return self::textArrayToDataprovider($domains); } /** diff --git a/tests/Cookie/PathMatchesTest.php b/tests/Cookie/PathMatchesTest.php index f1a62b70b..b9a8c71d7 100644 --- a/tests/Cookie/PathMatchesTest.php +++ b/tests/Cookie/PathMatchesTest.php @@ -44,7 +44,7 @@ public function dataManuallySetCookie() { '/test/', ]; - return $this->textArrayToDataprovider($paths); + return self::textArrayToDataprovider($paths); } /** diff --git a/tests/Cookie/UriMatchesTest.php b/tests/Cookie/UriMatchesTest.php index 1dfed6021..c5a2dcace 100644 --- a/tests/Cookie/UriMatchesTest.php +++ b/tests/Cookie/UriMatchesTest.php @@ -272,6 +272,6 @@ public function dataManuallySetCookie() { 'http://example.net/test/', ]; - return $this->textArrayToDataprovider($urls); + return self::textArrayToDataprovider($urls); } } diff --git a/tests/TestCase.php b/tests/TestCase.php index 93d1e617e..c7310a0a8 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -77,7 +77,7 @@ public function transportProvider() { * * @return array[] Array which is usable as a test data provider with named data sets. */ - public function textArrayToDataprovider($input) { + public static function textArrayToDataprovider($input) { $data = []; foreach ($input as $value) { if (!is_string($value)) { From 1b13f11de609ea312da9a59c07dc951a0561c81f Mon Sep 17 00:00:00 2001 From: jrfnl Date: Tue, 6 Jun 2023 16:40:48 +0200 Subject: [PATCH 04/12] TestCase::transportProvider(): make static This method is used exclusively as a data providers and as of PHPUnit 10, data providers should be static methods, so this method needs to be `static` too. --- tests/TestCase.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/TestCase.php b/tests/TestCase.php index c7310a0a8..41b9b5206 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -59,7 +59,7 @@ public function httpbin($suffix = '', $ssl = false) { * * @return array */ - public function transportProvider() { + public static function transportProvider() { $data = []; foreach (Requests::DEFAULT_TRANSPORTS as $transport) { From f15c06c3a5fe25913645c35f4c55f5066e450097 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Tue, 6 Jun 2023 17:00:10 +0200 Subject: [PATCH 05/12] TestCase: split `httpbin()` method and make Session\ConstructorTest::dataValidUrl() method static As of PHPUnit 10, data providers are (again) expected to be `static` methods. One of the data providers is using the `httpbin()` method, but as the `httpbin()` method needs `$this` to handle the test skipping, the method cannot be made static. This commit splits the `httpbin()` method into three methods: * A `skipOnUnavailableHttpbinHost()` method which contains the test skip check. * A `static` `getHttpbinUrl()` method which builds the URL. * The original `httpbin()` method which now calls the two new methods to maintain the same functionality as before. By splitting the method in this way, we prevent having to change all method calls to the `httpbin()` method throughout the test suite and can still fix the data provider method using the `httpbin()` method to not use `$this` (which allows to make it `static`). --- tests/Session/ConstructorTest.php | 8 +++++--- tests/TestCase.php | 26 +++++++++++++++++++++++++- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/tests/Session/ConstructorTest.php b/tests/Session/ConstructorTest.php index ac7d057fb..7e8b24101 100644 --- a/tests/Session/ConstructorTest.php +++ b/tests/Session/ConstructorTest.php @@ -105,6 +105,8 @@ public function dataInvalidTypeNotArray() { * @return void */ public function testValidUrl($input) { + $this->skipOnUnavailableHttpbinHost(); + $this->assertInstanceOf(Session::class, new Session($input)); } @@ -113,11 +115,11 @@ public function testValidUrl($input) { * * @return array */ - public function dataValidUrl() { + public static function dataValidUrl() { return [ 'null' => [null], - 'string' => [$this->httpbin('/')], - 'stringable object' => [new Iri($this->httpbin('/'))], + 'string' => [self::getHttpbinUrl('/')], + 'stringable object' => [new Iri(self::getHttpbinUrl('/'))], ]; } } diff --git a/tests/TestCase.php b/tests/TestCase.php index 41b9b5206..148b3a786 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -33,7 +33,7 @@ public function skipWhenTransportNotAvailable($transport) { } /** - * Retrieve a URL to use for testing. + * Retrieve a URL to use for testing and mark the test as skipped if the server for that URL is unavailable. * * @param string $suffix The query path to add to the base URL. * @param bool $ssl Whether to get the URL using the `http` or the `https` protocol. @@ -42,6 +42,19 @@ public function skipWhenTransportNotAvailable($transport) { * @return string */ public function httpbin($suffix = '', $ssl = false) { + $this->skipOnUnavailableHttpbinHost($ssl); + + return self::getHttpbinUrl($suffix, $ssl); + } + + /** + * Check if a test which depends on a certain server type to be available should run or not. + * + * @param bool $ssl Whether the URL under tests will be using the `http` or the `https` protocol. + * + * @return void + */ + public function skipOnUnavailableHttpbinHost($ssl = false) { if ($ssl === false && REQUESTS_TEST_SERVER_HTTP_AVAILABLE === false) { $this->markTestSkipped(sprintf('Host %s not available. This needs investigation', REQUESTS_TEST_HOST_HTTP)); } @@ -49,7 +62,18 @@ public function httpbin($suffix = '', $ssl = false) { if ($ssl === true && REQUESTS_TEST_SERVER_HTTPS_AVAILABLE === false) { $this->markTestSkipped(sprintf('Host %s not available. This needs investigation', REQUESTS_TEST_HOST_HTTPS)); } + } + /** + * Retrieve a URL to use for testing. + * + * @param string $suffix The query path to add to the base URL. + * @param bool $ssl Whether to get the URL using the `http` or the `https` protocol. + * Defaults to `false`, which will result in a URL using `http`. + * + * @return string + */ + public static function getHttpbinUrl($suffix = '', $ssl = false) { $host = $ssl ? 'https://' . \REQUESTS_TEST_HOST_HTTPS : 'http://' . \REQUESTS_TEST_HOST_HTTP; return rtrim($host, '/') . '/' . ltrim($suffix, '/'); } From 64e62ecb5985daf1da36348c904fb7a59c13040c Mon Sep 17 00:00:00 2001 From: jrfnl Date: Tue, 6 Jun 2023 16:59:33 +0200 Subject: [PATCH 06/12] Tests: make dataproviders `static` As of PHPUnit 10, data providers are (again) expected to be `static` methods. This updates the test suite to respect that. Includes removing the use of `$this` from select data providers. --- tests/Auth/Basic/ConstructorTest.php | 4 ++-- tests/Autoload/AutoloadTest.php | 2 +- tests/Cookie/ConstructorTest.php | 16 ++++++++-------- tests/Cookie/DomainMatchesTest.php | 6 +++--- tests/Cookie/Jar/ConstructorTest.php | 4 ++-- tests/Cookie/Jar/NormalizeCookieTest.php | 2 +- tests/Cookie/NormalizeTest.php | 8 ++++---- tests/Cookie/ParseTest.php | 4 ++-- tests/Cookie/PathMatchesTest.php | 6 +++--- tests/Cookie/UriMatchesTest.php | 6 +++--- tests/Exception/Http/HttpTest.php | 4 ++-- tests/Exception/Http/StatusUnknownTest.php | 2 +- tests/Exception/Transport/Curl/CurlTest.php | 2 +- tests/Hooks/DispatchTest.php | 4 ++-- tests/Hooks/RegisterTest.php | 8 ++++---- tests/IdnaEncoder/IdnaEncoderTest.php | 6 +++--- tests/Ipv6/CheckIpv6Test.php | 4 ++-- tests/Ipv6/CompressTest.php | 4 ++-- tests/Ipv6/UncompressTest.php | 4 ++-- tests/Iri/ConstructorTest.php | 2 +- tests/Port/GetTest.php | 6 +++--- tests/Proxy/Http/ConstructorTest.php | 2 +- tests/Requests/DecodeChunkedTest.php | 4 ++-- tests/Requests/DecompressionTest.php | 14 +++++++------- tests/Requests/FlattenTest.php | 4 ++-- tests/Requests/RequestsTest.php | 8 ++++---- tests/Requests/SetCertificatePathTest.php | 4 ++-- tests/Response/DecodeBodyTest.php | 2 +- tests/Response/Headers/ArrayAccessTest.php | 6 +++--- tests/Response/Headers/FlattenTest.php | 4 ++-- tests/Response/Headers/GetValuesTest.php | 4 ++-- tests/Response/IsRedirectTest.php | 4 ++-- tests/Session/ConstructorTest.php | 4 ++-- tests/Session/RequestMultipleTest.php | 4 ++-- tests/Ssl/MatchDomainTest.php | 2 +- tests/Ssl/SslTestCase.php | 4 ++-- tests/Ssl/VerifyCertificateTest.php | 10 +++++----- tests/Ssl/VerifyReferenceNameTest.php | 4 ++-- tests/Transport/BaseTestCase.php | 14 +++++++------- .../ArrayAccessTest.php | 4 ++-- .../Utility/FilteredIterator/ConstructorTest.php | 12 ++++++------ tests/Utility/FilteredIterator/CurrentTest.php | 2 +- .../FilteredIterator/SerializationTest.php | 2 +- .../InputValidator/HasArrayAccessTest.php | 4 ++-- .../Utility/InputValidator/IsCurlHandleTest.php | 4 ++-- tests/Utility/InputValidator/IsIterableTest.php | 4 ++-- .../InputValidator/IsNumericArrayKeyTest.php | 4 ++-- .../InputValidator/IsStringOrStringableTest.php | 4 ++-- .../InputValidator/IsStringableObjectTest.php | 4 ++-- 49 files changed, 123 insertions(+), 123 deletions(-) diff --git a/tests/Auth/Basic/ConstructorTest.php b/tests/Auth/Basic/ConstructorTest.php index a7b392a51..bb98ba78d 100644 --- a/tests/Auth/Basic/ConstructorTest.php +++ b/tests/Auth/Basic/ConstructorTest.php @@ -34,7 +34,7 @@ public function testInvalidInputType($input) { * * @return array */ - public function dataInvalidInputType() { + public static function dataInvalidInputType() { return TypeProviderHelper::getAllExcept(TypeProviderHelper::GROUP_NULL, TypeProviderHelper::GROUP_ARRAY); } @@ -59,7 +59,7 @@ public function testInvalidArgumentCount($input) { * * @return array */ - public function dataInvalidArgumentCount() { + public static function dataInvalidArgumentCount() { return [ 'empty array' => [[]], 'array with only one element' => [['user']], diff --git a/tests/Autoload/AutoloadTest.php b/tests/Autoload/AutoloadTest.php index 4a8cd358b..c9acb2a6b 100644 --- a/tests/Autoload/AutoloadTest.php +++ b/tests/Autoload/AutoloadTest.php @@ -91,7 +91,7 @@ public function testLoad($class_name, $expected) { * * @return array */ - public function dataLoad() { + public static function dataLoad() { return [ 'Request for class not in this package should be rejected' => [ 'class_name' => 'Unrelated\Package\ClassName', diff --git a/tests/Cookie/ConstructorTest.php b/tests/Cookie/ConstructorTest.php index 9aabcf664..d9b32b065 100644 --- a/tests/Cookie/ConstructorTest.php +++ b/tests/Cookie/ConstructorTest.php @@ -50,7 +50,7 @@ public function testInvalidValue($input) { * * @return array */ - public function dataInvalidStringInput() { + public static function dataInvalidStringInput() { return TypeProviderHelper::getAllExcept(TypeProviderHelper::GROUP_STRING); } @@ -75,7 +75,7 @@ public function testInvalidAttributes($input) { * * @return array */ - public function dataInvalidAttributes() { + public static function dataInvalidAttributes() { $except = array_intersect(TypeProviderHelper::GROUP_ITERABLE, TypeProviderHelper::GROUP_ARRAY_ACCESSIBLE); return TypeProviderHelper::getAllExcept($except); } @@ -101,7 +101,7 @@ public function testInvalidFlags($input) { * * @return array */ - public function dataInvalidFlags() { + public static function dataInvalidFlags() { return TypeProviderHelper::getAllExcept(TypeProviderHelper::GROUP_ARRAY); } @@ -126,7 +126,7 @@ public function testInvalidReferenceTime($input) { * * @return array */ - public function dataInvalidReferenceTime() { + public static function dataInvalidReferenceTime() { return TypeProviderHelper::getAllExcept(TypeProviderHelper::GROUP_NULL, TypeProviderHelper::GROUP_INT); } @@ -152,7 +152,7 @@ public function testMinimalArguments($name, $value) { * * @return array */ - public function dataMinimalArguments() { + public static function dataMinimalArguments() { return [ 'empty name and value' => [ 'name' => '', @@ -199,7 +199,7 @@ public function testFlagMerging($flags, $expected) { * * @return array */ - public function dataFlagMerging() { + public static function dataFlagMerging() { return [ 'empty array' => [ 'flags' => [], @@ -269,7 +269,7 @@ public function testSetReferenceTime($time, $expected = null) { * * @return array */ - public function dataSetReferenceTime() { + public static function dataSetReferenceTime() { return [ 'null' => [ 'time' => null, @@ -302,7 +302,7 @@ public function testAttributesAreNormalized($attributes, $expected) { * * @return array */ - public function dataAttributesAreNormalized() { + public static function dataAttributesAreNormalized() { return [ 'empty array' => [ 'attributes' => [], diff --git a/tests/Cookie/DomainMatchesTest.php b/tests/Cookie/DomainMatchesTest.php index 35e0267dc..c3bd86b92 100644 --- a/tests/Cookie/DomainMatchesTest.php +++ b/tests/Cookie/DomainMatchesTest.php @@ -34,7 +34,7 @@ public function testInvalidInput($input) { * * @return array */ - public function dataInvalidInput() { + public static function dataInvalidInput() { return TypeProviderHelper::getAllExcept(TypeProviderHelper::GROUP_STRING); } @@ -62,7 +62,7 @@ public function testManuallySetCookie($domain) { * * @return array */ - public function dataManuallySetCookie() { + public static function dataManuallySetCookie() { $domains = [ 'example.com', 'example.net', @@ -117,7 +117,7 @@ public function testDomainMatch($original, $check, $matches, $domain_matches) { * * @return array */ - public function dataDomainMatch() { + public static function dataDomainMatch() { return [ 'Empty string' => [ 'original' => 'example.com', diff --git a/tests/Cookie/Jar/ConstructorTest.php b/tests/Cookie/Jar/ConstructorTest.php index ba02766cf..98952f824 100644 --- a/tests/Cookie/Jar/ConstructorTest.php +++ b/tests/Cookie/Jar/ConstructorTest.php @@ -34,7 +34,7 @@ public function testInvalidInputType($input) { * * @return array */ - public function dataInvalidInputType() { + public static function dataInvalidInputType() { return TypeProviderHelper::getAllExcept(TypeProviderHelper::GROUP_ARRAY); } @@ -64,7 +64,7 @@ public function testValidInputType($input) { * * @return array */ - public function dataValidInputType() { + public static function dataValidInputType() { return TypeProviderHelper::getSelection(TypeProviderHelper::GROUP_ARRAY); } } diff --git a/tests/Cookie/Jar/NormalizeCookieTest.php b/tests/Cookie/Jar/NormalizeCookieTest.php index 0c28bdfdf..f90afb9d8 100644 --- a/tests/Cookie/Jar/NormalizeCookieTest.php +++ b/tests/Cookie/Jar/NormalizeCookieTest.php @@ -55,7 +55,7 @@ public function testNormalizationWithKey($cookie, $expected_name) { * * @return array */ - public function dataNormalization() { + public static function dataNormalization() { return [ 'unbaked cookie (string)' => [ 'cookie' => self::COOKIE_VALUE, diff --git a/tests/Cookie/NormalizeTest.php b/tests/Cookie/NormalizeTest.php index ed6a0bcb6..7a4c74eac 100644 --- a/tests/Cookie/NormalizeTest.php +++ b/tests/Cookie/NormalizeTest.php @@ -36,7 +36,7 @@ public function testNormalizeAttributes($attributes, $expected) { * * @return array */ - public function dataNormalizeAttributes() { + public static function dataNormalizeAttributes() { return [ /* * Test cases specific to the normalize() method. @@ -275,7 +275,7 @@ public function dataNormalizeAttributes() { * * @return array */ - public function dataNormalizeAttributesExpiresUnsupportedType() { + public static function dataNormalizeAttributesExpiresUnsupportedType() { $types = TypeProviderHelper::getAllExcept(TypeProviderHelper::GROUP_INT, TypeProviderHelper::GROUP_STRING); $data = []; @@ -296,7 +296,7 @@ public function dataNormalizeAttributesExpiresUnsupportedType() { * * @return array */ - public function dataNormalizeAttributesMaxAgeUnsupportedType() { + public static function dataNormalizeAttributesMaxAgeUnsupportedType() { $types = TypeProviderHelper::getAllExcept(TypeProviderHelper::GROUP_INT, TypeProviderHelper::GROUP_STRING); $data = []; @@ -317,7 +317,7 @@ public function dataNormalizeAttributesMaxAgeUnsupportedType() { * * @return array */ - public function dataNormalizeAttributesDomainUnsupportedType() { + public static function dataNormalizeAttributesDomainUnsupportedType() { $types = TypeProviderHelper::getAllExcept(TypeProviderHelper::GROUP_STRING); $data = []; diff --git a/tests/Cookie/ParseTest.php b/tests/Cookie/ParseTest.php index d844df219..3e29dd713 100644 --- a/tests/Cookie/ParseTest.php +++ b/tests/Cookie/ParseTest.php @@ -55,7 +55,7 @@ public function testParseInvalidName($input) { * * @return array */ - public function dataInvalidStringInput() { + public static function dataInvalidStringInput() { return TypeProviderHelper::getAllExcept(TypeProviderHelper::GROUP_STRING); } @@ -401,7 +401,7 @@ public function testParsingHeaderWithOrigin($header, $origin, $expected, $expect * * @return array */ - public function dataParsingHeaderWithOrigin() { + public static function dataParsingHeaderWithOrigin() { return [ // Varying origin path. 'Origin: http://example.com (no trailing slash for path)' => [ diff --git a/tests/Cookie/PathMatchesTest.php b/tests/Cookie/PathMatchesTest.php index b9a8c71d7..8faa2d44d 100644 --- a/tests/Cookie/PathMatchesTest.php +++ b/tests/Cookie/PathMatchesTest.php @@ -36,7 +36,7 @@ public function testManuallySetCookie($path) { * * @return array */ - public function dataManuallySetCookie() { + public static function dataManuallySetCookie() { $paths = [ '', '/', @@ -72,7 +72,7 @@ public function testPathMatch($original, $check, $matches) { * * @return array */ - public function dataPathMatchUndesiredInputTypes() { + public static function dataPathMatchUndesiredInputTypes() { $data = []; $all_types = TypeProviderHelper::getAll(); foreach ($all_types as $key => $value) { @@ -111,7 +111,7 @@ public function dataPathMatchUndesiredInputTypes() { * * @return array */ - public function dataPathMatch() { + public static function dataPathMatch() { return [ 'Exact match: "/"' => [ 'original' => '/', diff --git a/tests/Cookie/UriMatchesTest.php b/tests/Cookie/UriMatchesTest.php index c5a2dcace..749b7e9a9 100644 --- a/tests/Cookie/UriMatchesTest.php +++ b/tests/Cookie/UriMatchesTest.php @@ -68,7 +68,7 @@ public function testUrlMatch($domain, $path, $check, $matches, $domain_matches) * * @return array */ - public function dataUrlMatch() { + public static function dataUrlMatch() { return [ // Domain handling. 'Domain handling: same domain name, same TLD' => [ @@ -211,7 +211,7 @@ public function testUrlMatchSecure($secure, $scheme, $expected) { * * @return array */ - public function dataUrlMatchSecure() { + public static function dataUrlMatchSecure() { return [ 'Secure matching: off, scheme: http' => [ 'secure' => false, @@ -261,7 +261,7 @@ public function testManuallySetCookie($url) { * * @return array */ - public function dataManuallySetCookie() { + public static function dataManuallySetCookie() { $urls = [ 'http://example.com', 'http://example.com/', diff --git a/tests/Exception/Http/HttpTest.php b/tests/Exception/Http/HttpTest.php index 1d53b806c..e5871d892 100644 --- a/tests/Exception/Http/HttpTest.php +++ b/tests/Exception/Http/HttpTest.php @@ -39,7 +39,7 @@ public function testException($expected_msg, $expected_reason, $reason = null) { * * @return array */ - public function dataException() { + public static function dataException() { return [ 'null (or not passed)' => [ 'expected_msg' => 'Unknown', @@ -72,7 +72,7 @@ public function testGetClass($code, $expected) { * * @return array */ - public function dataGetClass() { + public static function dataGetClass() { $default = StatusUnknown::class; return [ diff --git a/tests/Exception/Http/StatusUnknownTest.php b/tests/Exception/Http/StatusUnknownTest.php index 1101ad53b..d7bd9963a 100644 --- a/tests/Exception/Http/StatusUnknownTest.php +++ b/tests/Exception/Http/StatusUnknownTest.php @@ -33,7 +33,7 @@ public function testException($expected_code, $data = null) { * * @return array */ - public function dataException() { + public static function dataException() { $response_with_status = new Response(); $response_with_status->status_code = 12345; diff --git a/tests/Exception/Transport/Curl/CurlTest.php b/tests/Exception/Transport/Curl/CurlTest.php index c975ae1fe..366ff092e 100644 --- a/tests/Exception/Transport/Curl/CurlTest.php +++ b/tests/Exception/Transport/Curl/CurlTest.php @@ -50,7 +50,7 @@ public function testException( * * @return array */ - public function dataException() { + public static function dataException() { return [ 'Everything set to null (or not passed)' => [ 'expected_msg' => '-1 Unknown', diff --git a/tests/Hooks/DispatchTest.php b/tests/Hooks/DispatchTest.php index e9f670599..4de29a529 100644 --- a/tests/Hooks/DispatchTest.php +++ b/tests/Hooks/DispatchTest.php @@ -50,7 +50,7 @@ public function testInvalidHookname($input) { * * @return array */ - public function dataInvalidHookname() { + public static function dataInvalidHookname() { return TypeProviderHelper::getAllExcept(TypeProviderHelper::GROUP_STRING); } @@ -75,7 +75,7 @@ public function testInvalidParameters($input) { * * @return array */ - public function dataInvalidParameters() { + public static function dataInvalidParameters() { return TypeProviderHelper::getAllExcept(TypeProviderHelper::GROUP_ARRAY); } diff --git a/tests/Hooks/RegisterTest.php b/tests/Hooks/RegisterTest.php index 57ce95c90..b14639d74 100644 --- a/tests/Hooks/RegisterTest.php +++ b/tests/Hooks/RegisterTest.php @@ -51,7 +51,7 @@ public function testInvalidHookname($input) { * * @return array */ - public function dataInvalidHookname() { + public static function dataInvalidHookname() { return TypeProviderHelper::getAllExcept(TypeProviderHelper::GROUP_STRING); } @@ -76,11 +76,11 @@ public function testInvalidCallback($input) { * * @return array */ - public function dataInvalidCallback() { + public static function dataInvalidCallback() { return [ 'null' => [null], 'non-existent function' => ['functionname'], - 'non-existent method' => [[$this, 'dummyCallbackDoesNotExist']], + 'non-existent method' => [[__CLASS__, 'dummyCallbackDoesNotExist']], 'empty array' => [[]], 'plain object' => [new stdClass(), 'method'], ]; @@ -107,7 +107,7 @@ public function testInvalidPriority($input) { * * @return array */ - public function dataInvalidPriority() { + public static function dataInvalidPriority() { return TypeProviderHelper::getAllExcept(TypeProviderHelper::GROUP_INT, ['numeric string']); } diff --git a/tests/IdnaEncoder/IdnaEncoderTest.php b/tests/IdnaEncoder/IdnaEncoderTest.php index dd2a24e15..af7baea21 100644 --- a/tests/IdnaEncoder/IdnaEncoderTest.php +++ b/tests/IdnaEncoder/IdnaEncoderTest.php @@ -38,7 +38,7 @@ public function testInvalidInputType($data) { * * @return array */ - public function dataInvalidInputType() { + public static function dataInvalidInputType() { return TypeProviderHelper::getAllExcept(TypeProviderHelper::GROUP_STRINGABLE); } @@ -62,7 +62,7 @@ public function testEncoding($data, $expected) { * * @return array */ - public function dataEncoding() { + public static function dataEncoding() { return [ 'empty string' => [ 'data' => '', @@ -242,7 +242,7 @@ public function testInvalidUnicode($data) { * * @return array */ - public function dataInvalidUnicode() { + public static function dataInvalidUnicode() { return [ 'Five-byte character' => ["\xfb\xb6\xb6\xb6\xb6"], 'Six-byte character' => ["\xfd\xb6\xb6\xb6\xb6\xb6"], diff --git a/tests/Ipv6/CheckIpv6Test.php b/tests/Ipv6/CheckIpv6Test.php index 6193c1250..25f322fd0 100644 --- a/tests/Ipv6/CheckIpv6Test.php +++ b/tests/Ipv6/CheckIpv6Test.php @@ -39,7 +39,7 @@ public function testInvalidInputType($ip) { * * @return array */ - public function dataInvalidInputType() { + public static function dataInvalidInputType() { return TypeProviderHelper::getAllExcept(TypeProviderHelper::GROUP_STRINGABLE); } @@ -61,7 +61,7 @@ public function testValidInputType($ip) { * * @return array */ - public function dataValidInputType() { + public static function dataValidInputType() { return [ 'string' => ['::1'], 'stringable' => [new StringableObject('0:1234:dc0:41:216:3eff:fe67:3e01')], diff --git a/tests/Ipv6/CompressTest.php b/tests/Ipv6/CompressTest.php index 22e82f959..22b298910 100644 --- a/tests/Ipv6/CompressTest.php +++ b/tests/Ipv6/CompressTest.php @@ -39,7 +39,7 @@ public function testInvalidInputType($ip) { * * @return array */ - public function dataInvalidInputType() { + public static function dataInvalidInputType() { return TypeProviderHelper::getAllExcept(TypeProviderHelper::GROUP_STRINGABLE); } @@ -61,7 +61,7 @@ public function testValidInputType($ip) { * * @return array */ - public function dataValidInputType() { + public static function dataValidInputType() { return [ 'string' => ['::1'], 'stringable' => [new StringableObject('0:1234:dc0:41:216:3eff:fe67:3e01')], diff --git a/tests/Ipv6/UncompressTest.php b/tests/Ipv6/UncompressTest.php index 4153fd090..3eed170c5 100644 --- a/tests/Ipv6/UncompressTest.php +++ b/tests/Ipv6/UncompressTest.php @@ -39,7 +39,7 @@ public function testInvalidInputType($ip) { * * @return array */ - public function dataInvalidInputType() { + public static function dataInvalidInputType() { return TypeProviderHelper::getAllExcept(TypeProviderHelper::GROUP_STRINGABLE); } @@ -61,7 +61,7 @@ public function testValidInputType($ip) { * * @return array */ - public function dataValidInputType() { + public static function dataValidInputType() { return [ 'string' => ['::1'], 'stringable' => [new StringableObject('0:1234:dc0:41:216:3eff:fe67:3e01')], diff --git a/tests/Iri/ConstructorTest.php b/tests/Iri/ConstructorTest.php index 2c9405726..16757d760 100644 --- a/tests/Iri/ConstructorTest.php +++ b/tests/Iri/ConstructorTest.php @@ -34,7 +34,7 @@ public function testInvalidInput($iri) { * * @return array */ - public function dataInvalidInput() { + public static function dataInvalidInput() { return TypeProviderHelper::getAllExcept(TypeProviderHelper::GROUP_NULL, TypeProviderHelper::GROUP_STRINGABLE); } diff --git a/tests/Port/GetTest.php b/tests/Port/GetTest.php index 86eb6df76..5b3b65806 100644 --- a/tests/Port/GetTest.php +++ b/tests/Port/GetTest.php @@ -34,7 +34,7 @@ public function testGetPortThrowsExceptionOnInvalidInputType($input) { * * @return array */ - public function dataGetPortThrowsExceptionOnInvalidInputType() { + public static function dataGetPortThrowsExceptionOnInvalidInputType() { return TypeProviderHelper::getAllExcept(TypeProviderHelper::GROUP_STRING); } @@ -59,7 +59,7 @@ public function testGetPortThrowsExceptionOnUnsupportedPortType($input) { * * @return array */ - public function dataGetPortThrowsExceptionOnUnsupportedPortType() { + public static function dataGetPortThrowsExceptionOnUnsupportedPortType() { return [ 'type not supported' => ['FTP'], 'empty string' => [''], @@ -85,7 +85,7 @@ public function testGetPort($input, $expected) { * * @return array */ - public function dataGetPort() { + public static function dataGetPort() { return [ 'lowercase type' => [ 'input' => 'https', diff --git a/tests/Proxy/Http/ConstructorTest.php b/tests/Proxy/Http/ConstructorTest.php index 366c91ec7..769e3acbb 100644 --- a/tests/Proxy/Http/ConstructorTest.php +++ b/tests/Proxy/Http/ConstructorTest.php @@ -33,7 +33,7 @@ public function testInvalidParameterType($input) { * * @return array */ - public function dataInvalidParameterType() { + public static function dataInvalidParameterType() { return TypeProviderHelper::getAllExcept( TypeProviderHelper::GROUP_NULL, TypeProviderHelper::GROUP_STRING, diff --git a/tests/Requests/DecodeChunkedTest.php b/tests/Requests/DecodeChunkedTest.php index d97a44b95..a1ebdf242 100644 --- a/tests/Requests/DecodeChunkedTest.php +++ b/tests/Requests/DecodeChunkedTest.php @@ -41,7 +41,7 @@ public function testChunked($body, $expected) { * * @return array */ - public function dataChunked() { + public static function dataChunked() { return [ [ 'body' => "25\r\nThis is the data in the first chunk\r\n\r\n1A\r\nand this is the second one\r\n0\r\n", @@ -98,7 +98,7 @@ public function testNotActuallyChunked($body) { * * @return array */ - public function dataNotActuallyChunked() { + public static function dataNotActuallyChunked() { return [ 'empty string' => [''], 'invalid chunk size' => ['Hello! This is a non-chunked response!'], diff --git a/tests/Requests/DecompressionTest.php b/tests/Requests/DecompressionTest.php index 9dd410f3b..e8bbd8ace 100644 --- a/tests/Requests/DecompressionTest.php +++ b/tests/Requests/DecompressionTest.php @@ -54,7 +54,7 @@ public function testCompatibleInflate($expected, $compressed) { * * @return array */ - public function dataDecompressNotCompressed() { + public static function dataDecompressNotCompressed() { return [ 'not compressed: empty string' => [ 'expected' => '', @@ -76,8 +76,8 @@ public function dataDecompressNotCompressed() { * * @return array */ - public function dataCompatibleInflateNotCompressed() { - $data = $this->dataDecompressNotCompressed(); + public static function dataCompatibleInflateNotCompressed() { + $data = self::dataDecompressNotCompressed(); foreach ($data as $key => $value) { $data[$key]['expected'] = false; } @@ -90,7 +90,7 @@ public function dataCompatibleInflateNotCompressed() { * * @return array */ - public function dataGzip() { + public static function dataGzip() { return [ /* * Test data generated using CLI command: @@ -119,7 +119,7 @@ public function dataGzip() { * * @return array */ - public function dataDeflate() { + public static function dataDeflate() { return [ // TODO: What is this byte stream representing? Looks like GZIP header with ZLIB compressed data... 'deflate: foobar' => [ @@ -142,7 +142,7 @@ public function dataDeflate() { * * @return array */ - public function dataDeflateWithoutHeaders() { + public static function dataDeflateWithoutHeaders() { return [ /* * Test data generated using CLI command: @@ -232,7 +232,7 @@ public function testCompatibleGzinflateInvalidInputType($input) { * * @return array */ - public function dataInvalidInputType() { + public static function dataInvalidInputType() { return TypeProviderHelper::getAllExcept(TypeProviderHelper::GROUP_STRING); } } diff --git a/tests/Requests/FlattenTest.php b/tests/Requests/FlattenTest.php index f02e8b785..58d101a28 100644 --- a/tests/Requests/FlattenTest.php +++ b/tests/Requests/FlattenTest.php @@ -34,7 +34,7 @@ public function testInvalidData($input) { * * @return array */ - public function dataInvalidData() { + public static function dataInvalidData() { return TypeProviderHelper::getAllExcept(TypeProviderHelper::GROUP_ITERABLE); } @@ -61,7 +61,7 @@ public function testFlatten($input) { * * @return array */ - public function dataFlatten() { + public static function dataFlatten() { $to_flatten = ['key1' => 'value1', 'key2' => 'value2']; return [ diff --git a/tests/Requests/RequestsTest.php b/tests/Requests/RequestsTest.php index 1eabff3bd..e229ace17 100644 --- a/tests/Requests/RequestsTest.php +++ b/tests/Requests/RequestsTest.php @@ -37,7 +37,7 @@ public function testRequestInvalidUrl($input) { * * @return array */ - public function dataRequestInvalidUrl() { + public static function dataRequestInvalidUrl() { return TypeProviderHelper::getAllExcept(TypeProviderHelper::GROUP_STRINGABLE); } @@ -64,7 +64,7 @@ public function testRequestInvalidType($input) { * * @return array */ - public function dataInvalidTypeNotString() { + public static function dataInvalidTypeNotString() { return TypeProviderHelper::getAllExcept(TypeProviderHelper::GROUP_STRING); } @@ -109,7 +109,7 @@ public function testRequestMultipleInvalidRequests($input) { * * @return array */ - public function dataRequestMultipleInvalidRequests() { + public static function dataRequestMultipleInvalidRequests() { $except = array_intersect(TypeProviderHelper::GROUP_ITERABLE, TypeProviderHelper::GROUP_ARRAY_ACCESSIBLE); return TypeProviderHelper::getAllExcept($except); } @@ -137,7 +137,7 @@ public function testRequestMultipleInvalidOptions($input) { * * @return array */ - public function dataInvalidTypeNotArray() { + public static function dataInvalidTypeNotArray() { return TypeProviderHelper::getAllExcept(TypeProviderHelper::GROUP_ARRAY); } diff --git a/tests/Requests/SetCertificatePathTest.php b/tests/Requests/SetCertificatePathTest.php index 80138b1ac..bdf07b310 100644 --- a/tests/Requests/SetCertificatePathTest.php +++ b/tests/Requests/SetCertificatePathTest.php @@ -35,7 +35,7 @@ public function testInvalidData($input) { * * @return array */ - public function dataInvalidData() { + public static function dataInvalidData() { return TypeProviderHelper::getAllExcept(TypeProviderHelper::GROUP_BOOL, TypeProviderHelper::GROUP_STRINGABLE); } @@ -59,7 +59,7 @@ public function testValidData($input) { * * @return array */ - public function dataValidData() { + public static function dataValidData() { return [ 'boolean false' => [false], 'boolean true' => [true], diff --git a/tests/Response/DecodeBodyTest.php b/tests/Response/DecodeBodyTest.php index 0422a13aa..e76f739be 100644 --- a/tests/Response/DecodeBodyTest.php +++ b/tests/Response/DecodeBodyTest.php @@ -37,7 +37,7 @@ public function testInvalidJsonResponse($body) { * * @return array */ - public function dataInvalidJsonResponse() { + public static function dataInvalidJsonResponse() { $data = [ 'text string, not JSON (syntax error)' => ['Invalid JSON'], 'invalid JSON: single quotes (syntax error)' => ["{ 'bar': 'baz' }"], diff --git a/tests/Response/Headers/ArrayAccessTest.php b/tests/Response/Headers/ArrayAccessTest.php index 183d62a3d..760d607b5 100644 --- a/tests/Response/Headers/ArrayAccessTest.php +++ b/tests/Response/Headers/ArrayAccessTest.php @@ -50,7 +50,7 @@ public function testCaseInsensitiveArrayAccess($key) { * * @return array */ - public function dataCaseInsensitiveArrayAccess() { + public static function dataCaseInsensitiveArrayAccess() { return [ 'access using case as set' => ['Content-Type'], 'access using lowercase' => ['content-type'], @@ -104,7 +104,7 @@ public function testOffsetSetDoesNotTryToLowercaseNonStringKeys($key, $request_k * * @return array */ - public function dataOffsetSetDoesNotTryToLowercaseNonStringKeys() { + public static function dataOffsetSetDoesNotTryToLowercaseNonStringKeys() { return [ 'integer key' => [10], 'boolean false key' => [false, 0], @@ -150,7 +150,7 @@ public function testOffsetGetReturnsNullForNonRegisteredHeader($key) { * * @return array */ - public function dataOffsetGetReturnsNullForNonRegisteredHeader() { + public static function dataOffsetGetReturnsNullForNonRegisteredHeader() { return [ // This test case also tests that no "passing null to non-nullable" deprecation is thrown in PHP 8.1. 'null' => [null], diff --git a/tests/Response/Headers/FlattenTest.php b/tests/Response/Headers/FlattenTest.php index 5a9fc0c68..37fded5aa 100644 --- a/tests/Response/Headers/FlattenTest.php +++ b/tests/Response/Headers/FlattenTest.php @@ -32,7 +32,7 @@ public function testFlatten($input, $expected) { * * @return array */ - public function dataFlatten() { + public static function dataFlatten() { return [ 'string' => ['text', 'text'], 'empty array' => [[], ''], @@ -62,7 +62,7 @@ public function testInvalidValue($input) { * * @return array */ - public function dataInvalidValue() { + public static function dataInvalidValue() { return TypeProviderHelper::getAllExcept(TypeProviderHelper::GROUP_STRING, TypeProviderHelper::GROUP_ARRAY); } } diff --git a/tests/Response/Headers/GetValuesTest.php b/tests/Response/Headers/GetValuesTest.php index 18b450a3f..43e76655a 100644 --- a/tests/Response/Headers/GetValuesTest.php +++ b/tests/Response/Headers/GetValuesTest.php @@ -34,7 +34,7 @@ public function testInvalidOffset($key) { * * @return array */ - public function dataInvalidOffset() { + public static function dataInvalidOffset() { return TypeProviderHelper::getAllExcept(TypeProviderHelper::GROUP_STRING, TypeProviderHelper::GROUP_INT); } @@ -63,7 +63,7 @@ public function testGetValues($key, $expected) { * * @return array */ - public function dataGetValues() { + public static function dataGetValues() { return [ 'using case as set, single entry header' => [ 'key' => 'Content-Type', diff --git a/tests/Response/IsRedirectTest.php b/tests/Response/IsRedirectTest.php index 53df1a99a..58c69e4e0 100644 --- a/tests/Response/IsRedirectTest.php +++ b/tests/Response/IsRedirectTest.php @@ -32,7 +32,7 @@ public function testIsRedirect($code) { * * @return array */ - public function dataIsRedirect() { + public static function dataIsRedirect() { $data = []; $codes = [300, 301, 302, 303]; @@ -69,7 +69,7 @@ public function testNotRedirect($code) { * * @return array */ - public function dataNotRedirect() { + public static function dataNotRedirect() { $data = []; $data['Non-blocking request: status code: false (default value)'] = [false]; diff --git a/tests/Session/ConstructorTest.php b/tests/Session/ConstructorTest.php index 7e8b24101..ee3cdf412 100644 --- a/tests/Session/ConstructorTest.php +++ b/tests/Session/ConstructorTest.php @@ -34,7 +34,7 @@ public function testInvalidUrl($input) { * * @return array */ - public function dataInvalidUrl() { + public static function dataInvalidUrl() { return TypeProviderHelper::getAllExcept(TypeProviderHelper::GROUP_NULL, TypeProviderHelper::GROUP_STRINGABLE); } @@ -91,7 +91,7 @@ public function testInvalidOptions($input) { * * @return array */ - public function dataInvalidTypeNotArray() { + public static function dataInvalidTypeNotArray() { return TypeProviderHelper::getAllExcept(TypeProviderHelper::GROUP_ARRAY); } diff --git a/tests/Session/RequestMultipleTest.php b/tests/Session/RequestMultipleTest.php index b86df3c90..5501afd3f 100644 --- a/tests/Session/RequestMultipleTest.php +++ b/tests/Session/RequestMultipleTest.php @@ -35,7 +35,7 @@ public function testInvalidRequests($input) { * * @return array */ - public function dataInvalidRequests() { + public static function dataInvalidRequests() { $except = array_intersect(TypeProviderHelper::GROUP_ITERABLE, TypeProviderHelper::GROUP_ARRAY_ACCESSIBLE); return TypeProviderHelper::getAllExcept($except); } @@ -62,7 +62,7 @@ public function testInvalidOptions($input) { * * @return array */ - public function dataInvalidOptions() { + public static function dataInvalidOptions() { return TypeProviderHelper::getAllExcept(TypeProviderHelper::GROUP_ARRAY); } diff --git a/tests/Ssl/MatchDomainTest.php b/tests/Ssl/MatchDomainTest.php index f8c19cb57..64823d8a1 100644 --- a/tests/Ssl/MatchDomainTest.php +++ b/tests/Ssl/MatchDomainTest.php @@ -33,7 +33,7 @@ public function testInvalidInputType($input) { * * @return array */ - public function dataInvalidInputType() { + public static function dataInvalidInputType() { return TypeProviderHelper::getAllExcept(TypeProviderHelper::GROUP_STRINGABLE); } diff --git a/tests/Ssl/SslTestCase.php b/tests/Ssl/SslTestCase.php index 68b283127..a08b16e3b 100644 --- a/tests/Ssl/SslTestCase.php +++ b/tests/Ssl/SslTestCase.php @@ -44,7 +44,7 @@ protected function fakeCertificate($dnsname, $with_san = true) { * * @return array */ - public function dataMatch() { + public static function dataMatch() { return [ 'top-level domain (stringable object)' => [ 'host' => new StringableObject('example.com'), @@ -66,7 +66,7 @@ public function dataMatch() { * * @return array */ - public function dataNoMatch() { + public static function dataNoMatch() { return [ // Check that we need at least 3 components. 'not a domain; wildcard reference' => [ diff --git a/tests/Ssl/VerifyCertificateTest.php b/tests/Ssl/VerifyCertificateTest.php index b49a66e9d..1afcf474c 100644 --- a/tests/Ssl/VerifyCertificateTest.php +++ b/tests/Ssl/VerifyCertificateTest.php @@ -33,7 +33,7 @@ public function testInvalidInputHost($input) { * * @return array */ - public function dataInvalidInputHost() { + public static function dataInvalidInputHost() { return TypeProviderHelper::getAllExcept(TypeProviderHelper::GROUP_STRINGABLE); } @@ -58,7 +58,7 @@ public function testInvalidInputCert($input) { * * @return array */ - public function dataInvalidInputCert() { + public static function dataInvalidInputCert() { return TypeProviderHelper::getAllExcept(TypeProviderHelper::GROUP_ARRAY_ACCESSIBLE); } @@ -87,7 +87,7 @@ public function testMatchViaCertificate($host, $reference, $with_san = true) { * * @return array */ - public function dataMatchViaCertificate() { + public static function dataMatchViaCertificate() { return [ 'top-level domain; missing SAN, fallback to CN' => [ 'host' => 'example.com', @@ -142,7 +142,7 @@ public function testNoMatchViaCertificate($host, $reference, $with_san = true) { * * @return array */ - public function dataNoMatchViaCertificate() { + public static function dataNoMatchViaCertificate() { return [ 'top-level domain; missing SAN, fallback to invalid CN' => [ 'host' => 'example.net', @@ -207,7 +207,7 @@ public function testWithInvalidCertificates($host, $certificate, $expected) { * * @return array */ - public function dataWithInvalidCertificates() { + public static function dataWithInvalidCertificates() { return [ 'empty array' => [ 'host' => 'example.com', diff --git a/tests/Ssl/VerifyReferenceNameTest.php b/tests/Ssl/VerifyReferenceNameTest.php index 32cb7d786..87dca1b18 100644 --- a/tests/Ssl/VerifyReferenceNameTest.php +++ b/tests/Ssl/VerifyReferenceNameTest.php @@ -34,7 +34,7 @@ public function testInvalidInputType($input) { * * @return array */ - public function dataInvalidInputType() { + public static function dataInvalidInputType() { return TypeProviderHelper::getAllExcept(TypeProviderHelper::GROUP_STRINGABLE); } @@ -57,7 +57,7 @@ public function testVerifyReferenceName($reference, $expected) { * * @return array */ - public function dataVerifyReferenceName() { + public static function dataVerifyReferenceName() { return [ 'empty string' => [ 'reference' => '', diff --git a/tests/Transport/BaseTestCase.php b/tests/Transport/BaseTestCase.php index bc33ead9b..bcc557e98 100644 --- a/tests/Transport/BaseTestCase.php +++ b/tests/Transport/BaseTestCase.php @@ -220,7 +220,7 @@ public function testRequestInvalidUrl($input) { * * @return array */ - public function dataRequestInvalidUrl() { + public static function dataRequestInvalidUrl() { return TypeProviderHelper::getAllExcept(TypeProviderHelper::GROUP_STRINGABLE); } @@ -278,7 +278,7 @@ public function testIncorrectDataTypeAcceptedPOST($data, $expected) { * * @return array */ - public function dataIncorrectDataTypeAccepted() { + public static function dataIncorrectDataTypeAccepted() { return [ 'null' => [null, ''], ]; @@ -309,7 +309,7 @@ public function testRequestInvalidData($input) { * * @return array */ - public function dataIncorrectDataTypeException() { + public static function dataIncorrectDataTypeException() { return TypeProviderHelper::getAllExcept( TypeProviderHelper::GROUP_NULL, TypeProviderHelper::GROUP_STRING, @@ -359,7 +359,7 @@ public function testRequestMultipleReturnsEmptyArrayWhenRequestsIsEmpty($input) * * @return array */ - public function dataRequestMultipleReturnsEmptyArrayWhenRequestsIsEmpty() { + public static function dataRequestMultipleReturnsEmptyArrayWhenRequestsIsEmpty() { return TypeProviderHelper::getSelection(TypeProviderHelper::GROUP_EMPTY); } @@ -388,7 +388,7 @@ public function testRequestMultipleInvalidRequests($input) { * * @return array */ - public function dataRequestMultipleInvalidRequests() { + public static function dataRequestMultipleInvalidRequests() { $except = array_intersect(TypeProviderHelper::GROUP_ITERABLE, TypeProviderHelper::GROUP_ARRAY_ACCESSIBLE); return TypeProviderHelper::getAllExcept($except, TypeProviderHelper::GROUP_EMPTY); } @@ -418,7 +418,7 @@ public function testRequestMultipleInvalidOptions($input) { * * @return array */ - public function dataInvalidTypeNotArray() { + public static function dataInvalidTypeNotArray() { return TypeProviderHelper::getAllExcept(TypeProviderHelper::GROUP_ARRAY); } @@ -917,7 +917,7 @@ public function testSNISupport($options) { * * @return array */ - public function dataSNISupport() { + public static function dataSNISupport() { return [ 'Without options' => [ 'options' => [], diff --git a/tests/Utility/CaseInsensitiveDictionary/ArrayAccessTest.php b/tests/Utility/CaseInsensitiveDictionary/ArrayAccessTest.php index 69abc359e..211bf6b47 100644 --- a/tests/Utility/CaseInsensitiveDictionary/ArrayAccessTest.php +++ b/tests/Utility/CaseInsensitiveDictionary/ArrayAccessTest.php @@ -116,7 +116,7 @@ public function testAccessValidEntries($key, $value) { * * @return array */ - public function dataAccessValidEntries() { + public static function dataAccessValidEntries() { $data = []; foreach (self::DATASET_REVERSED as $key => $value) { @@ -171,7 +171,7 @@ public function testAccessInvalidEntry($key) { * * @return array */ - public function dataAccessInvalidEntry() { + public static function dataAccessInvalidEntry() { return [ 'string key' => ['Non-existant entry'], 'integer key' => [25], diff --git a/tests/Utility/FilteredIterator/ConstructorTest.php b/tests/Utility/FilteredIterator/ConstructorTest.php index fb1bf52bb..a7446eee5 100644 --- a/tests/Utility/FilteredIterator/ConstructorTest.php +++ b/tests/Utility/FilteredIterator/ConstructorTest.php @@ -32,7 +32,7 @@ public function testValidData($input) { * * @return array */ - public function dataValidData() { + public static function dataValidData() { return TypeProviderHelper::getSelection(TypeProviderHelper::GROUP_ITERABLE); } @@ -57,7 +57,7 @@ public function testInvalidData($input) { * * @return array */ - public function dataInvalidData() { + public static function dataInvalidData() { return TypeProviderHelper::getAllExcept(TypeProviderHelper::GROUP_ITERABLE); } @@ -87,10 +87,10 @@ public function testValidCallback($input) { * * @return array */ - public function dataValidCallback() { + public static function dataValidCallback() { return [ 'existing PHP native function' => ['strtolower'], - 'dummy callback method' => [[$this, 'dummyCallback']], + 'dummy callback method' => [[__CLASS__, 'dummyCallback']], ]; } @@ -120,7 +120,7 @@ public function testInvalidCallback($input) { * * @return array */ - public function dataInvalidCallback() { + public static function dataInvalidCallback() { return [ 'null' => [null], 'non-existent function' => ['functionname'], @@ -133,5 +133,5 @@ public function dataInvalidCallback() { * * @return void */ - public function dummyCallback() {} + public static function dummyCallback() {} } diff --git a/tests/Utility/FilteredIterator/CurrentTest.php b/tests/Utility/FilteredIterator/CurrentTest.php index 76f87627e..f70f1a74e 100644 --- a/tests/Utility/FilteredIterator/CurrentTest.php +++ b/tests/Utility/FilteredIterator/CurrentTest.php @@ -37,7 +37,7 @@ public function testCallbackIsAppliedIfValid($data, $callback, $expected) { * * @return array */ - public function dataCallbackIsAppliedIfValid() { + public static function dataCallbackIsAppliedIfValid() { $original = [ 'key1' => 'lowercase', 'key2' => 'UPPER CASE', diff --git a/tests/Utility/FilteredIterator/SerializationTest.php b/tests/Utility/FilteredIterator/SerializationTest.php index 478bd52ab..f16969993 100644 --- a/tests/Utility/FilteredIterator/SerializationTest.php +++ b/tests/Utility/FilteredIterator/SerializationTest.php @@ -47,7 +47,7 @@ public function testSerializeDeserializeObjects($value) { * * @return array */ - public function dataSerializeDeserializeObjects() { + public static function dataSerializeDeserializeObjects() { return [ 'FilteredIterator object with one value, callback: md5' => [ 'value' => new FilteredIterator([1], 'md5'), diff --git a/tests/Utility/InputValidator/HasArrayAccessTest.php b/tests/Utility/InputValidator/HasArrayAccessTest.php index 466efc3ee..dcd3ae890 100644 --- a/tests/Utility/InputValidator/HasArrayAccessTest.php +++ b/tests/Utility/InputValidator/HasArrayAccessTest.php @@ -29,7 +29,7 @@ public function testValid($input) { * * @return array */ - public function dataValid() { + public static function dataValid() { return TypeProviderHelper::getSelection(TypeProviderHelper::GROUP_ARRAY_ACCESSIBLE); } @@ -51,7 +51,7 @@ public function testInvalid($input) { * * @return array */ - public function dataInvalid() { + public static function dataInvalid() { return TypeProviderHelper::getAllExcept(TypeProviderHelper::GROUP_ARRAY_ACCESSIBLE); } } diff --git a/tests/Utility/InputValidator/IsCurlHandleTest.php b/tests/Utility/InputValidator/IsCurlHandleTest.php index d7ce1bf0f..5e42e146e 100644 --- a/tests/Utility/InputValidator/IsCurlHandleTest.php +++ b/tests/Utility/InputValidator/IsCurlHandleTest.php @@ -47,7 +47,7 @@ public function testValid($input) { * * @return array */ - public function dataValid() { + public static function dataValid() { if (isset(self::$curl_handle) === false) { self::$curl_handle = curl_init('http://httpbin.org/anything'); } @@ -75,7 +75,7 @@ public function testInvalid($input) { * * @return array */ - public function dataInvalid() { + public static function dataInvalid() { return TypeProviderHelper::getAll(); } } diff --git a/tests/Utility/InputValidator/IsIterableTest.php b/tests/Utility/InputValidator/IsIterableTest.php index e3b5a2e66..f55eaaf1e 100644 --- a/tests/Utility/InputValidator/IsIterableTest.php +++ b/tests/Utility/InputValidator/IsIterableTest.php @@ -29,7 +29,7 @@ public function testValid($input) { * * @return array */ - public function dataValid() { + public static function dataValid() { return TypeProviderHelper::getSelection(TypeProviderHelper::GROUP_ITERABLE); } @@ -51,7 +51,7 @@ public function testInvalid($input) { * * @return array */ - public function dataInvalid() { + public static function dataInvalid() { return TypeProviderHelper::getAllExcept(TypeProviderHelper::GROUP_ITERABLE); } } diff --git a/tests/Utility/InputValidator/IsNumericArrayKeyTest.php b/tests/Utility/InputValidator/IsNumericArrayKeyTest.php index 4f0dbbc3f..096d6994d 100644 --- a/tests/Utility/InputValidator/IsNumericArrayKeyTest.php +++ b/tests/Utility/InputValidator/IsNumericArrayKeyTest.php @@ -29,7 +29,7 @@ public function testValid($input) { * * @return array */ - public function dataValid() { + public static function dataValid() { return TypeProviderHelper::getSelection(TypeProviderHelper::GROUP_INT, ['numeric string']); } @@ -51,7 +51,7 @@ public function testInvalid($input) { * * @return array */ - public function dataInvalid() { + public static function dataInvalid() { return TypeProviderHelper::getAllExcept(TypeProviderHelper::GROUP_INT, ['numeric string']); } } diff --git a/tests/Utility/InputValidator/IsStringOrStringableTest.php b/tests/Utility/InputValidator/IsStringOrStringableTest.php index c08c10812..5f47cc17e 100644 --- a/tests/Utility/InputValidator/IsStringOrStringableTest.php +++ b/tests/Utility/InputValidator/IsStringOrStringableTest.php @@ -29,7 +29,7 @@ public function testValid($input) { * * @return array */ - public function dataValid() { + public static function dataValid() { return TypeProviderHelper::getSelection(TypeProviderHelper::GROUP_STRINGABLE); } @@ -51,7 +51,7 @@ public function testInvalid($input) { * * @return array */ - public function dataInvalid() { + public static function dataInvalid() { return TypeProviderHelper::getAllExcept(TypeProviderHelper::GROUP_STRINGABLE); } } diff --git a/tests/Utility/InputValidator/IsStringableObjectTest.php b/tests/Utility/InputValidator/IsStringableObjectTest.php index c02dcfaf9..211d0f9e4 100644 --- a/tests/Utility/InputValidator/IsStringableObjectTest.php +++ b/tests/Utility/InputValidator/IsStringableObjectTest.php @@ -29,7 +29,7 @@ public function testValid($input) { * * @return array */ - public function dataValid() { + public static function dataValid() { return TypeProviderHelper::getSelection(['Stringable object']); } @@ -51,7 +51,7 @@ public function testInvalid($input) { * * @return array */ - public function dataInvalid() { + public static function dataInvalid() { return TypeProviderHelper::getAllExcept(['Stringable object']); } } From c03629d02336804549c9b5f172abd68868e587d4 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Mon, 26 Jun 2023 13:24:36 +0200 Subject: [PATCH 07/12] Tests: replace `assertObjectHasAttribute()` with `assertObjectHasProperty()` The `assertObjectHasAttribute()` method has been deprecated in PHPUnit 9 and removed in PHPUnit 10. PHPUnit 10.1 introduces a replacement `assertObjectHasProperty()` method, which is polyfilled by the PHPUnit Polyfills. This switches all uses of the old method to the new method name. --- tests/Auth/Basic/BasicTest.php | 18 +++++++++--------- tests/Transport/BaseTestCase.php | 4 ++-- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/tests/Auth/Basic/BasicTest.php b/tests/Auth/Basic/BasicTest.php index 1ca8ee117..34f914f7d 100644 --- a/tests/Auth/Basic/BasicTest.php +++ b/tests/Auth/Basic/BasicTest.php @@ -44,14 +44,14 @@ public function testUsingArray($transport) { $result = json_decode($request->body); $this->assertIsObject($result, 'Decoded response body is not an object'); - $this->assertObjectHasAttribute( + $this->assertObjectHasProperty( 'authenticated', $result, 'Property "authenticated" not available in decoded response' ); $this->assertTrue($result->authenticated, 'Authentication failed'); - $this->assertObjectHasAttribute( + $this->assertObjectHasProperty( 'user', $result, 'Property "user" not available in decoded response' @@ -91,14 +91,14 @@ public function testUsingInstantiation($transport) { $result = json_decode($request->body); $this->assertIsObject($result, 'Decoded response body is not an object'); - $this->assertObjectHasAttribute( + $this->assertObjectHasProperty( 'authenticated', $result, 'Property "authenticated" not available in decoded response' ); $this->assertTrue($result->authenticated, 'Authentication failed'); - $this->assertObjectHasAttribute( + $this->assertObjectHasProperty( 'user', $result, 'Property "user" not available in decoded response' @@ -141,14 +141,14 @@ public function testUsingInstantiationWithDelayedSettingOfCredentials($transport $result = json_decode($request->body); $this->assertIsObject($result, 'Decoded response body is not an object'); - $this->assertObjectHasAttribute( + $this->assertObjectHasProperty( 'authenticated', $result, 'Property "authenticated" not available in decoded response' ); $this->assertTrue($result->authenticated, 'Authentication failed'); - $this->assertObjectHasAttribute( + $this->assertObjectHasProperty( 'user', $result, 'Property "user" not available in decoded response' @@ -189,12 +189,12 @@ public function testPOSTUsingInstantiation($transport) { $result = json_decode($request->body); $this->assertIsObject($result, 'Decoded response body is not an object'); - $this->assertObjectHasAttribute( + $this->assertObjectHasProperty( 'headers', $result, 'Property "headers" not available in decoded response' ); - $this->assertObjectHasAttribute( + $this->assertObjectHasProperty( 'Authorization', $result->headers, 'Property "headers->Authorization" not available in decoded response' @@ -205,7 +205,7 @@ public function testPOSTUsingInstantiation($transport) { $this->assertArrayHasKey(1, $auth, 'Authorization header failed to be split into two parts'); $this->assertSame(base64_encode('user:passwd'), $auth[1], 'Unexpected authorization string in headers'); - $this->assertObjectHasAttribute( + $this->assertObjectHasProperty( 'data', $result, 'Property "data" not available in decoded response' diff --git a/tests/Transport/BaseTestCase.php b/tests/Transport/BaseTestCase.php index bcc557e98..10e43e617 100644 --- a/tests/Transport/BaseTestCase.php +++ b/tests/Transport/BaseTestCase.php @@ -262,10 +262,10 @@ public function testRequestInvalidHeaders($input) { public function testIncorrectDataTypeAcceptedPOST($data, $expected) { $request = Requests::post($this->httpbin('/post'), [], $data, $this->getOptions()); $this->assertIsObject($request, 'POST request did not return an object'); - $this->assertObjectHasAttribute('status_code', $request, 'POST request object does not have a "status_code" property'); + $this->assertObjectHasProperty('status_code', $request, 'POST request object does not have a "status_code" property'); $this->assertSame(200, $request->status_code, 'POST request status code is not 200'); - $this->assertObjectHasAttribute('body', $request, 'POST request object does not have a "body" property'); + $this->assertObjectHasProperty('body', $request, 'POST request object does not have a "body" property'); $result = json_decode($request->body, true); $this->assertIsArray($result, 'Json decoded POST request body is not an array'); From 38c1847e9a5e35ae403283b3a8aa1fb06b7c068e Mon Sep 17 00:00:00 2001 From: jrfnl Date: Mon, 26 Jun 2023 11:11:26 +0200 Subject: [PATCH 08/12] Tests: work around for `MockBuilder::setMethods()` removal Please note: * The `getMockBuilder()` method is also deprecated now, so replacing with another method call on the `MockBuilder` class will only work in the short/medium term and in a future iteration, this will have to be refactored again. * The `addMethods()` method has been (soft) deprecated in PHPUnit 10.1 and is expected to be removed in PHPUnit 12. Also see 814 Refs: * sebastianbergmann/phpunit 3687#issuecomment-492537584 * sebastianbergmann/phpunit 3770 * sebastianbergmann/phpunit 3769 * sebastianbergmann/phpunit 4775 --- tests/Hooks/DispatchTest.php | 9 ++------- tests/TestCase.php | 29 +++++++++++++++++++++++++++++ tests/Transport/BaseTestCase.php | 7 ++----- 3 files changed, 33 insertions(+), 12 deletions(-) diff --git a/tests/Hooks/DispatchTest.php b/tests/Hooks/DispatchTest.php index 4de29a529..0b28ab08e 100644 --- a/tests/Hooks/DispatchTest.php +++ b/tests/Hooks/DispatchTest.php @@ -2,7 +2,6 @@ namespace WpOrg\Requests\Tests\Hooks; -use stdClass; use WpOrg\Requests\Exception\InvalidArgument; use WpOrg\Requests\Hooks; use WpOrg\Requests\Tests\TestCase; @@ -181,9 +180,7 @@ static function(&$text) { * @return void */ public function testDispatchWithSingleRegisteredHook() { - $mock = $this->getMockBuilder(stdClass::class) - ->setMethods(['callback']) - ->getMock(); + $mock = $this->getMockedStdClassWithMethods(['callback']); $mock->expects($this->once()) ->method('callback'); @@ -199,9 +196,7 @@ public function testDispatchWithSingleRegisteredHook() { * @return void */ public function testDispatchWithMultipleRegisteredHooks() { - $mock = $this->getMockBuilder(stdClass::class) - ->setMethods(['callback_a', 'callback_b', 'callback_c']) - ->getMock(); + $mock = $this->getMockedStdClassWithMethods(['callback_a', 'callback_b', 'callback_c']); $mock->expects($this->never()) ->method('callback_a'); diff --git a/tests/TestCase.php b/tests/TestCase.php index 148b3a786..eb188596c 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -3,6 +3,7 @@ namespace WpOrg\Requests\Tests; use Exception; +use stdClass; use WpOrg\Requests\Requests; use WpOrg\Requests\Tests\TypeProviderHelper; use Yoast\PHPUnitPolyfills\TestCases\TestCase as Polyfill_TestCase; @@ -124,4 +125,32 @@ public static function textArrayToDataprovider($input) { return $data; } + + /** + * Helper method to retrieve a mock object based on stdClass with select methods mocked. + * + * The `setMethods()` method was silently deprecated in PHPUnit 8.3 and removed in PHPUnit 10. + * + * Note: the `getMockBuilder()` and `addMethods()` methods are also soft deprecated as of + * PHPUnit 10.x, and are expected to be hard deprecated in PHPUnit 11 and removed in PHPUnit 12. + * Dealing with that is something for a later iteration of the test suite. + * {@link https://github.com/WordPress/Requests/issues/814} + * + * @param array $methods The names of the methods to mock. + * + * @return \PHPUnit\Framework\MockObject\MockObject + */ + protected function getMockedStdClassWithMethods($methods) { + $mock = $this->getMockBuilder(stdClass::class); + + if (\method_exists($mock, 'addMethods')) { + // PHPUnit 8.3.0+. + return $mock->addMethods($methods) + ->getMock(); + } + + // PHPUnit < 8.3.0. + return $mock->setMethods($methods) + ->getMock(); + } } diff --git a/tests/Transport/BaseTestCase.php b/tests/Transport/BaseTestCase.php index 10e43e617..84bb46ecf 100644 --- a/tests/Transport/BaseTestCase.php +++ b/tests/Transport/BaseTestCase.php @@ -2,7 +2,6 @@ namespace WpOrg\Requests\Tests\Transport; -use stdClass; use WpOrg\Requests\Capability; use WpOrg\Requests\Exception; use WpOrg\Requests\Exception\Http\StatusUnknown; @@ -1117,7 +1116,7 @@ public function testAlternatePort() { } public function testProgressCallback() { - $mock = $this->getMockBuilder(stdClass::class)->setMethods(['progress'])->getMock(); + $mock = $this->getMockedStdClassWithMethods(['progress']); $mock->expects($this->atLeastOnce())->method('progress'); $hooks = new Hooks(); $hooks->register('request.progress', [$mock, 'progress']); @@ -1130,9 +1129,7 @@ public function testProgressCallback() { } public function testAfterRequestCallback() { - $mock = $this->getMockBuilder(stdClass::class) - ->setMethods(['after_request']) - ->getMock(); + $mock = $this->getMockedStdClassWithMethods(['after_request']); $mock->expects($this->atLeastOnce()) ->method('after_request') From 4f3550a7287394ed9b00399d5d2904bd17a5cce6 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Mon, 26 Jun 2023 11:38:56 +0200 Subject: [PATCH 09/12] Tests: work around for removal of expectDeprecation et al PHPUnit will no longer stop a test on deprecations/notices/warnings. This also means that the PHPUnit native way to expect deprecations/notices/warnings etc is no longer supported. This implements a work-around for the limited cases in which that functionality was used in this test suite. Refs: * https://phpunit.de/announcements/phpunit-10.html * sebastianbergmann/phpunit 5062 --- .phpcs.xml.dist | 5 +++++ tests/Autoload/AutoloadTest.php | 27 +++++++++++++++++++++++---- tests/Iri/IriTest.php | 14 +++++++++++++- 3 files changed, 41 insertions(+), 5 deletions(-) diff --git a/.phpcs.xml.dist b/.phpcs.xml.dist index 985ccd146..2be1b2317 100644 --- a/.phpcs.xml.dist +++ b/.phpcs.xml.dist @@ -247,4 +247,9 @@ /tests/*\.php$ + + + /tests/*\.php$ + + diff --git a/tests/Autoload/AutoloadTest.php b/tests/Autoload/AutoloadTest.php index c9acb2a6b..e9876bf04 100644 --- a/tests/Autoload/AutoloadTest.php +++ b/tests/Autoload/AutoloadTest.php @@ -2,6 +2,7 @@ namespace WpOrg\Requests\Tests\Autoload; +use Exception; use Requests; use Requests_Exception_Transport_cURL; use Requests_Utility_FilteredIterator; @@ -21,8 +22,17 @@ final class AutoloadTest extends TestCase { * Verify that a deprecation notice is thrown when the "old" Requests class is loaded via a require/include. */ public function testDeprecationNoticeThrownForOldRequestsClass() { - $this->expectDeprecation(); - $this->expectDeprecationMessage(self::MSG); + // PHPUnit 10 compatible way to test the deprecation notice. + set_error_handler( + static function ($errno, $errstr) { + restore_error_handler(); + throw new Exception($errstr, $errno); + }, + E_USER_DEPRECATED + ); + + $this->expectException(Exception::class); + $this->expectExceptionMessage(self::MSG); require_once dirname(dirname(__DIR__)) . '/library/Requests.php'; } @@ -31,8 +41,17 @@ public function testDeprecationNoticeThrownForOldRequestsClass() { * Verify that a deprecation notice is thrown when one of the other "old" Requests classes is autoloaded. */ public function testDeprecationNoticeThrownForOtherOldRequestsClass() { - $this->expectDeprecation(); - $this->expectDeprecationMessage(self::MSG); + // PHPUnit 10 compatible way to test the deprecation notice. + set_error_handler( + static function ($errno, $errstr) { + restore_error_handler(); + throw new Exception($errstr, $errno); + }, + E_USER_DEPRECATED + ); + + $this->expectException(Exception::class); + $this->expectExceptionMessage(self::MSG); $this->assertNotEmpty(Requests_Exception_Transport_cURL::EASY); } diff --git a/tests/Iri/IriTest.php b/tests/Iri/IriTest.php index 1017eb96c..a763fb08c 100644 --- a/tests/Iri/IriTest.php +++ b/tests/Iri/IriTest.php @@ -42,6 +42,7 @@ namespace WpOrg\Requests\Tests\Iri; +use Exception; use WpOrg\Requests\Iri; use WpOrg\Requests\Tests\TestCase; @@ -391,7 +392,18 @@ public function testWriteAliased() public function testNonexistantProperty() { - $this->expectNotice('Undefined property: WpOrg\Requests\Iri::nonexistant_prop'); + // PHPUnit 10 compatible way to test the notice. + set_error_handler( + static function ($errno, $errstr) { + restore_error_handler(); + throw new Exception($errstr, $errno); + }, + E_USER_NOTICE + ); + + $this->expectException(Exception::class); + $this->expectExceptionMessage('Undefined property: WpOrg\Requests\Iri::nonexistant_prop'); + $iri = new Iri(); $this->assertFalse(isset($iri->nonexistant_prop)); $should_fail = $iri->nonexistant_prop; From 5bbef6dc6d3029722af738a4876b0daec7ac96db Mon Sep 17 00:00:00 2001 From: jrfnl Date: Mon, 26 Jun 2023 14:05:53 +0200 Subject: [PATCH 10/12] Curl/Fsockopen: add some extra defensive coding The `error_get_last()` function can return `null` if no error occurred, in which case, the `throw new Exception()` statement will run into two new errors: * `Trying to access array offset on value of type null` for accessing `$error['message']`. * ... which then leads to a `Exception::__construct(): Passing null to parameter #1 ($message) of type string is deprecated`. This commit adds some defensive coding to handle the hypothetical situation that `error_get_last()` would return `null` when a file could not be opened. Note: this is actually a bug in PHPUnit 10 which breaks `error_get_last()`. We should be able to remove the extra defensive coding once the upstream bug has been fixed. Upstream bug report: https://github.com/sebastianbergmann/phpunit/issues/5428 --- src/Transport/Curl.php | 5 +++++ src/Transport/Fsockopen.php | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/src/Transport/Curl.php b/src/Transport/Curl.php index 0b3794808..3995197f4 100644 --- a/src/Transport/Curl.php +++ b/src/Transport/Curl.php @@ -177,6 +177,11 @@ public function request($url, $headers = [], $data = [], $options = []) { $this->stream_handle = @fopen($options['filename'], 'wb'); if ($this->stream_handle === false) { $error = error_get_last(); + if (!is_array($error)) { + // Shouldn't be possible, but can happen in test situations. + $error = ['message' => 'Failed to open stream']; + } + throw new Exception($error['message'], 'fopen'); } } diff --git a/src/Transport/Fsockopen.php b/src/Transport/Fsockopen.php index 97a1f7373..15a5ba9b0 100644 --- a/src/Transport/Fsockopen.php +++ b/src/Transport/Fsockopen.php @@ -282,6 +282,11 @@ public function request($url, $headers = [], $data = [], $options = []) { $download = @fopen($options['filename'], 'wb'); if ($download === false) { $error = error_get_last(); + if (!is_array($error)) { + // Shouldn't be possible, but can happen in test situations. + $error = ['message' => 'Failed to open stream']; + } + throw new Exception($error['message'], 'fopen'); } } From 2c43c17efd3303aafcdcba470508a5e565c6e0e3 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Mon, 26 Jun 2023 13:01:26 +0200 Subject: [PATCH 11/12] PHPUnit: add separate configuration for PHPUnit 10 PHPUnit 10 makes significant changes to the configuration file. Most notably: * In PHPUnit 9.3, the manner of specifying the code coverage configuration has changed. * In PHPUnit 10.0, a significant number of attributes of the `` element were removed or renamed. * In PHPUnit 10.1, the manner of specifying code coverage has changed again. While there is a `--migrate-configuration` option available in PHPUnit, that doesn't get us a well enough converted configuration file, so instead use a separate `phpunit10.xml.dist` file for running the tests on PHPUnit 10 with an optimal configuration. Includes: * Ignoring the new file for package archives. * Adding separate scripts to the `composer.json` file to make how to run the tests on PHPUnit 10 more obvious for contributors. * Updating the GH Actions workflows to take the new configuration file into account when appropriate. --- .gitattributes | 1 + .github/workflows/quicktest.yml | 12 ++++++++--- .github/workflows/test.yml | 23 ++++++++++++++------- composer.json | 6 ++++++ phpunit.xml.dist | 1 + phpunit10.xml.dist | 36 +++++++++++++++++++++++++++++++++ 6 files changed, 69 insertions(+), 10 deletions(-) create mode 100644 phpunit10.xml.dist diff --git a/.gitattributes b/.gitattributes index 62575cea0..65c0a70bc 100644 --- a/.gitattributes +++ b/.gitattributes @@ -9,3 +9,4 @@ tests/ export-ignore .phpcs.xml.dist export-ignore phpdoc.dist.xml export-ignore phpunit.xml.dist export-ignore +phpunit10.xml.dist export-ignore diff --git a/.github/workflows/quicktest.yml b/.github/workflows/quicktest.yml index a0305edbc..5190e33e4 100644 --- a/.github/workflows/quicktest.yml +++ b/.github/workflows/quicktest.yml @@ -90,12 +90,18 @@ jobs: - name: Access localhost on port 9002 run: curl -i http://localhost:9002 - - name: Show PHPUnit version - run: vendor/bin/phpunit --version + - name: Grab PHPUnit version + id: phpunit_version + run: echo "VERSION=$(vendor/bin/phpunit --version | grep --only-matching --max-count=1 --extended-regexp '\b[0-9]+\.[0-9]+')" >> $GITHUB_OUTPUT - - name: Run the unit tests + - name: Run the unit tests (PHPUnit < 10) + if: ${{ ! startsWith( steps.phpunit_version.outputs.VERSION, '10.' ) }} run: composer test + - name: Run the unit tests (PHPUnit 10+) + if: ${{ startsWith( steps.phpunit_version.outputs.VERSION, '10.' ) }} + run: composer test10 + - name: Stop proxy server continue-on-error: true run: | diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index a24c93504..93f733684 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -114,16 +114,25 @@ jobs: - name: Access localhost on port 9002 run: curl -i http://localhost:9002 - - name: Show PHPUnit version - run: vendor/bin/phpunit --version + - name: Grab PHPUnit version + id: phpunit_version + run: echo "VERSION=$(vendor/bin/phpunit --version | grep --only-matching --max-count=1 --extended-regexp '\b[0-9]+\.[0-9]+')" >> $GITHUB_OUTPUT - - name: Run the unit tests, no code coverage - if: ${{ matrix.coverage == false }} + - name: Run the unit tests, no code coverage (PHPUnit < 10) + if: ${{ matrix.coverage == false && ! startsWith( steps.phpunit_version.outputs.VERSION, '10.' ) }} run: composer test - - name: Run the unit tests with code coverage - if: ${{ matrix.coverage == true }} - run: vendor/bin/phpunit --coverage-clover clover.xml + - name: Run the unit tests, no code coverage (PHPUnit 10+) + if: ${{ matrix.coverage == false && startsWith( steps.phpunit_version.outputs.VERSION, '10.' ) }} + run: composer test10 + + - name: Run the unit tests with code coverage (PHPUnit < 10) + if: ${{ matrix.coverage == true && ! startsWith( steps.phpunit_version.outputs.VERSION, '10.' ) }} + run: composer coverage -- --coverage-clover clover.xml + + - name: Run the unit tests with code coverage (PHPUnit 10+) + if: ${{ matrix.coverage == true && startsWith( steps.phpunit_version.outputs.VERSION, '10.' ) }} + run: composer coverage10 -- --coverage-clover clover.xml - name: Stop proxy server continue-on-error: true diff --git a/composer.json b/composer.json index 79b0c3631..8e5572dc7 100644 --- a/composer.json +++ b/composer.json @@ -84,8 +84,14 @@ "test": [ "@php ./vendor/phpunit/phpunit/phpunit --no-coverage" ], + "test10": [ + "@php ./vendor/phpunit/phpunit/phpunit -c phpunit10.xml.dist --no-coverage" + ], "coverage": [ "@php ./vendor/phpunit/phpunit/phpunit" + ], + "coverage10": [ + "@php ./vendor/phpunit/phpunit/phpunit -c phpunit10.xml.dist" ] } } diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 393afcbcb..854fb0950 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -4,6 +4,7 @@ xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/7.5/phpunit.xsd" backupGlobals="true" bootstrap="tests/bootstrap.php" + beStrictAboutTestsThatDoNotTestAnything="true" convertDeprecationsToExceptions="true" colors="true" verbose="true" diff --git a/phpunit10.xml.dist b/phpunit10.xml.dist new file mode 100644 index 000000000..8826f5bfe --- /dev/null +++ b/phpunit10.xml.dist @@ -0,0 +1,36 @@ + + + + + tests + + + + + + ./src/ + + + + + + + + + From 148c25e030bf4f1f86504b0f8b9b66e06b3af4fa Mon Sep 17 00:00:00 2001 From: jrfnl Date: Mon, 24 Jul 2023 10:39:07 +0200 Subject: [PATCH 12/12] Composer: add script descriptions ... as it is now less intuitive to run the unit tests via the Composer scripts, so improve the discoverability of the different scripts by adding descriptions for each script. --- composer.json | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/composer.json b/composer.json index 8e5572dc7..ccafa9c09 100644 --- a/composer.json +++ b/composer.json @@ -93,5 +93,14 @@ "coverage10": [ "@php ./vendor/phpunit/phpunit/phpunit -c phpunit10.xml.dist" ] + }, + "scripts-descriptions": { + "lint": "Lint PHP files to find parse errors.", + "checkcs": "Check the entire codebase for code-style issues.", + "fixcs": "Fix all auto-fixable code-style issues in the entire codebase.", + "test": "Run the unit tests on PHPUnit 5.x - 9.x without code coverage.", + "test10": "Run the unit tests on PHPUnit 10.x without code coverage.", + "coverage": "Run the unit tests on PHPUnit 5.x - 9.x with code coverage.", + "coverage10": "Run the unit tests on PHPUnit 10.x with code coverage." } }