From c59e6d4af2d2cbaf38282218324b973370502280 Mon Sep 17 00:00:00 2001 From: Phil Davis Date: Mon, 6 Jan 2025 14:14:03 +0545 Subject: [PATCH 1/5] chore: update to phpstan major version 2 --- composer.json | 7 +++++-- lib/Message.php | 5 +---- lib/Sapi.php | 2 +- phpstan.neon | 8 ++++++++ tests/HTTP/Auth/AWSTest.php | 2 +- tests/HTTP/Auth/DigestTest.php | 2 +- tests/HTTP/RequestTest.php | 2 +- 7 files changed, 18 insertions(+), 10 deletions(-) diff --git a/composer.json b/composer.json index 80c9daa..d3768ad 100644 --- a/composer.json +++ b/composer.json @@ -13,8 +13,11 @@ "sabre/uri" : "^2.3" }, "require-dev" : { - "friendsofphp/php-cs-fixer": "^3.87", - "phpstan/phpstan": "^1.12", + "friendsofphp/php-cs-fixer": "^3.95", + "phpstan/phpstan": "^2.1", + "phpstan/phpstan-phpunit": "^2.0", + "phpstan/phpstan-strict-rules": "^2.0", + "phpstan/extension-installer": "^1.4", "phpunit/phpunit" : "^9.6" }, "suggest" : { diff --git a/lib/Message.php b/lib/Message.php index a999999..201458c 100644 --- a/lib/Message.php +++ b/lib/Message.php @@ -82,11 +82,8 @@ public function getBodyAsString(): string return ob_get_clean(); } - /** - * @var string|int|null $contentLength - */ $contentLength = $this->getHeader('Content-Length'); - if (null !== $contentLength && (is_int($contentLength) || ctype_digit($contentLength))) { + if (null !== $contentLength && ctype_digit($contentLength)) { return stream_get_contents($body, (int) $contentLength); } diff --git a/lib/Sapi.php b/lib/Sapi.php index b37c023..d1a5065 100644 --- a/lib/Sapi.php +++ b/lib/Sapi.php @@ -86,7 +86,7 @@ public static function sendResponse(ResponseInterface $response): void $contentLength = $response->getHeader('Content-Length'); if (null !== $contentLength) { $output = fopen('php://output', 'wb'); - if (is_resource($body) && 'stream' == get_resource_type($body)) { + if (is_resource($body) && 'stream' === get_resource_type($body)) { // a workaround to make PHP more possible to use mmap based copy, see https://github.com/sabre-io/http/pull/119 $left = (int) $contentLength; // copy with 4MiB chunks diff --git a/phpstan.neon b/phpstan.neon index 5802f6f..25979fe 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -14,6 +14,14 @@ parameters: message: "#^Left side of || is always false.$#" count: 2 path: lib/Client.php + - + message: "#^Strict comparison using !== between '' and non-empty-string will always evaluate to true.$#" + count: 1 + path: lib/Auth/Digest.php + - + message: "#^Casting to string something that's already string.$#" + count: 1 + path: lib/Sapi.php - message: "#^Strict comparison using === between null and array will always evaluate to false.$#" count: 1 diff --git a/tests/HTTP/Auth/AWSTest.php b/tests/HTTP/Auth/AWSTest.php index 0999c95..4e266ae 100644 --- a/tests/HTTP/Auth/AWSTest.php +++ b/tests/HTTP/Auth/AWSTest.php @@ -200,7 +200,7 @@ public function test401(): void { $this->auth->requireLogin(); $test = preg_match('/^AWS$/', $this->response->getHeader('WWW-Authenticate'), $matches); - $this->assertTrue(true == $test, 'The WWW-Authenticate response didn\'t match our pattern'); + self::assertTrue(1 === $test, 'The WWW-Authenticate response didn\'t match our pattern'); } /** diff --git a/tests/HTTP/Auth/DigestTest.php b/tests/HTTP/Auth/DigestTest.php index dbc9416..13bfae5 100644 --- a/tests/HTTP/Auth/DigestTest.php +++ b/tests/HTTP/Auth/DigestTest.php @@ -166,7 +166,7 @@ private function getServerTokens(int $qop = Digest::QOP_AUTH): array $test = preg_match('/Digest realm="'.self::REALM.'",qop="'.$qopstr.'",nonce="([0-9a-f]*)",opaque="([0-9a-f]*)"/', $this->response->getHeader('WWW-Authenticate'), $matches); - $this->assertTrue(true == $test, 'The WWW-Authenticate response didn\'t match our pattern. We received: '.$this->response->getHeader('WWW-Authenticate')); + self::assertTrue(1 === $test, 'The WWW-Authenticate response didn\'t match our pattern. We received: '.$this->response->getHeader('WWW-Authenticate')); $nonce = $matches[1]; $opaque = $matches[2]; diff --git a/tests/HTTP/RequestTest.php b/tests/HTTP/RequestTest.php index 2a7432a..d1a8644 100644 --- a/tests/HTTP/RequestTest.php +++ b/tests/HTTP/RequestTest.php @@ -35,7 +35,7 @@ public function testGetQueryParametersNoData(): void } /** - * @backupGlobals + * @backupGlobals enabled */ public function testCreateFromPHPRequest(): void { From 6a036f0d8a4fdcafb305647b529a49d65ad08027 Mon Sep 17 00:00:00 2001 From: Phil Davis Date: Mon, 6 Jan 2025 17:15:32 +0545 Subject: [PATCH 2/5] chore: remove phpVersion from phpstan.neon --- phpstan.neon | 1 - 1 file changed, 1 deletion(-) diff --git a/phpstan.neon b/phpstan.neon index 25979fe..fd45673 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,6 +1,5 @@ parameters: level: 6 - phpVersion: 70430 # PHP 7.4.30 ignoreErrors: - message: "#^Negated boolean expression is always true.$#" From 1d1839b950354b403a06777b865c4b136409ce0b Mon Sep 17 00:00:00 2001 From: Phil Davis Date: Mon, 6 Jan 2025 17:53:49 +0545 Subject: [PATCH 3/5] chore: update ignoreErrrors count --- phpstan.neon | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpstan.neon b/phpstan.neon index fd45673..5e58410 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -11,7 +11,7 @@ parameters: path: lib/Client.php - message: "#^Left side of || is always false.$#" - count: 2 + count: 19 path: lib/Client.php - message: "#^Strict comparison using !== between '' and non-empty-string will always evaluate to true.$#" From 2e6fd93ea9f2711e101e50b59c7712239fdc4399 Mon Sep 17 00:00:00 2001 From: Phillip Davis Date: Mon, 27 Apr 2026 16:07:43 +0930 Subject: [PATCH 4/5] chore: implement different phpstan ignore by PHP version --- phpstan-ignore-by-php-version.neon.php | 18 ++++++++++++++++++ phpstan-ignore-php74.neon | 6 ++++++ phpstan-ignore-php8.neon | 6 ++++++ phpstan.neon | 15 +++------------ 4 files changed, 33 insertions(+), 12 deletions(-) create mode 100644 phpstan-ignore-by-php-version.neon.php create mode 100644 phpstan-ignore-php74.neon create mode 100644 phpstan-ignore-php8.neon diff --git a/phpstan-ignore-by-php-version.neon.php b/phpstan-ignore-by-php-version.neon.php new file mode 100644 index 0000000..5f58a1c --- /dev/null +++ b/phpstan-ignore-by-php-version.neon.php @@ -0,0 +1,18 @@ += 80000) { + $includes[] = __DIR__.'/phpstan-ignore-php8.neon'; +} else { + $includes[] = __DIR__.'/phpstan-ignore-php74.neon'; +} + +$config = []; +$config['includes'] = $includes; + +// overrides config.platform.php in composer.json +$config['parameters']['phpVersion'] = PHP_VERSION_ID; + +return $config; diff --git a/phpstan-ignore-php74.neon b/phpstan-ignore-php74.neon new file mode 100644 index 0000000..041b324 --- /dev/null +++ b/phpstan-ignore-php74.neon @@ -0,0 +1,6 @@ +parameters: + ignoreErrors: + - + message: "#^Left side of || is always false.$#" + count: 10 + path: lib/Client.php diff --git a/phpstan-ignore-php8.neon b/phpstan-ignore-php8.neon new file mode 100644 index 0000000..43b26f0 --- /dev/null +++ b/phpstan-ignore-php8.neon @@ -0,0 +1,6 @@ +parameters: + ignoreErrors: + - + message: "#^Left side of || is always false.$#" + count: 23 + path: lib/Client.php diff --git a/phpstan.neon b/phpstan.neon index 5e58410..52d9ac3 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,18 +1,9 @@ +includes: + - phpstan-ignore-by-php-version.neon.php + parameters: level: 6 ignoreErrors: - - - message: "#^Negated boolean expression is always true.$#" - count: 1 - path: lib/Client.php - - - message: "#^If condition is always false.$#" - count: 3 - path: lib/Client.php - - - message: "#^Left side of || is always false.$#" - count: 19 - path: lib/Client.php - message: "#^Strict comparison using !== between '' and non-empty-string will always evaluate to true.$#" count: 1 From c76b861017f6f797f13590e42f349868ede7ad6c Mon Sep 17 00:00:00 2001 From: Phil Davis Date: Wed, 8 Feb 2023 17:57:54 +0545 Subject: [PATCH 5/5] test: Call static assert functions with self:: --- tests/HTTP/Auth/AWSTest.php | 30 ++++----- tests/HTTP/Auth/BasicTest.php | 12 ++-- tests/HTTP/Auth/BearerTest.php | 10 +-- tests/HTTP/Auth/DigestTest.php | 16 ++--- tests/HTTP/ClientTest.php | 96 ++++++++++++++-------------- tests/HTTP/FunctionsTest.php | 14 ++-- tests/HTTP/MessageDecoratorTest.php | 52 +++++++-------- tests/HTTP/MessageTest.php | 62 +++++++++--------- tests/HTTP/NegotiateTest.php | 2 +- tests/HTTP/RequestDecoratorTest.php | 38 +++++------ tests/HTTP/RequestTest.php | 28 ++++---- tests/HTTP/ResponseDecoratorTest.php | 10 +-- tests/HTTP/ResponseTest.php | 14 ++-- tests/HTTP/SapiTest.php | 44 ++++++------- tests/HTTP/URLUtilTest.php | 22 +++---- 15 files changed, 225 insertions(+), 225 deletions(-) diff --git a/tests/HTTP/Auth/AWSTest.php b/tests/HTTP/Auth/AWSTest.php index 4e266ae..f9ac27f 100644 --- a/tests/HTTP/Auth/AWSTest.php +++ b/tests/HTTP/Auth/AWSTest.php @@ -29,8 +29,8 @@ public function testNoHeader(): void $this->request->setMethod('GET'); $result = $this->auth->init(); - $this->assertFalse($result, 'No AWS Authorization header was supplied, so we should have gotten false'); - $this->assertEquals(AWS::ERR_NOAWSHEADER, $this->auth->errorCode); + self::assertFalse($result, 'No AWS Authorization header was supplied, so we should have gotten false'); + self::assertEquals(AWS::ERR_NOAWSHEADER, $this->auth->errorCode); } public function testInvalidAuthorizationHeader(): void @@ -38,7 +38,7 @@ public function testInvalidAuthorizationHeader(): void $this->request->setMethod('GET'); $this->request->setHeader('Authorization', 'Invalid Auth Header'); - $this->assertFalse($this->auth->init(), 'The Invalid AWS authorization header'); + self::assertFalse($this->auth->init(), 'The Invalid AWS authorization header'); } public function testIncorrectContentMD5(): void @@ -56,8 +56,8 @@ public function testIncorrectContentMD5(): void $this->auth->init(); $result = $this->auth->validate($secretKey); - $this->assertFalse($result); - $this->assertEquals(AWS::ERR_MD5CHECKSUMWRONG, $this->auth->errorCode); + self::assertFalse($result); + self::assertEquals(AWS::ERR_MD5CHECKSUMWRONG, $this->auth->errorCode); } public function testNoDate(): void @@ -78,8 +78,8 @@ public function testNoDate(): void $this->auth->init(); $result = $this->auth->validate($secretKey); - $this->assertFalse($result); - $this->assertEquals(AWS::ERR_INVALIDDATEFORMAT, $this->auth->errorCode); + self::assertFalse($result); + self::assertEquals(AWS::ERR_INVALIDDATEFORMAT, $this->auth->errorCode); } public function testFutureDate(): void @@ -105,8 +105,8 @@ public function testFutureDate(): void $this->auth->init(); $result = $this->auth->validate($secretKey); - $this->assertFalse($result); - $this->assertEquals(AWS::ERR_REQUESTTIMESKEWED, $this->auth->errorCode); + self::assertFalse($result); + self::assertEquals(AWS::ERR_REQUESTTIMESKEWED, $this->auth->errorCode); } public function testPastDate(): void @@ -132,8 +132,8 @@ public function testPastDate(): void $this->auth->init(); $result = $this->auth->validate($secretKey); - $this->assertFalse($result); - $this->assertEquals(AWS::ERR_REQUESTTIMESKEWED, $this->auth->errorCode); + self::assertFalse($result); + self::assertEquals(AWS::ERR_REQUESTTIMESKEWED, $this->auth->errorCode); } public function testIncorrectSignature(): void @@ -160,8 +160,8 @@ public function testIncorrectSignature(): void $this->auth->init(); $result = $this->auth->validate($secretKey); - $this->assertFalse($result); - $this->assertEquals(AWS::ERR_INVALIDSIGNATURE, $this->auth->errorCode); + self::assertFalse($result); + self::assertEquals(AWS::ERR_INVALIDSIGNATURE, $this->auth->errorCode); } public function testValidRequest(): void @@ -192,8 +192,8 @@ public function testValidRequest(): void $this->auth->init(); $result = $this->auth->validate($secretKey); - $this->assertTrue($result, 'Signature did not validate, got errorcode '.$this->auth->errorCode); - $this->assertEquals($accessKey, $this->auth->getAccessKey()); + self::assertTrue($result, 'Signature did not validate, got errorcode '.$this->auth->errorCode); + self::assertEquals($accessKey, $this->auth->getAccessKey()); } public function test401(): void diff --git a/tests/HTTP/Auth/BasicTest.php b/tests/HTTP/Auth/BasicTest.php index 9b10381..7819528 100644 --- a/tests/HTTP/Auth/BasicTest.php +++ b/tests/HTTP/Auth/BasicTest.php @@ -17,7 +17,7 @@ public function testGetCredentials(): void $basic = new Basic('Dagger', $request, new Response()); - $this->assertEquals([ + self::assertEquals([ 'user', 'pass:bla', ], $basic->getCredentials()); @@ -31,7 +31,7 @@ public function testGetInvalidCredentialsColonMissing(): void $basic = new Basic('Dagger', $request, new Response()); - $this->assertNull($basic->getCredentials()); + self::assertNull($basic->getCredentials()); } public function testGetCredentialsNoHeader(): void @@ -39,7 +39,7 @@ public function testGetCredentialsNoHeader(): void $request = new Request('GET', '/', []); $basic = new Basic('Dagger', $request, new Response()); - $this->assertNull($basic->getCredentials()); + self::assertNull($basic->getCredentials()); } public function testGetCredentialsNotBasic(): void @@ -49,7 +49,7 @@ public function testGetCredentialsNotBasic(): void ]); $basic = new Basic('Dagger', $request, new Response()); - $this->assertNull($basic->getCredentials()); + self::assertNull($basic->getCredentials()); } public function testRequireLogin(): void @@ -61,7 +61,7 @@ public function testRequireLogin(): void $basic->requireLogin(); - $this->assertEquals('Basic realm="Dagger", charset="UTF-8"', $response->getHeader('WWW-Authenticate')); - $this->assertEquals(401, $response->getStatus()); + self::assertEquals('Basic realm="Dagger", charset="UTF-8"', $response->getHeader('WWW-Authenticate')); + self::assertEquals(401, $response->getStatus()); } } diff --git a/tests/HTTP/Auth/BearerTest.php b/tests/HTTP/Auth/BearerTest.php index d21f23d..22df027 100644 --- a/tests/HTTP/Auth/BearerTest.php +++ b/tests/HTTP/Auth/BearerTest.php @@ -17,7 +17,7 @@ public function testGetToken(): void $bearer = new Bearer('Dagger', $request, new Response()); - $this->assertEquals( + self::assertEquals( '12345', $bearer->getToken() ); @@ -28,7 +28,7 @@ public function testGetCredentialsNoHeader(): void $request = new Request('GET', '/', []); $bearer = new Bearer('Dagger', $request, new Response()); - $this->assertNull($bearer->getToken()); + self::assertNull($bearer->getToken()); } public function testGetCredentialsNotBearer(): void @@ -38,7 +38,7 @@ public function testGetCredentialsNotBearer(): void ]); $bearer = new Bearer('Dagger', $request, new Response()); - $this->assertNull($bearer->getToken()); + self::assertNull($bearer->getToken()); } public function testRequireLogin(): void @@ -49,7 +49,7 @@ public function testRequireLogin(): void $bearer->requireLogin(); - $this->assertEquals('Bearer realm="Dagger"', $response->getHeader('WWW-Authenticate')); - $this->assertEquals(401, $response->getStatus()); + self::assertEquals('Bearer realm="Dagger"', $response->getHeader('WWW-Authenticate')); + self::assertEquals(401, $response->getStatus()); } } diff --git a/tests/HTTP/Auth/DigestTest.php b/tests/HTTP/Auth/DigestTest.php index 13bfae5..f5bc609 100644 --- a/tests/HTTP/Auth/DigestTest.php +++ b/tests/HTTP/Auth/DigestTest.php @@ -50,10 +50,10 @@ public function testDigest(): void $this->auth->init(); - $this->assertEquals($username, $this->auth->getUsername()); - $this->assertEquals(self::REALM, $this->auth->getRealm()); - $this->assertTrue($this->auth->validateA1(md5($username.':'.self::REALM.':'.$password)), 'Authentication is deemed invalid through validateA1'); - $this->assertTrue($this->auth->validatePassword($password), 'Authentication is deemed invalid through validatePassword'); + self::assertEquals($username, $this->auth->getUsername()); + self::assertEquals(self::REALM, $this->auth->getRealm()); + self::assertTrue($this->auth->validateA1(md5($username.':'.self::REALM.':'.$password)), 'Authentication is deemed invalid through validateA1'); + self::assertTrue($this->auth->validatePassword($password), 'Authentication is deemed invalid through validatePassword'); } public function testInvalidDigest(): void @@ -79,7 +79,7 @@ public function testInvalidDigest(): void $this->auth->init(); - $this->assertFalse($this->auth->validateA1(md5($username.':'.self::REALM.':'.($password.'randomness'))), 'Authentication is deemed invalid through validateA1'); + self::assertFalse($this->auth->validateA1(md5($username.':'.self::REALM.':'.($password.'randomness'))), 'Authentication is deemed invalid through validateA1'); } public function testInvalidDigest2(): void @@ -88,7 +88,7 @@ public function testInvalidDigest2(): void $this->request->setHeader('Authorization', 'basic blablabla'); $this->auth->init(); - $this->assertFalse($this->auth->validateA1(md5('user:realm:password'))); + self::assertFalse($this->auth->validateA1(md5('user:realm:password'))); } public function testDigestAuthInt(): void @@ -116,7 +116,7 @@ public function testDigestAuthInt(): void $this->auth->init(); - $this->assertTrue($this->auth->validateA1(md5($username.':'.self::REALM.':'.$password)), 'Authentication is deemed invalid through validateA1'); + self::assertTrue($this->auth->validateA1(md5($username.':'.self::REALM.':'.$password)), 'Authentication is deemed invalid through validateA1'); } public function testDigestAuthBoth(): void @@ -144,7 +144,7 @@ public function testDigestAuthBoth(): void $this->auth->init(); - $this->assertTrue($this->auth->validateA1(md5($username.':'.self::REALM.':'.$password)), 'Authentication is deemed invalid through validateA1'); + self::assertTrue($this->auth->validateA1(md5($username.':'.self::REALM.':'.$password)), 'Authentication is deemed invalid through validateA1'); } /** diff --git a/tests/HTTP/ClientTest.php b/tests/HTTP/ClientTest.php index 0c264cf..9fe3d04 100644 --- a/tests/HTTP/ClientTest.php +++ b/tests/HTTP/ClientTest.php @@ -48,7 +48,7 @@ public function testCreateCurlSettingsArrayGET(): void CURLOPT_USERAGENT => 'sabre-http/'.Version::VERSION.' (http://sabre.io/)', ] + self::protocolSettings(); - $this->assertEquals($settings, $client->createCurlSettingsArray($request)); + self::assertEquals($settings, $client->createCurlSettingsArray($request)); } public function testCreateCurlSettingsHTTPHeader(): void @@ -91,7 +91,7 @@ public function testCreateCurlSettingsArrayHEAD(): void CURLOPT_USERAGENT => 'sabre-http/'.Version::VERSION.' (http://sabre.io/)', ] + self::protocolSettings(); - $this->assertEquals($settings, $client->createCurlSettingsArray($request)); + self::assertEquals($settings, $client->createCurlSettingsArray($request)); } public function testCreateCurlSettingsArrayGETAfterHEAD(): void @@ -117,7 +117,7 @@ public function testCreateCurlSettingsArrayGETAfterHEAD(): void CURLOPT_USERAGENT => 'sabre-http/'.Version::VERSION.' (http://sabre.io/)', ] + self::protocolSettings(); - $this->assertEquals($settings, $client->createCurlSettingsArray($request)); + self::assertEquals($settings, $client->createCurlSettingsArray($request)); } public function testCreateCurlSettingsArrayPUTStream(): void @@ -142,7 +142,7 @@ public function testCreateCurlSettingsArrayPUTStream(): void CURLOPT_USERAGENT => 'sabre-http/'.Version::VERSION.' (http://sabre.io/)', ] + self::protocolSettings(); - $this->assertEquals($settings, $client->createCurlSettingsArray($request)); + self::assertEquals($settings, $client->createCurlSettingsArray($request)); } public function testCreateCurlSettingsArrayPUTString(): void @@ -161,7 +161,7 @@ public function testCreateCurlSettingsArrayPUTString(): void CURLOPT_USERAGENT => 'sabre-http/'.Version::VERSION.' (http://sabre.io/)', ] + self::protocolSettings(); - $this->assertEquals($settings, $client->createCurlSettingsArray($request)); + self::assertEquals($settings, $client->createCurlSettingsArray($request)); } public function testIssue89MultiplePutInfileGivesWarning(): void @@ -171,20 +171,20 @@ public function testIssue89MultiplePutInfileGivesWarning(): void $request = new Request('POST', 'http://example.org/', ['X-Foo' => 'bar'], 'body'); $settings = $client->createCurlSettingsArray($request); - $this->assertArrayNotHasKey(CURLOPT_PUT, $settings); - $this->assertArrayNotHasKey(CURLOPT_INFILE, $settings); + self::assertArrayNotHasKey(CURLOPT_PUT, $settings); + self::assertArrayNotHasKey(CURLOPT_INFILE, $settings); $request = new Request('POST', 'http://example.org/', ['X-Foo' => 'bar'], $tmpFile); $settings = $client->createCurlSettingsArray($request); - $this->assertEquals(true, $settings[CURLOPT_PUT]); - $this->assertEquals($tmpFile, $settings[CURLOPT_INFILE]); + self::assertEquals(true, $settings[CURLOPT_PUT]); + self::assertEquals($tmpFile, $settings[CURLOPT_INFILE]); $request = new Request('POST', 'http://example.org/', ['X-Foo' => 'bar'], 'body'); $settings = $client->createCurlSettingsArray($request); - $this->assertArrayNotHasKey(CURLOPT_PUT, $settings); - $this->assertArrayNotHasKey(CURLOPT_INFILE, $settings); + self::assertArrayNotHasKey(CURLOPT_PUT, $settings); + self::assertArrayNotHasKey(CURLOPT_INFILE, $settings); } public function testSend(): void @@ -198,7 +198,7 @@ public function testSend(): void $response = $client->send($request); - $this->assertEquals(200, $response->getStatus()); + self::assertEquals(200, $response->getStatus()); } /** @@ -238,8 +238,8 @@ public function testSendToGetLargeContent(): void $client = new Client(); $response = $client->send($request); - $this->assertEquals(200, $response->getStatus()); - $this->assertLessThan( + self::assertEquals(200, $response->getStatus()); + self::assertLessThan( (int) $maxPeakMemoryUsage, memory_get_peak_usage(), "Hint: you can adjust the max peak memory usage allowed for this test by defining env variable $maxPeakMemoryUsageEnvVariable to be the desired max bytes" @@ -260,9 +260,9 @@ public function testSendAsync(): void $request = new Request('GET', $url); $client->sendAsync($request, function (ResponseInterface $response) { - $this->assertEquals("foo\n", $response->getBody()); - $this->assertEquals(200, $response->getStatus()); - $this->assertEquals(4, $response->getHeader('Content-Length')); + self::assertEquals("foo\n", $response->getBody()); + self::assertEquals(200, $response->getStatus()); + self::assertEquals(4, $response->getHeader('Content-Length')); }, function ($error) use ($request) { $url = $request->getUrl(); $this->fail("Failed to GET $url"); @@ -285,9 +285,9 @@ public function testSendAsynConsecutively(): void $request = new Request('GET', $url); $client->sendAsync($request, function (ResponseInterface $response) { - $this->assertEquals("foo\n", $response->getBody()); - $this->assertEquals(200, $response->getStatus()); - $this->assertEquals(4, $response->getHeader('Content-Length')); + self::assertEquals("foo\n", $response->getBody()); + self::assertEquals(200, $response->getStatus()); + self::assertEquals(4, $response->getHeader('Content-Length')); }, function ($error) use ($request) { $url = $request->getUrl(); $this->fail("Failed to get $url"); @@ -296,9 +296,9 @@ public function testSendAsynConsecutively(): void $url = $this->getAbsoluteUrl('/bar.php'); $request = new Request('GET', $url); $client->sendAsync($request, function (ResponseInterface $response) { - $this->assertEquals("bar\n", $response->getBody()); - $this->assertEquals(200, $response->getStatus()); - $this->assertEquals('Bar', $response->getHeader('X-Test')); + self::assertEquals("bar\n", $response->getBody()); + self::assertEquals(200, $response->getStatus()); + self::assertEquals('Bar', $response->getHeader('X-Test')); }, function ($error) use ($request) { $url = $request->getUrl(); $this->fail("Failed to get $url"); @@ -325,7 +325,7 @@ public function testSendClientError(): void $this->fail('send() should have thrown an exception'); } catch (ClientException $e) { } - $this->assertTrue($called); + self::assertTrue($called); } public function testSendHttpError(): void @@ -345,7 +345,7 @@ public function testSendHttpError(): void }); $client->send($request); - $this->assertEquals(2, $called); + self::assertEquals(2, $called); } public function testSendRetry(): void @@ -370,9 +370,9 @@ public function testSendRetry(): void }); $response = $client->send($request); - $this->assertEquals(3, $called); - $this->assertEquals(2, $errorCalled); - $this->assertEquals(200, $response->getStatus()); + self::assertEquals(3, $called); + self::assertEquals(2, $errorCalled); + self::assertEquals(200, $response->getStatus()); } public function testHttpErrorException(): void @@ -389,8 +389,8 @@ public function testHttpErrorException(): void $client->send($request); $this->fail('An exception should have been thrown'); } catch (ClientHttpException $e) { - $this->assertEquals(404, $e->getHttpStatus()); - $this->assertInstanceOf('Sabre\HTTP\Response', $e->getResponse()); + self::assertEquals(404, $e->getHttpStatus()); + self::assertInstanceOf('Sabre\HTTP\Response', $e->getResponse()); } } @@ -412,11 +412,11 @@ public function testParseCurlResult(): void /** @phpstan-ignore-next-line */ $result = $client->parseCurlResult($body, 'foobar'); - $this->assertEquals(Client::STATUS_SUCCESS, $result['status']); - $this->assertEquals(200, $result['http_code']); - $this->assertEquals(200, $result['response']->getStatus()); - $this->assertEquals(['Header1' => ['Val1']], $result['response']->getHeaders()); - $this->assertEquals('Foo', $result['response']->getBodyAsString()); + self::assertEquals(Client::STATUS_SUCCESS, $result['status']); + self::assertEquals(200, $result['http_code']); + self::assertEquals(200, $result['response']->getStatus()); + self::assertEquals(['Header1' => ['Val1']], $result['response']->getHeaders()); + self::assertEquals('Foo', $result['response']->getBodyAsString()); } public function testParseCurlResultEmptyBody(): void @@ -437,11 +437,11 @@ public function testParseCurlResultEmptyBody(): void /** @phpstan-ignore-next-line */ $result = $client->parseCurlResult($body, 'foobar'); - $this->assertEquals(Client::STATUS_SUCCESS, $result['status']); - $this->assertEquals(200, $result['http_code']); - $this->assertEquals(200, $result['response']->getStatus()); - $this->assertEquals(['Header1' => ['Val1']], $result['response']->getHeaders()); - $this->assertEquals('', $result['response']->getBodyAsString()); + self::assertEquals(Client::STATUS_SUCCESS, $result['status']); + self::assertEquals(200, $result['http_code']); + self::assertEquals(200, $result['response']->getStatus()); + self::assertEquals(['Header1' => ['Val1']], $result['response']->getHeaders()); + self::assertEquals('', $result['response']->getBodyAsString()); } public function testParseCurlError(): void @@ -459,9 +459,9 @@ public function testParseCurlError(): void /** @phpstan-ignore-next-line */ $result = $client->parseCurlResult($body, 'foobar'); - $this->assertEquals(Client::STATUS_CURLERROR, $result['status']); - $this->assertEquals(1, $result['curl_errno']); - $this->assertEquals('Curl error', $result['curl_errmsg']); + self::assertEquals(Client::STATUS_CURLERROR, $result['status']); + self::assertEquals(1, $result['curl_errno']); + self::assertEquals('Curl error', $result['curl_errmsg']); } public function testDoRequest(): void @@ -482,9 +482,9 @@ public function testDoRequest(): void ]; }); $response = $client->doRequest($request); - $this->assertEquals(200, $response->getStatus()); - $this->assertEquals(['Header1' => ['Val1']], $response->getHeaders()); - $this->assertEquals('Foo', $response->getBodyAsString()); + self::assertEquals(200, $response->getStatus()); + self::assertEquals(['Header1' => ['Val1']], $response->getHeaders()); + self::assertEquals('Foo', $response->getBodyAsString()); } public function testDoRequestCurlError(): void @@ -506,8 +506,8 @@ public function testDoRequestCurlError(): void $response = $client->doRequest($request); $this->fail('This should have thrown an exception'); } catch (ClientException $e) { - $this->assertEquals(1, $e->getCode()); - $this->assertEquals('Curl error', $e->getMessage()); + self::assertEquals(1, $e->getCode()); + self::assertEquals('Curl error', $e->getMessage()); } } } diff --git a/tests/HTTP/FunctionsTest.php b/tests/HTTP/FunctionsTest.php index 720209d..506786a 100644 --- a/tests/HTTP/FunctionsTest.php +++ b/tests/HTTP/FunctionsTest.php @@ -15,7 +15,7 @@ class FunctionsTest extends \PHPUnit\Framework\TestCase */ public function testGetHeaderValuesOnValues2(array $result, array $values1, array $values2): void { - $this->assertEquals($result, getHeaderValues($values1, $values2)); + self::assertEquals($result, getHeaderValues($values1, $values2)); } /** @@ -45,7 +45,7 @@ public function getHeaderValuesDataOnValues2(): array */ public function testGetHeaderValues($input, array $output): void { - $this->assertEquals( + self::assertEquals( $output, getHeaderValues($input) ); @@ -88,7 +88,7 @@ public function getHeaderValuesData(): array */ public function testPrefer($input, array $output): void { - $this->assertEquals( + self::assertEquals( $output, parsePrefer($input) ); @@ -165,11 +165,11 @@ public function testParseHTTPDate(): void foreach ($times as $time) { $result = parseDate($time); - $this->assertEquals($expected, $result->format('U')); + self::assertEquals($expected, $result->format('U')); } $result = parseDate('Wed Oct 6 10:26:00 2010'); - $this->assertEquals(1286360760, $result->format('U')); + self::assertEquals(1286360760, $result->format('U')); } public function testParseHTTPDateFail(): void @@ -194,7 +194,7 @@ public function testParseHTTPDateFail(): void ]; foreach ($times as $time) { - $this->assertFalse(parseDate($time), 'We used the string: '.$time); + self::assertFalse(parseDate($time), 'We used the string: '.$time); } } @@ -212,7 +212,7 @@ public function testToHTTPDate(): void { $dt = new \DateTime('2011-12-10 12:00:00 +0200'); - $this->assertEquals( + self::assertEquals( 'Sat, 10 Dec 2011 10:00:00 GMT', toDate($dt) ); diff --git a/tests/HTTP/MessageDecoratorTest.php b/tests/HTTP/MessageDecoratorTest.php index bc3e73e..6b58df5 100644 --- a/tests/HTTP/MessageDecoratorTest.php +++ b/tests/HTTP/MessageDecoratorTest.php @@ -18,12 +18,12 @@ public function setUp(): void public function testBody(): void { $this->outer->setBody('foo'); - $this->assertEquals('foo', stream_get_contents($this->inner->getBodyAsStream())); - $this->assertEquals('foo', stream_get_contents($this->outer->getBodyAsStream())); - $this->assertEquals('foo', $this->inner->getBodyAsString()); - $this->assertEquals('foo', $this->outer->getBodyAsString()); - $this->assertEquals('foo', $this->inner->getBody()); - $this->assertEquals('foo', $this->outer->getBody()); + self::assertEquals('foo', stream_get_contents($this->inner->getBodyAsStream())); + self::assertEquals('foo', stream_get_contents($this->outer->getBodyAsStream())); + self::assertEquals('foo', $this->inner->getBodyAsString()); + self::assertEquals('foo', $this->outer->getBodyAsString()); + self::assertEquals('foo', $this->inner->getBody()); + self::assertEquals('foo', $this->outer->getBody()); } public function testHeaders(): void @@ -32,60 +32,60 @@ public function testHeaders(): void 'a' => 'b', ]); - $this->assertEquals(['a' => ['b']], $this->inner->getHeaders()); - $this->assertEquals(['a' => ['b']], $this->outer->getHeaders()); + self::assertEquals(['a' => ['b']], $this->inner->getHeaders()); + self::assertEquals(['a' => ['b']], $this->outer->getHeaders()); $this->outer->setHeaders([ 'c' => 'd', ]); - $this->assertEquals(['a' => ['b'], 'c' => ['d']], $this->inner->getHeaders()); - $this->assertEquals(['a' => ['b'], 'c' => ['d']], $this->outer->getHeaders()); + self::assertEquals(['a' => ['b'], 'c' => ['d']], $this->inner->getHeaders()); + self::assertEquals(['a' => ['b'], 'c' => ['d']], $this->outer->getHeaders()); $this->outer->addHeaders([ 'e' => 'f', ]); - $this->assertEquals(['a' => ['b'], 'c' => ['d'], 'e' => ['f']], $this->inner->getHeaders()); - $this->assertEquals(['a' => ['b'], 'c' => ['d'], 'e' => ['f']], $this->outer->getHeaders()); + self::assertEquals(['a' => ['b'], 'c' => ['d'], 'e' => ['f']], $this->inner->getHeaders()); + self::assertEquals(['a' => ['b'], 'c' => ['d'], 'e' => ['f']], $this->outer->getHeaders()); } public function testHeader(): void { - $this->assertFalse($this->outer->hasHeader('a')); - $this->assertFalse($this->inner->hasHeader('a')); + self::assertFalse($this->outer->hasHeader('a')); + self::assertFalse($this->inner->hasHeader('a')); $this->outer->setHeader('a', 'c'); - $this->assertTrue($this->outer->hasHeader('a')); - $this->assertTrue($this->inner->hasHeader('a')); + self::assertTrue($this->outer->hasHeader('a')); + self::assertTrue($this->inner->hasHeader('a')); - $this->assertEquals('c', $this->inner->getHeader('A')); - $this->assertEquals('c', $this->outer->getHeader('A')); + self::assertEquals('c', $this->inner->getHeader('A')); + self::assertEquals('c', $this->outer->getHeader('A')); $this->outer->addHeader('A', 'd'); - $this->assertEquals( + self::assertEquals( ['c', 'd'], $this->inner->getHeaderAsArray('A') ); - $this->assertEquals( + self::assertEquals( ['c', 'd'], $this->outer->getHeaderAsArray('A') ); $success = $this->outer->removeHeader('a'); - $this->assertTrue($success); - $this->assertNull($this->inner->getHeader('A')); - $this->assertNull($this->outer->getHeader('A')); + self::assertTrue($success); + self::assertNull($this->inner->getHeader('A')); + self::assertNull($this->outer->getHeader('A')); - $this->assertFalse($this->outer->removeHeader('i-dont-exist')); + self::assertFalse($this->outer->removeHeader('i-dont-exist')); } public function testHttpVersion(): void { $this->outer->setHttpVersion('1.0'); - $this->assertEquals('1.0', $this->inner->getHttpVersion()); - $this->assertEquals('1.0', $this->outer->getHttpVersion()); + self::assertEquals('1.0', $this->inner->getHttpVersion()); + self::assertEquals('1.0', $this->outer->getHttpVersion()); } } diff --git a/tests/HTTP/MessageTest.php b/tests/HTTP/MessageTest.php index 579b9dc..07d6ab0 100644 --- a/tests/HTTP/MessageTest.php +++ b/tests/HTTP/MessageTest.php @@ -9,7 +9,7 @@ class MessageTest extends \PHPUnit\Framework\TestCase public function testConstruct(): void { $message = new MessageMock(); - $this->assertInstanceOf('Sabre\HTTP\Message', $message); + self::assertInstanceOf('Sabre\HTTP\Message', $message); } public function testStreamBody(): void @@ -22,11 +22,11 @@ public function testStreamBody(): void $message = new MessageMock(); $message->setBody($h); - $this->assertEquals($body, $message->getBodyAsString()); + self::assertEquals($body, $message->getBodyAsString()); rewind($h); - $this->assertEquals($body, stream_get_contents($message->getBodyAsStream())); + self::assertEquals($body, stream_get_contents($message->getBodyAsStream())); rewind($h); - $this->assertEquals($body, stream_get_contents($message->getBody())); + self::assertEquals($body, stream_get_contents($message->getBody())); } public function testStringBody(): void @@ -36,9 +36,9 @@ public function testStringBody(): void $message = new MessageMock(); $message->setBody($body); - $this->assertEquals($body, $message->getBodyAsString()); - $this->assertEquals($body, stream_get_contents($message->getBodyAsStream())); - $this->assertEquals($body, $message->getBody()); + self::assertEquals($body, $message->getBodyAsString()); + self::assertEquals($body, stream_get_contents($message->getBodyAsStream())); + self::assertEquals($body, $message->getBody()); } public function testCallbackBodyAsString(): void @@ -50,7 +50,7 @@ public function testCallbackBodyAsString(): void $string = $message->getBodyAsString(); - $this->assertSame('foo', $string); + self::assertSame('foo', $string); } public function testCallbackBodyAsStream(): void @@ -62,7 +62,7 @@ public function testCallbackBodyAsStream(): void $stream = $message->getBodyAsStream(); - $this->assertSame('foo', stream_get_contents($stream)); + self::assertSame('foo', stream_get_contents($stream)); } public function testGetBodyWhenCallback(): void @@ -72,7 +72,7 @@ public function testGetBodyWhenCallback(): void $message = new MessageMock(); $message->setBody($callback); - $this->assertSame($callback, $message->getBody()); + self::assertSame($callback, $message->getBody()); } /** @@ -96,7 +96,7 @@ public function testLongStreamToStringBody(): void $message->setBody($body); $message->setHeader('Content-Length', '4'); - $this->assertEquals( + self::assertEquals( 'cdef', $message->getBodyAsString() ); @@ -116,7 +116,7 @@ public function testEmptyContentLengthHeader(): void $message->setBody($body); $message->setHeader('Content-Length', ''); - $this->assertEquals( + self::assertEquals( 'cdefg', $message->getBodyAsString() ); @@ -127,7 +127,7 @@ public function testGetEmptyBodyStream(): void $message = new MessageMock(); $body = $message->getBodyAsStream(); - $this->assertEquals('', stream_get_contents($body)); + self::assertEquals('', stream_get_contents($body)); } public function testGetEmptyBodyString(): void @@ -135,7 +135,7 @@ public function testGetEmptyBodyString(): void $message = new MessageMock(); $body = $message->getBodyAsString(); - $this->assertEquals('', $body); + self::assertEquals('', $body); } public function testHeaders(): void @@ -144,14 +144,14 @@ public function testHeaders(): void $message->setHeader('X-Foo', 'bar'); // Testing caselessness - $this->assertEquals('bar', $message->getHeader('X-Foo')); - $this->assertEquals('bar', $message->getHeader('x-fOO')); + self::assertEquals('bar', $message->getHeader('X-Foo')); + self::assertEquals('bar', $message->getHeader('x-fOO')); - $this->assertTrue( + self::assertTrue( $message->removeHeader('X-FOO') ); - $this->assertNull($message->getHeader('X-Foo')); - $this->assertFalse( + self::assertNull($message->getHeader('X-Foo')); + self::assertFalse( $message->removeHeader('X-FOO') ); } @@ -166,7 +166,7 @@ public function testSetHeaders(): void ]; $message->setHeaders($headers); - $this->assertEquals($headers, $message->getHeaders()); + self::assertEquals($headers, $message->getHeaders()); $message->setHeaders([ 'X-Foo' => ['3', '4'], @@ -178,7 +178,7 @@ public function testSetHeaders(): void 'X-Bar' => ['5'], ]; - $this->assertEquals($expected, $message->getHeaders()); + self::assertEquals($expected, $message->getHeaders()); } public function testAddHeaders(): void @@ -191,7 +191,7 @@ public function testAddHeaders(): void ]; $message->addHeaders($headers); - $this->assertEquals($headers, $message->getHeaders()); + self::assertEquals($headers, $message->getHeaders()); $message->addHeaders([ 'X-Foo' => ['3', '4'], @@ -203,7 +203,7 @@ public function testAddHeaders(): void 'X-Bar' => ['2', '5'], ]; - $this->assertEquals($expected, $message->getHeaders()); + self::assertEquals($expected, $message->getHeaders()); } public function testSendBody(): void @@ -222,7 +222,7 @@ public function testSendBody(): void $body = $message->getBody(); rewind($body); - $this->assertEquals('bar', stream_get_contents($body)); + self::assertEquals('bar', stream_get_contents($body)); } public function testMultipleHeaders(): void @@ -231,24 +231,24 @@ public function testMultipleHeaders(): void $message->setHeader('a', '1'); $message->addHeader('A', '2'); - $this->assertEquals( + self::assertEquals( '1,2', $message->getHeader('A') ); - $this->assertEquals( + self::assertEquals( '1,2', $message->getHeader('a') ); - $this->assertEquals( + self::assertEquals( ['1', '2'], $message->getHeaderAsArray('a') ); - $this->assertEquals( + self::assertEquals( ['1', '2'], $message->getHeaderAsArray('A') ); - $this->assertEquals( + self::assertEquals( [], $message->getHeaderAsArray('B') ); @@ -258,9 +258,9 @@ public function testHasHeaders(): void { $message = new MessageMock(); - $this->assertFalse($message->hasHeader('X-Foo')); + self::assertFalse($message->hasHeader('X-Foo')); $message->setHeader('X-Foo', 'Bar'); - $this->assertTrue($message->hasHeader('X-Foo')); + self::assertTrue($message->hasHeader('X-Foo')); } /** diff --git a/tests/HTTP/NegotiateTest.php b/tests/HTTP/NegotiateTest.php index 40738e0..4ee2002 100644 --- a/tests/HTTP/NegotiateTest.php +++ b/tests/HTTP/NegotiateTest.php @@ -13,7 +13,7 @@ class NegotiateTest extends \PHPUnit\Framework\TestCase */ public function testNegotiate(?string $acceptHeader, array $available, ?string $expected): void { - $this->assertEquals( + self::assertEquals( $expected, negotiateContentType($acceptHeader, $available) ); diff --git a/tests/HTTP/RequestDecoratorTest.php b/tests/HTTP/RequestDecoratorTest.php index d768135..a6f661a 100644 --- a/tests/HTTP/RequestDecoratorTest.php +++ b/tests/HTTP/RequestDecoratorTest.php @@ -18,37 +18,37 @@ public function setUp(): void public function testMethod(): void { $this->outer->setMethod('FOO'); - $this->assertEquals('FOO', $this->inner->getMethod()); - $this->assertEquals('FOO', $this->outer->getMethod()); + self::assertEquals('FOO', $this->inner->getMethod()); + self::assertEquals('FOO', $this->outer->getMethod()); } public function testUrl(): void { $this->outer->setUrl('/foo'); - $this->assertEquals('/foo', $this->inner->getUrl()); - $this->assertEquals('/foo', $this->outer->getUrl()); + self::assertEquals('/foo', $this->inner->getUrl()); + self::assertEquals('/foo', $this->outer->getUrl()); } public function testAbsoluteUrl(): void { $this->outer->setAbsoluteUrl('http://example.org/foo'); - $this->assertEquals('http://example.org/foo', $this->inner->getAbsoluteUrl()); - $this->assertEquals('http://example.org/foo', $this->outer->getAbsoluteUrl()); + self::assertEquals('http://example.org/foo', $this->inner->getAbsoluteUrl()); + self::assertEquals('http://example.org/foo', $this->outer->getAbsoluteUrl()); } public function testBaseUrl(): void { $this->outer->setBaseUrl('/foo'); - $this->assertEquals('/foo', $this->inner->getBaseUrl()); - $this->assertEquals('/foo', $this->outer->getBaseUrl()); + self::assertEquals('/foo', $this->inner->getBaseUrl()); + self::assertEquals('/foo', $this->outer->getBaseUrl()); } public function testPath(): void { $this->outer->setBaseUrl('/foo'); $this->outer->setUrl('/foo/bar'); - $this->assertEquals('bar', $this->inner->getPath()); - $this->assertEquals('bar', $this->outer->getPath()); + self::assertEquals('bar', $this->inner->getPath()); + self::assertEquals('bar', $this->outer->getPath()); } public function testQueryParams(): void @@ -60,8 +60,8 @@ public function testQueryParams(): void 'e' => null, ]; - $this->assertEquals($expected, $this->inner->getQueryParameters()); - $this->assertEquals($expected, $this->outer->getQueryParameters()); + self::assertEquals($expected, $this->inner->getQueryParameters()); + self::assertEquals($expected, $this->outer->getQueryParameters()); } public function testPostData(): void @@ -73,8 +73,8 @@ public function testPostData(): void ]; $this->outer->setPostData($postData); - $this->assertEquals($postData, $this->inner->getPostData()); - $this->assertEquals($postData, $this->outer->getPostData()); + self::assertEquals($postData, $this->inner->getPostData()); + self::assertEquals($postData, $this->outer->getPostData()); } public function testServerData(): void @@ -84,11 +84,11 @@ public function testServerData(): void ]; $this->outer->setRawServerData($serverData); - $this->assertEquals('On', $this->inner->getRawServerValue('HTTPS')); - $this->assertEquals('On', $this->outer->getRawServerValue('HTTPS')); + self::assertEquals('On', $this->inner->getRawServerValue('HTTPS')); + self::assertEquals('On', $this->outer->getRawServerValue('HTTPS')); - $this->assertNull($this->inner->getRawServerValue('FOO')); - $this->assertNull($this->outer->getRawServerValue('FOO')); + self::assertNull($this->inner->getRawServerValue('FOO')); + self::assertNull($this->outer->getRawServerValue('FOO')); } public function testToString(): void @@ -98,6 +98,6 @@ public function testToString(): void $this->inner->setBody('foo'); $this->inner->setHeader('foo', 'bar'); - $this->assertEquals((string) $this->inner, (string) $this->outer); + self::assertEquals((string) $this->inner, (string) $this->outer); } } diff --git a/tests/HTTP/RequestTest.php b/tests/HTTP/RequestTest.php index d1a8644..2e154b4 100644 --- a/tests/HTTP/RequestTest.php +++ b/tests/HTTP/RequestTest.php @@ -11,9 +11,9 @@ public function testConstruct(): void $request = new Request('GET', '/foo', [ 'User-Agent' => 'Evert', ]); - $this->assertEquals('GET', $request->getMethod()); - $this->assertEquals('/foo', $request->getUrl()); - $this->assertEquals([ + self::assertEquals('GET', $request->getMethod()); + self::assertEquals('/foo', $request->getUrl()); + self::assertEquals([ 'User-Agent' => ['Evert'], ], $request->getHeaders()); } @@ -21,7 +21,7 @@ public function testConstruct(): void public function testGetQueryParameters(): void { $request = new Request('GET', '/foo?a=b&c&d=e'); - $this->assertEquals([ + self::assertEquals([ 'a' => 'b', 'c' => null, 'd' => 'e', @@ -31,7 +31,7 @@ public function testGetQueryParameters(): void public function testGetQueryParametersNoData(): void { $request = new Request('GET', '/foo'); - $this->assertEquals([], $request->getQueryParameters()); + self::assertEquals([], $request->getQueryParameters()); } /** @@ -43,7 +43,7 @@ public function testCreateFromPHPRequest(): void $_SERVER['REQUEST_METHOD'] = 'PUT'; $request = Sapi::getRequest(); - $this->assertEquals('PUT', $request->getMethod()); + self::assertEquals('PUT', $request->getMethod()); } public function testGetAbsoluteUrl(): void @@ -52,7 +52,7 @@ public function testGetAbsoluteUrl(): void 'Host' => 'sabredav.org', ]); - $this->assertEquals('http://sabredav.org/foo', $r->getAbsoluteUrl()); + self::assertEquals('http://sabredav.org/foo', $r->getAbsoluteUrl()); $s = [ 'HTTP_HOST' => 'sabredav.org', @@ -63,7 +63,7 @@ public function testGetAbsoluteUrl(): void $r = Sapi::createFromServerArray($s); - $this->assertEquals('https://sabredav.org/foo', $r->getAbsoluteUrl()); + self::assertEquals('https://sabredav.org/foo', $r->getAbsoluteUrl()); } public function testGetPostData(): void @@ -73,7 +73,7 @@ public function testGetPostData(): void ]; $r = new Request('POST', '/'); $r->setPostData($post); - $this->assertEquals($post, $r->getPostData()); + self::assertEquals($post, $r->getPostData()); } public function testGetPath(): void @@ -82,7 +82,7 @@ public function testGetPath(): void $request->setBaseUrl('/foo'); $request->setUrl('/foo/bar/'); - $this->assertEquals('bar', $request->getPath()); + self::assertEquals('bar', $request->getPath()); } public function testGetPathStrippedQuery(): void @@ -90,7 +90,7 @@ public function testGetPathStrippedQuery(): void $request = new Request('GET', '/foo/bar?a=B'); $request->setBaseUrl('/foo'); - $this->assertEquals('bar', $request->getPath()); + self::assertEquals('bar', $request->getPath()); } public function testGetPathMissingSlash(): void @@ -98,7 +98,7 @@ public function testGetPathMissingSlash(): void $request = new Request('GET', '/foo'); $request->setBaseUrl('/foo/'); - $this->assertEquals('', $request->getPath()); + self::assertEquals('', $request->getPath()); } public function testGetPathOutsideBaseUrl(): void @@ -119,7 +119,7 @@ public function testToString(): void ."Content-Type: text/xml\r\n" ."\r\n" .'foo'; - $this->assertEquals($expected, (string) $request); + self::assertEquals($expected, (string) $request); } public function testToStringAuthorization(): void @@ -132,7 +132,7 @@ public function testToStringAuthorization(): void ."Authorization: Basic REDACTED\r\n" ."\r\n" .'foo'; - $this->assertEquals($expected, (string) $request); + self::assertEquals($expected, (string) $request); } public function testAbsoluteUrlHttp(): void diff --git a/tests/HTTP/ResponseDecoratorTest.php b/tests/HTTP/ResponseDecoratorTest.php index 83f89d8..1d16da1 100644 --- a/tests/HTTP/ResponseDecoratorTest.php +++ b/tests/HTTP/ResponseDecoratorTest.php @@ -18,10 +18,10 @@ public function setUp(): void public function testStatus(): void { $this->outer->setStatus(201); - $this->assertEquals(201, $this->inner->getStatus()); - $this->assertEquals(201, $this->outer->getStatus()); - $this->assertEquals('Created', $this->inner->getStatusText()); - $this->assertEquals('Created', $this->outer->getStatusText()); + self::assertEquals(201, $this->inner->getStatus()); + self::assertEquals(201, $this->outer->getStatus()); + self::assertEquals('Created', $this->inner->getStatusText()); + self::assertEquals('Created', $this->outer->getStatusText()); } public function testToString(): void @@ -30,6 +30,6 @@ public function testToString(): void $this->inner->setBody('foo'); $this->inner->setHeader('foo', 'bar'); - $this->assertEquals((string) $this->inner, (string) $this->outer); + self::assertEquals((string) $this->inner, (string) $this->outer); } } diff --git a/tests/HTTP/ResponseTest.php b/tests/HTTP/ResponseTest.php index 52680cd..042b7e9 100644 --- a/tests/HTTP/ResponseTest.php +++ b/tests/HTTP/ResponseTest.php @@ -9,24 +9,24 @@ class ResponseTest extends \PHPUnit\Framework\TestCase public function testConstruct(): void { $response = new Response(200, ['Content-Type' => 'text/xml']); - $this->assertEquals(200, $response->getStatus()); - $this->assertEquals('OK', $response->getStatusText()); + self::assertEquals(200, $response->getStatus()); + self::assertEquals('OK', $response->getStatusText()); } public function testSetStatus(): void { $response = new Response(); $response->setStatus('402 Where\'s my money?'); - $this->assertEquals(402, $response->getStatus()); - $this->assertEquals('Where\'s my money?', $response->getStatusText()); + self::assertEquals(402, $response->getStatus()); + self::assertEquals('Where\'s my money?', $response->getStatusText()); } public function testSetStatusWithoutText(): void { $response = new Response(); $response->setStatus('402'); - $this->assertEquals(402, $response->getStatus()); - $this->assertEquals('Payment Required', $response->getStatusText()); + self::assertEquals(402, $response->getStatus()); + self::assertEquals('Payment Required', $response->getStatusText()); } public function testInvalidStatus(): void @@ -44,6 +44,6 @@ public function testToString(): void ."Content-Type: text/xml\r\n" ."\r\n" .'foo'; - $this->assertEquals($expected, (string) $response); + self::assertEquals($expected, (string) $response); } } diff --git a/tests/HTTP/SapiTest.php b/tests/HTTP/SapiTest.php index 39d97ed..1deb941 100644 --- a/tests/HTTP/SapiTest.php +++ b/tests/HTTP/SapiTest.php @@ -17,18 +17,18 @@ public function testConstructFromServerArray(): void 'SERVER_PROTOCOL' => 'HTTP/1.0', ]); - $this->assertEquals('GET', $request->getMethod()); - $this->assertEquals('/foo', $request->getUrl()); - $this->assertEquals([ + self::assertEquals('GET', $request->getMethod()); + self::assertEquals('/foo', $request->getUrl()); + self::assertEquals([ 'User-Agent' => ['Evert'], 'Content-Type' => ['text/xml'], 'Content-Length' => ['400'], ], $request->getHeaders()); - $this->assertEquals('1.0', $request->getHttpVersion()); + self::assertEquals('1.0', $request->getHttpVersion()); - $this->assertEquals('400', $request->getRawServerValue('CONTENT_LENGTH')); - $this->assertNull($request->getRawServerValue('FOO')); + self::assertEquals('400', $request->getRawServerValue('CONTENT_LENGTH')); + self::assertNull($request->getRawServerValue('FOO')); } public function testConstructFromServerArrayOnNullUrl(): void @@ -68,9 +68,9 @@ public function testConstructPHPAuth(): void 'PHP_AUTH_PW' => 'pass', ]); - $this->assertEquals('GET', $request->getMethod()); - $this->assertEquals('/foo', $request->getUrl()); - $this->assertEquals([ + self::assertEquals('GET', $request->getMethod()); + self::assertEquals('/foo', $request->getUrl()); + self::assertEquals([ 'Authorization' => ['Basic '.base64_encode('user:pass')], ], $request->getHeaders()); } @@ -83,9 +83,9 @@ public function testConstructPHPAuthDigest(): void 'PHP_AUTH_DIGEST' => 'blabla', ]); - $this->assertEquals('GET', $request->getMethod()); - $this->assertEquals('/foo', $request->getUrl()); - $this->assertEquals([ + self::assertEquals('GET', $request->getMethod()); + self::assertEquals('/foo', $request->getUrl()); + self::assertEquals([ 'Authorization' => ['Digest blabla'], ], $request->getHeaders()); } @@ -98,9 +98,9 @@ public function testConstructRedirectAuth(): void 'REDIRECT_HTTP_AUTHORIZATION' => 'Basic bla', ]); - $this->assertEquals('GET', $request->getMethod()); - $this->assertEquals('/foo', $request->getUrl()); - $this->assertEquals([ + self::assertEquals('GET', $request->getMethod()); + self::assertEquals('/foo', $request->getUrl()); + self::assertEquals([ 'Authorization' => ['Basic bla'], ], $request->getHeaders()); } @@ -131,7 +131,7 @@ public function testSend(): void $result = ob_get_clean(); header_remove(); - $this->assertEquals( + self::assertEquals( [ 'Content-Type: text/xml;charset=UTF-8', 'Content-Type: application/xml', @@ -139,7 +139,7 @@ public function testSend(): void $headers ); - $this->assertEquals('foo', $result); + self::assertEquals('foo', $result); } /** @@ -161,7 +161,7 @@ public function testSendLimitedByContentLengthString(): void $result = ob_get_clean(); header_remove(); - $this->assertEquals('Send this sentence.', $result); + self::assertEquals('Send this sentence.', $result); } /** @@ -175,7 +175,7 @@ public function testRecognizeHttp2(): void 'REQUEST_METHOD' => 'GET', ]); - $this->assertEquals('2.0', $request->getHttpVersion()); + self::assertEquals('2.0', $request->getHttpVersion()); } /** @@ -200,7 +200,7 @@ public function testSendLimitedByContentLengthStream(): void $result = ob_get_clean(); header_remove(); - $this->assertEquals('Send this sentence.', $result); + self::assertEquals('Send this sentence.', $result); } /** @@ -246,7 +246,7 @@ public function testSendContentRangeStream( $result = ob_get_clean(); header_remove(); - $this->assertEquals($partial, $result); + self::assertEquals($partial, $result); } /** @@ -298,7 +298,7 @@ public function testSendWorksWithCallbackAsBody(): void $result = ob_get_clean(); - $this->assertEquals('foo', $result); + self::assertEquals('foo', $result); } public function testSendConnectionAborted(): void diff --git a/tests/HTTP/URLUtilTest.php b/tests/HTTP/URLUtilTest.php index 7ce73c3..94f2118 100644 --- a/tests/HTTP/URLUtilTest.php +++ b/tests/HTTP/URLUtilTest.php @@ -15,7 +15,7 @@ public function testEncodePath(): void $newStr = encodePath($str); - $this->assertEquals( + self::assertEquals( '%00%01%02%03%04%05%06%07%08%09%0a%0b%0c%0d%0e%0f'. '%10%11%12%13%14%15%16%17%18%19%1a%1b%1c%1d%1e%1f'. '%20%21%22%23%24%25%26%27()%2a%2b%2c-./'. @@ -26,7 +26,7 @@ public function testEncodePath(): void 'pqrstuvwxyz%7b%7c%7d~%7f', $newStr); - $this->assertEquals($str, decodePath($newStr)); + self::assertEquals($str, decodePath($newStr)); } public function testEncodePathSegment(): void @@ -38,9 +38,9 @@ public function testEncodePathSegment(): void $newStr = encodePathSegment($str); - // Note: almost exactly the same as the last test, with the - // exception of the encoding of / (ascii code 2f) - $this->assertEquals( + // Note: almost exactly the same as the last test, except for + // the encoding of / (ascii code 2f) + self::assertEquals( '%00%01%02%03%04%05%06%07%08%09%0a%0b%0c%0d%0e%0f'. '%10%11%12%13%14%15%16%17%18%19%1a%1b%1c%1d%1e%1f'. '%20%21%22%23%24%25%26%27()%2a%2b%2c-.%2f'. @@ -51,14 +51,14 @@ public function testEncodePathSegment(): void 'pqrstuvwxyz%7b%7c%7d~%7f', $newStr); - $this->assertEquals($str, decodePathSegment($newStr)); + self::assertEquals($str, decodePathSegment($newStr)); } public function testDecode(): void { $str = 'Hello%20Test+Test2.txt'; $newStr = decodePath($str); - $this->assertEquals('Hello Test+Test2.txt', $newStr); + self::assertEquals('Hello Test+Test2.txt', $newStr); } /** @@ -68,7 +68,7 @@ public function testDecodeUmlaut(): void { $str = 'Hello%C3%BC.txt'; $newStr = decodePath($str); - $this->assertEquals("Hello\xC3\xBC.txt", $newStr); + self::assertEquals("Hello\xC3\xBC.txt", $newStr); } /** @@ -86,7 +86,7 @@ public function testDecodeSlavicWords(): void foreach ($words as $word) { $str = rawurlencode($word); $newStr = decodePath($str); - $this->assertEquals($word, $newStr); + self::assertEquals($word, $newStr); } } @@ -97,7 +97,7 @@ public function testDecodeUmlautLatin1(): void { $str = 'Hello%FC.txt'; $newStr = decodePath($str); - $this->assertEquals("Hello\xC3\xBC.txt", $newStr); + self::assertEquals("Hello\xC3\xBC.txt", $newStr); } /** @@ -109,6 +109,6 @@ public function testDecodeAccentsWindows7(): void { $str = '/webdav/%C3%A0fo%C3%B3'; $newStr = decodePath($str); - $this->assertEquals(strtolower($str), encodePath($newStr)); + self::assertEquals(strtolower($str), encodePath($newStr)); } }