Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
tools: composer:v2

- name: Checkout code
uses: actions/checkout@v4
uses: actions/checkout@v5

- name: Download dependencies
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/static.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:

steps:
- name: Checkout code
uses: actions/checkout@v4
uses: actions/checkout@v5

- name: PHP-CS-Fixer
uses: docker://oskarstark/php-cs-fixer-ga:2.16.4
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
],
"require": {
"php": "^7.4 || ^8.0",
"phpunit/phpunit": "^9.6.17",
"phpunit/phpunit": "^9.6.17 || ^10.0 || ^11.0 || ^12.0",
"php-http/message": "^1.0 || ^2.0",
"php-http/message-factory": "^1.0",
"guzzlehttp/psr7": "^1.9 || ^2.0",
Expand Down
17 changes: 12 additions & 5 deletions src/HttpAsyncClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
namespace Http\Client\Tests;

use Http\Client\HttpAsyncClient;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Group;

abstract class HttpAsyncClientTest extends HttpBaseTest
{
Expand Down Expand Up @@ -33,8 +35,8 @@ public function testSuccessiveCallMustUseResponseInterface()
{
$request = self::$messageFactory->createRequest(
'GET',
$this->getUri(),
$this->defaultHeaders
self::getUri(),
self::$defaultHeaders
);

$promise = $this->httpAsyncClient->sendAsyncRequest($request);
Expand All @@ -61,7 +63,7 @@ public function testSuccessiveInvalidCallMustUseException()
$request = self::$messageFactory->createRequest(
'GET',
$this->getInvalidUri(),
$this->defaultHeaders
self::$defaultHeaders
);

$promise = $this->httpAsyncClient->sendAsyncRequest($request);
Expand Down Expand Up @@ -90,6 +92,8 @@ public function testSuccessiveInvalidCallMustUseException()
* @dataProvider requestProvider
* @group integration
*/
#[DataProvider('requestProvider')]
#[Group('integration')]
public function testAsyncSendRequest($method, $uri, array $headers, $body)
{
if (null != $body) {
Expand Down Expand Up @@ -124,14 +128,15 @@ public function testAsyncSendRequest($method, $uri, array $headers, $body)
}

/**
* @group integration
* @group integration
*/
#[Group('integration')]
public function testSendAsyncWithInvalidUri()
{
$request = self::$messageFactory->createRequest(
'GET',
$this->getInvalidUri(),
$this->defaultHeaders
self::$defaultHeaders
);

$exception = null;
Expand Down Expand Up @@ -159,6 +164,8 @@ public function testSendAsyncWithInvalidUri()
* @dataProvider requestWithOutcomeProvider
* @group integration
*/
#[Group('integration')]
#[DataProvider('requestWithOutcomeProvider')]
public function testSendAsyncRequestWithOutcome($uriAndOutcome, $protocolVersion, array $headers, $body)
{
if ('1.0' === $protocolVersion) {
Expand Down
50 changes: 25 additions & 25 deletions src/HttpBaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ abstract class HttpBaseTest extends TestCase
/**
* @var array
*/
protected $defaultHeaders = [
protected static $defaultHeaders = [
'Connection' => 'close',
'User-Agent' => 'PHP HTTP Adapter',
'Content-Length' => '0',
Expand All @@ -61,13 +61,13 @@ public static function tearDownAfterClass(): void
}
}

public function requestProvider(): array
public static function requestProvider(): array
{
$sets = [
'methods' => $this->getMethods(),
'uris' => [$this->getUri()],
'headers' => $this->getHeaders(),
'body' => $this->getBodies(),
'methods' => self::getMethods(),
'uris' => [self::getUri()],
'headers' => self::getHeaders(),
'body' => self::getBodies(),
];

$cartesianProduct = new CartesianProduct($sets);
Expand All @@ -84,21 +84,21 @@ public function requestProvider(): array
});
}

public function requestWithOutcomeProvider(): array
public static function requestWithOutcomeProvider(): array
{
$sets = [
'urisAndOutcomes' => $this->getUrisAndOutcomes(),
'protocolVersions' => $this->getProtocolVersions(),
'headers' => $this->getHeaders(),
'body' => $this->getBodies(),
'urisAndOutcomes' => self::getUrisAndOutcomes(),
'protocolVersions' => self::getProtocolVersions(),
'headers' => self::getHeaders(),
'body' => self::getBodies(),
];

$cartesianProduct = new CartesianProduct($sets);

return $cartesianProduct->compute();
}

private function getMethods(): array
private static function getMethods(): array
{
return [
'GET',
Expand All @@ -116,7 +116,7 @@ private function getMethods(): array
*
* @return string|null
*/
protected function getUri(array $query = [])
protected static function getUri(array $query = [])
{
return !empty($query)
? PHPUnitUtility::getUri().'?'.http_build_query($query, '', '&')
Expand All @@ -134,25 +134,25 @@ protected function getInvalidUri()
/**
* @return array
*/
private function getUrisAndOutcomes()
private static function getUrisAndOutcomes()
{
return [
[
$this->getUri(['client_error' => true]),
self::getUri(['client_error' => true]),
[
'statusCode' => 400,
'reasonPhrase' => 'Bad Request',
],
],
[
$this->getUri(['server_error' => true]),
self::getUri(['server_error' => true]),
[
'statusCode' => 500,
'reasonPhrase' => 'Internal Server Error',
],
],
[
$this->getUri(['redirect' => true]),
self::getUri(['redirect' => true]),
[
'statusCode' => 302,
'reasonPhrase' => 'Found',
Expand All @@ -165,41 +165,41 @@ private function getUrisAndOutcomes()
/**
* @return array
*/
private function getProtocolVersions()
private static function getProtocolVersions()
{
return ['1.1', '1.0'];
}

/**
* @return string[]
*/
private function getHeaders()
private static function getHeaders()
{
$headers = $this->defaultHeaders;
$headers = self::$defaultHeaders;
$headers['Accept-Charset'] = 'utf-8';
$headers['Accept-Language'] = 'en';

return [
$this->defaultHeaders,
self::$defaultHeaders,
$headers,
];
}

/**
* @return array
*/
private function getBodies()
private static function getBodies()
{
return [
null,
http_build_query($this->getData(), '', '&'),
http_build_query(self::getData(), '', '&'),
];
}

/**
* @return array
*/
private function getData()
private static function getData()
{
return ['param1' => 'foo', 'param2' => ['bar', ['baz']]];
}
Expand All @@ -223,7 +223,7 @@ protected function assertResponse(ResponseInterface $response, array $options =
if (null === $options['body']) {
$this->assertEmpty($response->getBody()->__toString());
} else {
$this->assertStringContainsString($options['body'], $response->getBody()->__toString());
self::assertStringContainsStringCompatible($options['body'], $response->getBody()->__toString());
}
}

Expand Down
9 changes: 8 additions & 1 deletion src/HttpClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Http\Client\Tests;

use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Group;
use Psr\Http\Client\ClientInterface;
use Psr\Http\Client\NetworkExceptionInterface;

Expand Down Expand Up @@ -37,6 +39,8 @@ abstract protected function createHttpAdapter(): ClientInterface;
* @dataProvider requestProvider
* @group integration
*/
#[Group('integration')]
#[DataProvider('requestProvider')]
public function testSendRequest($method, $uri, array $headers, $body)
{
if (null != $body) {
Expand Down Expand Up @@ -65,6 +69,8 @@ public function testSendRequest($method, $uri, array $headers, $body)
* @dataProvider requestWithOutcomeProvider
* @group integration
*/
#[Group('integration')]
#[DataProvider('requestWithOutcomeProvider')]
public function testSendRequestWithOutcome($uriAndOutcome, $protocolVersion, array $headers, $body)
{
if ('1.0' === $protocolVersion) {
Expand Down Expand Up @@ -95,12 +101,13 @@ public function testSendRequestWithOutcome($uriAndOutcome, $protocolVersion, arr
/**
* @group integration
*/
#[Group('integration')]
public function testSendWithInvalidUri()
{
$request = self::$messageFactory->createRequest(
'GET',
$this->getInvalidUri(),
$this->defaultHeaders
self::$defaultHeaders
);

$this->expectException(NetworkExceptionInterface::class);
Expand Down
6 changes: 3 additions & 3 deletions src/HttpFeatureTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public function testEncoding()
$response = $this->createClient()->sendRequest($request);

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

/**
Expand All @@ -159,7 +159,7 @@ public function testGzip()
$response = $this->createClient()->sendRequest($request);

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

/**
Expand All @@ -175,7 +175,7 @@ public function testDeflate()
$response = $this->createClient()->sendRequest($request);

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

/**
Expand Down
2 changes: 1 addition & 1 deletion src/PhpUnitBackwardCompatibleTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

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