Skip to content

Commit 49d98e0

Browse files
Nyholmgmponos
andauthored
Support PHPUnit 8 (#44)
* Support PHPUnit 8 * Added return types * Show Guzzle tests * minor * Fix the deprecation warnings (#45) * Fix the deprecation warnings * Provide a bc way for assertStringContainsString Co-authored-by: Mponos George <gmponos@gmail.com>
1 parent 4daae3f commit 49d98e0

8 files changed

+43
-15
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ env:
1313
- SUITE="curl" PACKAGE="php-http/curl-client:dev-master zendframework/zend-diactoros"
1414
- SUITE="Socket" PACKAGE="php-http/socket-client:dev-master php-http/client-common"
1515
- SUITE="Guzzle6" PACKAGE="php-http/guzzle6-adapter:dev-master"
16+
- SUITE="Guzzle" PACKAGE="guzzlehttp/guzzle:dev-master"
1617
- SUITE="React" PACKAGE="php-http/react-adapter:dev-master"
1718
- SUITE="Buzz" PACKAGE="php-http/buzz-adapter:dev-master"
1819
- SUITE="CakePHP" PACKAGE="php-http/cakephp-adapter:dev-master"

composer.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
],
1717
"require": {
1818
"php": "^7.1",
19-
"phpunit/phpunit": "^7.0",
19+
"phpunit/phpunit": "^7.0 || ^8.0",
2020
"php-http/message": "^1.0",
2121
"guzzlehttp/psr7": "^1.0",
2222
"th3n3rd/cartesian-product": "^0.3"
@@ -51,5 +51,6 @@
5151
"branch-alias": {
5252
"dev-master": "3.x-dev"
5353
}
54-
}
54+
},
55+
"minimum-stability": "dev"
5556
}

phpunit.xml.dist

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
<testsuite name="Socket">
1111
<directory>vendor/php-http/socket-client/tests</directory>
1212
</testsuite>
13+
<testsuite name="Guzzle">
14+
<file>vendor/guzzlehttp/guzzle/tests/HttplugIntegrationTest.php</file>
15+
</testsuite>
1316
<testsuite name="Guzzle5">
1417
<directory>vendor/php-http/guzzle5-adapter/tests</directory>
1518
</testsuite>

src/HttpAsyncClientTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ abstract class HttpAsyncClientTest extends HttpBaseTest
1414
/**
1515
* {@inheritdoc}
1616
*/
17-
protected function setUp()
17+
protected function setUp(): void
1818
{
1919
$this->httpAsyncClient = $this->createHttpAsyncClient();
2020
}
2121

2222
/**
2323
* {@inheritdoc}
2424
*/
25-
protected function tearDown()
25+
protected function tearDown(): void
2626
{
2727
unset($this->httpAdapter);
2828
}

src/HttpBaseTest.php

Lines changed: 5 additions & 3 deletions
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
*/
@@ -43,7 +45,7 @@ abstract class HttpBaseTest extends TestCase
4345
/**
4446
* {@inheritdoc}
4547
*/
46-
public static function setUpBeforeClass()
48+
public static function setUpBeforeClass(): void
4749
{
4850
self::$logPath = PHPUnitUtility::getFile(true, 'php-http-adapter.log');
4951
self::$messageFactory = new GuzzleMessageFactory();
@@ -52,7 +54,7 @@ public static function setUpBeforeClass()
5254
/**
5355
* {@inheritdoc}
5456
*/
55-
public static function tearDownAfterClass()
57+
public static function tearDownAfterClass(): void
5658
{
5759
if (file_exists(self::$logPath)) {
5860
unlink(self::$logPath);
@@ -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: 5 additions & 4 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>
@@ -17,15 +18,15 @@ abstract class HttpClientTest extends HttpBaseTest
1718
/**
1819
* {@inheritdoc}
1920
*/
20-
protected function setUp()
21+
protected function setUp(): void
2122
{
2223
$this->httpAdapter = $this->createHttpAdapter();
2324
}
2425

2526
/**
2627
* {@inheritdoc}
2728
*/
28-
protected function tearDown()
29+
protected function tearDown(): void
2930
{
3031
unset($this->httpAdapter);
3132
}
@@ -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: 6 additions & 4 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
*/
@@ -17,7 +19,7 @@ abstract class HttpFeatureTest extends TestCase
1719
/**
1820
* {@inheritdoc}
1921
*/
20-
public static function setUpBeforeClass()
22+
public static function setUpBeforeClass(): void
2123
{
2224
self::$messageFactory = new GuzzleMessageFactory();
2325
}
@@ -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)