From 2dafcf5d8533c4c459ae008c11cec3b5a3904ae8 Mon Sep 17 00:00:00 2001 From: Mponos George Date: Sun, 15 Dec 2019 20:26:26 +0200 Subject: [PATCH 1/3] Fix hte deprecation warnings --- src/HttpBaseTest.php | 7 ++++++- src/HttpClientTest.php | 4 ++-- src/HttpFeatureTest.php | 6 +++--- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/HttpBaseTest.php b/src/HttpBaseTest.php index 79fb058..898c246 100644 --- a/src/HttpBaseTest.php +++ b/src/HttpBaseTest.php @@ -221,7 +221,12 @@ protected function assertResponse(ResponseInterface $response, array $options = if (null === $options['body']) { $this->assertEmpty($response->getBody()->__toString()); } else { - $this->assertContains($options['body'], $response->getBody()->__toString()); + // For supporting both phpunit 7 and 8 without display any deprecation. + if (method_exists($this, 'assertStringContainsString')) { + $this->assertStringContainsString($options['body'], $response->getBody()->__toString()); + } else { + $this->assertContains($options['body'], $response->getBody()->__toString()); + } } } diff --git a/src/HttpClientTest.php b/src/HttpClientTest.php index 5c82aa6..e6d4bb7 100644 --- a/src/HttpClientTest.php +++ b/src/HttpClientTest.php @@ -92,8 +92,7 @@ public function testSendRequestWithOutcome($uriAndOutcome, $protocolVersion, arr } /** - * @expectedException \Psr\Http\Client\NetworkExceptionInterface - * @group integration + * @group integration */ public function testSendWithInvalidUri() { @@ -103,6 +102,7 @@ public function testSendWithInvalidUri() $this->defaultHeaders ); + $this->expectException(\Psr\Http\Client\NetworkExceptionInterface::class); $this->httpAdapter->sendRequest($request); } } diff --git a/src/HttpFeatureTest.php b/src/HttpFeatureTest.php index 08f7ced..0a55cf6 100644 --- a/src/HttpFeatureTest.php +++ b/src/HttpFeatureTest.php @@ -141,7 +141,7 @@ public function testEncoding() $response = $this->createClient()->sendRequest($request); $this->assertSame(200, $response->getStatusCode()); - $this->assertContains('€', $response->getBody()->__toString()); + $this->assertStringContainsString('€', $response->getBody()->__toString()); } /** @@ -157,7 +157,7 @@ public function testGzip() $response = $this->createClient()->sendRequest($request); $this->assertSame(200, $response->getStatusCode()); - $this->assertContains('gzip', $response->getBody()->__toString()); + $this->assertStringContainsString('gzip', $response->getBody()->__toString()); } /** @@ -173,7 +173,7 @@ public function testDeflate() $response = $this->createClient()->sendRequest($request); $this->assertSame(200, $response->getStatusCode()); - $this->assertContains('deflate', $response->getBody()->__toString()); + $this->assertStringContainsString('deflate', $response->getBody()->__toString()); } /** From 6a22274fc16c94b4c4159cdce019d37737051715 Mon Sep 17 00:00:00 2001 From: Mponos George Date: Sun, 15 Dec 2019 20:41:30 +0200 Subject: [PATCH 2/3] Provide a bc way for assertStringContainsString --- src/HttpBaseTest.php | 9 +++------ src/HttpFeatureTest.php | 2 ++ src/PhpUnitBackwardCompatibleTrait.php | 18 ++++++++++++++++++ 3 files changed, 23 insertions(+), 6 deletions(-) create mode 100644 src/PhpUnitBackwardCompatibleTrait.php diff --git a/src/HttpBaseTest.php b/src/HttpBaseTest.php index 898c246..44a7f7d 100644 --- a/src/HttpBaseTest.php +++ b/src/HttpBaseTest.php @@ -10,6 +10,8 @@ abstract class HttpBaseTest extends TestCase { + use PhpUnitBackwardCompatibleTrait; + /** * @var string */ @@ -221,12 +223,7 @@ protected function assertResponse(ResponseInterface $response, array $options = if (null === $options['body']) { $this->assertEmpty($response->getBody()->__toString()); } else { - // For supporting both phpunit 7 and 8 without display any deprecation. - if (method_exists($this, 'assertStringContainsString')) { - $this->assertStringContainsString($options['body'], $response->getBody()->__toString()); - } else { - $this->assertContains($options['body'], $response->getBody()->__toString()); - } + $this->assertStringContainsString($options['body'], $response->getBody()->__toString()); } } diff --git a/src/HttpFeatureTest.php b/src/HttpFeatureTest.php index 0a55cf6..fd4836f 100644 --- a/src/HttpFeatureTest.php +++ b/src/HttpFeatureTest.php @@ -9,6 +9,8 @@ abstract class HttpFeatureTest extends TestCase { + use PhpUnitBackwardCompatibleTrait; + /** * @var MessageFactory */ diff --git a/src/PhpUnitBackwardCompatibleTrait.php b/src/PhpUnitBackwardCompatibleTrait.php new file mode 100644 index 0000000..05f094d --- /dev/null +++ b/src/PhpUnitBackwardCompatibleTrait.php @@ -0,0 +1,18 @@ + Date: Wed, 18 Dec 2019 16:00:51 +0200 Subject: [PATCH 3/3] Import a use statement --- src/HttpClientTest.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/HttpClientTest.php b/src/HttpClientTest.php index e6d4bb7..aaaf7a4 100644 --- a/src/HttpClientTest.php +++ b/src/HttpClientTest.php @@ -3,6 +3,7 @@ namespace Http\Client\Tests; use Psr\Http\Client\ClientInterface; +use Psr\Http\Client\NetworkExceptionInterface; /** * @author GeLo @@ -102,7 +103,7 @@ public function testSendWithInvalidUri() $this->defaultHeaders ); - $this->expectException(\Psr\Http\Client\NetworkExceptionInterface::class); + $this->expectException(NetworkExceptionInterface::class); $this->httpAdapter->sendRequest($request); } }