Skip to content

Fix the deprecation warnings #45

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/HttpBaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

abstract class HttpBaseTest extends TestCase
{
use PhpUnitBackwardCompatibleTrait;

/**
* @var string
*/
Expand Down Expand Up @@ -221,7 +223,7 @@ protected function assertResponse(ResponseInterface $response, array $options =
if (null === $options['body']) {
$this->assertEmpty($response->getBody()->__toString());
} else {
$this->assertContains($options['body'], $response->getBody()->__toString());
$this->assertStringContainsString($options['body'], $response->getBody()->__toString());
}
}

Expand Down
5 changes: 3 additions & 2 deletions src/HttpClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Http\Client\Tests;

use Psr\Http\Client\ClientInterface;
use Psr\Http\Client\NetworkExceptionInterface;

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

/**
* @expectedException \Psr\Http\Client\NetworkExceptionInterface
* @group integration
* @group integration
*/
public function testSendWithInvalidUri()
{
Expand All @@ -103,6 +103,7 @@ public function testSendWithInvalidUri()
$this->defaultHeaders
);

$this->expectException(NetworkExceptionInterface::class);
$this->httpAdapter->sendRequest($request);
}
}
8 changes: 5 additions & 3 deletions src/HttpFeatureTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

abstract class HttpFeatureTest extends TestCase
{
use PhpUnitBackwardCompatibleTrait;

/**
* @var MessageFactory
*/
Expand Down Expand Up @@ -141,7 +143,7 @@ public function testEncoding()
$response = $this->createClient()->sendRequest($request);

$this->assertSame(200, $response->getStatusCode());
$this->assertContains('€', $response->getBody()->__toString());
$this->assertStringContainsString('€', $response->getBody()->__toString());
}

/**
Expand All @@ -157,7 +159,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());
}

/**
Expand All @@ -173,7 +175,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());
}

/**
Expand Down
18 changes: 18 additions & 0 deletions src/PhpUnitBackwardCompatibleTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace Http\Client\Tests;

use PHPUnit\Framework\TestCase;

trait PhpUnitBackwardCompatibleTrait
{
public static function assertStringContainsString(string $needle, string $haystack, string $message = ''): void
{
// For supporting both phpunit 7 and 8 without display any deprecation.
if (method_exists(TestCase::class, 'assertStringContainsString')) {
parent::assertStringContainsString($needle, $haystack, $message);
} else {
parent::assertContains($needle, $haystack, $message);
}
}
}