Skip to content

Support PHPUnit 8 #44

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 5 commits into from
Sep 30, 2020
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
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ env:
- SUITE="curl" PACKAGE="php-http/curl-client:dev-master zendframework/zend-diactoros"
- SUITE="Socket" PACKAGE="php-http/socket-client:dev-master php-http/client-common"
- SUITE="Guzzle6" PACKAGE="php-http/guzzle6-adapter:dev-master"
- SUITE="Guzzle" PACKAGE="guzzlehttp/guzzle:dev-master"
- SUITE="React" PACKAGE="php-http/react-adapter:dev-master"
- SUITE="Buzz" PACKAGE="php-http/buzz-adapter:dev-master"
- SUITE="CakePHP" PACKAGE="php-http/cakephp-adapter:dev-master"
Expand Down
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
],
"require": {
"php": "^7.1",
"phpunit/phpunit": "^7.0",
"phpunit/phpunit": "^7.0 || ^8.0",
"php-http/message": "^1.0",
"guzzlehttp/psr7": "^1.0",
"th3n3rd/cartesian-product": "^0.3"
Expand Down Expand Up @@ -51,5 +51,6 @@
"branch-alias": {
"dev-master": "3.x-dev"
}
}
},
"minimum-stability": "dev"
}
3 changes: 3 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
<testsuite name="Socket">
<directory>vendor/php-http/socket-client/tests</directory>
</testsuite>
<testsuite name="Guzzle">
<file>vendor/guzzlehttp/guzzle/tests/HttplugIntegrationTest.php</file>
</testsuite>
<testsuite name="Guzzle5">
<directory>vendor/php-http/guzzle5-adapter/tests</directory>
</testsuite>
Expand Down
4 changes: 2 additions & 2 deletions src/HttpAsyncClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ abstract class HttpAsyncClientTest extends HttpBaseTest
/**
* {@inheritdoc}
*/
protected function setUp()
protected function setUp(): void
{
$this->httpAsyncClient = $this->createHttpAsyncClient();
}

/**
* {@inheritdoc}
*/
protected function tearDown()
protected function tearDown(): void
{
unset($this->httpAdapter);
}
Expand Down
8 changes: 5 additions & 3 deletions 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 @@ -43,7 +45,7 @@ abstract class HttpBaseTest extends TestCase
/**
* {@inheritdoc}
*/
public static function setUpBeforeClass()
public static function setUpBeforeClass(): void
{
self::$logPath = PHPUnitUtility::getFile(true, 'php-http-adapter.log');
self::$messageFactory = new GuzzleMessageFactory();
Expand All @@ -52,7 +54,7 @@ public static function setUpBeforeClass()
/**
* {@inheritdoc}
*/
public static function tearDownAfterClass()
public static function tearDownAfterClass(): void
{
if (file_exists(self::$logPath)) {
unlink(self::$logPath);
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
9 changes: 5 additions & 4 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 <[email protected]>
Expand All @@ -17,15 +18,15 @@ abstract class HttpClientTest extends HttpBaseTest
/**
* {@inheritdoc}
*/
protected function setUp()
protected function setUp(): void
{
$this->httpAdapter = $this->createHttpAdapter();
}

/**
* {@inheritdoc}
*/
protected function tearDown()
protected function tearDown(): void
{
unset($this->httpAdapter);
}
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);
}
}
10 changes: 6 additions & 4 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 All @@ -17,7 +19,7 @@ abstract class HttpFeatureTest extends TestCase
/**
* {@inheritdoc}
*/
public static function setUpBeforeClass()
public static function setUpBeforeClass(): void
{
self::$messageFactory = new GuzzleMessageFactory();
}
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);
}
}
}