Skip to content

Commit 6d527ff

Browse files
gmponosdbu
authored andcommitted
Fix the deprecation warnings (#45)
* Fix the deprecation warnings * Provide a bc way for assertStringContainsString
1 parent 9422993 commit 6d527ff

File tree

4 files changed

+29
-6
lines changed

4 files changed

+29
-6
lines changed

src/HttpBaseTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
abstract class HttpBaseTest extends TestCase
1212
{
13+
use PhpUnitBackwardCompatibleTrait;
14+
1315
/**
1416
* @var string
1517
*/
@@ -221,7 +223,7 @@ protected function assertResponse(ResponseInterface $response, array $options =
221223
if (null === $options['body']) {
222224
$this->assertEmpty($response->getBody()->__toString());
223225
} else {
224-
$this->assertContains($options['body'], $response->getBody()->__toString());
226+
$this->assertStringContainsString($options['body'], $response->getBody()->__toString());
225227
}
226228
}
227229

src/HttpClientTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Http\Client\Tests;
44

55
use Psr\Http\Client\ClientInterface;
6+
use Psr\Http\Client\NetworkExceptionInterface;
67

78
/**
89
* @author GeLo <geloen.eric@gmail.com>
@@ -92,8 +93,7 @@ public function testSendRequestWithOutcome($uriAndOutcome, $protocolVersion, arr
9293
}
9394

9495
/**
95-
* @expectedException \Psr\Http\Client\NetworkExceptionInterface
96-
* @group integration
96+
* @group integration
9797
*/
9898
public function testSendWithInvalidUri()
9999
{
@@ -103,6 +103,7 @@ public function testSendWithInvalidUri()
103103
$this->defaultHeaders
104104
);
105105

106+
$this->expectException(NetworkExceptionInterface::class);
106107
$this->httpAdapter->sendRequest($request);
107108
}
108109
}

src/HttpFeatureTest.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
abstract class HttpFeatureTest extends TestCase
1111
{
12+
use PhpUnitBackwardCompatibleTrait;
13+
1214
/**
1315
* @var MessageFactory
1416
*/
@@ -141,7 +143,7 @@ public function testEncoding()
141143
$response = $this->createClient()->sendRequest($request);
142144

143145
$this->assertSame(200, $response->getStatusCode());
144-
$this->assertContains('', $response->getBody()->__toString());
146+
$this->assertStringContainsString('', $response->getBody()->__toString());
145147
}
146148

147149
/**
@@ -157,7 +159,7 @@ public function testGzip()
157159
$response = $this->createClient()->sendRequest($request);
158160

159161
$this->assertSame(200, $response->getStatusCode());
160-
$this->assertContains('gzip', $response->getBody()->__toString());
162+
$this->assertStringContainsString('gzip', $response->getBody()->__toString());
161163
}
162164

163165
/**
@@ -173,7 +175,7 @@ public function testDeflate()
173175
$response = $this->createClient()->sendRequest($request);
174176

175177
$this->assertSame(200, $response->getStatusCode());
176-
$this->assertContains('deflate', $response->getBody()->__toString());
178+
$this->assertStringContainsString('deflate', $response->getBody()->__toString());
177179
}
178180

179181
/**
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace Http\Client\Tests;
4+
5+
use PHPUnit\Framework\TestCase;
6+
7+
trait PhpUnitBackwardCompatibleTrait
8+
{
9+
public static function assertStringContainsString(string $needle, string $haystack, string $message = ''): void
10+
{
11+
// For supporting both phpunit 7 and 8 without display any deprecation.
12+
if (method_exists(TestCase::class, 'assertStringContainsString')) {
13+
parent::assertStringContainsString($needle, $haystack, $message);
14+
} else {
15+
parent::assertContains($needle, $haystack, $message);
16+
}
17+
}
18+
}

0 commit comments

Comments
 (0)