Skip to content

3.x preparation : Make httplug optional, depends on psr18 #43

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 4 commits into from
Feb 16, 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
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).


## [Unreleased]
## [3.0.0] - Unreleased

- Only support HTTPlug 2.0 and PSR-18
- HTTPlug 2.0 is now optional (only require it if you need to test async)
- HttpClientTest now relies only on PSR-18 (no need for HTTPlug)

## [2.0.1] - 2018-12-27

Expand Down
13 changes: 9 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,18 @@
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the branch alias in the composer.json file needs to be updated

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 totally forget this comment my bad, should be good

],
"require": {
"php": ">=5.4",
"phpunit/phpunit": "^4.8.35 || ^5.4.3 || ^6.0 || ^7.0",
"php-http/httplug": "^1.0 || ^2.0",
"php": "^7.1",
"phpunit/phpunit": "^7.0",
"php-http/message": "^1.0",
"guzzlehttp/psr7": "^1.0",
"th3n3rd/cartesian-product": "^0.3"
},
"suggest": {
"php-http/httplug": "To test async client"
},
"require-dev": {
"php-http/httplug": "^2.0"
},
"autoload": {
"psr-4": {
"Http\\Client\\Tests\\": "src/"
Expand All @@ -44,7 +49,7 @@
],
"extra": {
"branch-alias": {
"dev-master": "2.x-dev"
"dev-master": "3.x-dev"
}
}
}
5 changes: 1 addition & 4 deletions src/HttpAsyncClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,7 @@ protected function tearDown()
unset($this->httpAdapter);
}

/**
* @return HttpAsyncClient
*/
abstract protected function createHttpAsyncClient();
abstract protected function createHttpAsyncClient(): HttpAsyncClient;

public function testSuccessiveCallMustUseResponseInterface()
{
Expand Down
23 changes: 4 additions & 19 deletions src/HttpBaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,7 @@ public static function tearDownAfterClass()
}
}

/**
* @return array
*/
public function requestProvider()
public function requestProvider(): array
{
$sets = [
'methods' => $this->getMethods(),
Expand All @@ -85,10 +82,7 @@ public function requestProvider()
});
}

/**
* @return array
*/
public function requestWithOutcomeProvider()
public function requestWithOutcomeProvider(): array
{
$sets = [
'urisAndOutcomes' => $this->getUrisAndOutcomes(),
Expand All @@ -102,10 +96,7 @@ public function requestWithOutcomeProvider()
return $cartesianProduct->compute();
}

/**
* @return array
*/
private function getMethods()
private function getMethods(): array
{
return [
'GET',
Expand Down Expand Up @@ -211,14 +202,8 @@ private function getData()
return ['param1' => 'foo', 'param2' => ['bar', ['baz']]];
}

/**
* @param ResponseInterface $response
* @param array $options
*/
protected function assertResponse($response, array $options = [])
protected function assertResponse(ResponseInterface $response, array $options = [])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the explicit assertion would lead to a phpunit failure instead of a full php type explosion. but the client interface has a return type declaration, so it should be impossible to ever have anything else than a ResponseInterface, right? if thats the case then the change is fine for me.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, php will fail before that so we are pretty safe here

{
$this->assertInstanceOf('Psr\Http\Message\ResponseInterface', $response);

$options = array_merge($this->defaultOptions, $options);

// The response version may be greater or equal to the request version. See https://tools.ietf.org/html/rfc2145#section-2.3
Expand Down
9 changes: 3 additions & 6 deletions src/HttpClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

namespace Http\Client\Tests;

use Http\Client\HttpClient;
use Psr\Http\Client\ClientInterface;

/**
* @author GeLo <[email protected]>
*/
abstract class HttpClientTest extends HttpBaseTest
{
/**
* @var HttpClient
* @var ClientInterface
*/
protected $httpAdapter;

Expand All @@ -30,10 +30,7 @@ protected function tearDown()
unset($this->httpAdapter);
}

/**
* @return HttpClient
*/
abstract protected function createHttpAdapter();
abstract protected function createHttpAdapter(): ClientInterface;

/**
* @dataProvider requestProvider
Expand Down
19 changes: 2 additions & 17 deletions src/HttpFeatureTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Http\Client\Tests;

use Http\Client\HttpClient;
use Psr\Http\Client\ClientInterface;
use Http\Message\MessageFactory;
use Http\Message\MessageFactory\GuzzleMessageFactory;
use PHPUnit\Framework\TestCase;
Expand All @@ -22,10 +22,7 @@ public static function setUpBeforeClass()
self::$messageFactory = new GuzzleMessageFactory();
}

/**
* @return HttpClient
*/
abstract protected function createClient();
abstract protected function createClient(): ClientInterface;

/**
* @feature Send a GET Request
Expand All @@ -39,7 +36,6 @@ public function testGet()

$response = $this->createClient()->sendRequest($request);

$this->assertInstanceOf('Psr\Http\Message\ResponseInterface', $response);
$this->assertSame(200, $response->getStatusCode());
}

Expand All @@ -58,7 +54,6 @@ public function testPost()

$response = $this->createClient()->sendRequest($request);

$this->assertInstanceOf('Psr\Http\Message\ResponseInterface', $response);
$this->assertSame(200, $response->getStatusCode());

$contents = json_decode($response->getBody()->__toString());
Expand All @@ -78,7 +73,6 @@ public function testPatch()

$response = $this->createClient()->sendRequest($request);

$this->assertInstanceOf('Psr\Http\Message\ResponseInterface', $response);
$this->assertSame(200, $response->getStatusCode());
}

Expand All @@ -94,7 +88,6 @@ public function testPut()

$response = $this->createClient()->sendRequest($request);

$this->assertInstanceOf('Psr\Http\Message\ResponseInterface', $response);
$this->assertSame(200, $response->getStatusCode());
}

Expand All @@ -110,7 +103,6 @@ public function testDelete()

$response = $this->createClient()->sendRequest($request);

$this->assertInstanceOf('Psr\Http\Message\ResponseInterface', $response);
$this->assertSame(200, $response->getStatusCode());
}

Expand All @@ -129,7 +121,6 @@ public function testAutoSetContentLength()

$response = $this->createClient()->sendRequest($request);

$this->assertInstanceOf('Psr\Http\Message\ResponseInterface', $response);
$this->assertSame(200, $response->getStatusCode());

$contents = json_decode($response->getBody()->__toString());
Expand All @@ -149,7 +140,6 @@ public function testEncoding()

$response = $this->createClient()->sendRequest($request);

$this->assertInstanceOf('Psr\Http\Message\ResponseInterface', $response);
$this->assertSame(200, $response->getStatusCode());
$this->assertContains('€', $response->getBody()->__toString());
}
Expand All @@ -166,7 +156,6 @@ public function testGzip()

$response = $this->createClient()->sendRequest($request);

$this->assertInstanceOf('Psr\Http\Message\ResponseInterface', $response);
$this->assertSame(200, $response->getStatusCode());
$this->assertContains('gzip', $response->getBody()->__toString());
}
Expand All @@ -183,7 +172,6 @@ public function testDeflate()

$response = $this->createClient()->sendRequest($request);

$this->assertInstanceOf('Psr\Http\Message\ResponseInterface', $response);
$this->assertSame(200, $response->getStatusCode());
$this->assertContains('deflate', $response->getBody()->__toString());
}
Expand All @@ -200,7 +188,6 @@ public function testRedirect()

$response = $this->createClient()->sendRequest($request);

$this->assertInstanceOf('Psr\Http\Message\ResponseInterface', $response);
$this->assertSame(200, $response->getStatusCode());
}

Expand All @@ -216,7 +203,6 @@ public function testChunked()

$response = $this->createClient()->sendRequest($request);

$this->assertInstanceOf('Psr\Http\Message\ResponseInterface', $response);
$this->assertSame(200, $response->getStatusCode());

$content = @json_decode($response->getBody()->__toString());
Expand All @@ -236,7 +222,6 @@ public function testSsl()

$response = $this->createClient()->sendRequest($request);

$this->assertInstanceOf('Psr\Http\Message\ResponseInterface', $response);
$this->assertSame(200, $response->getStatusCode());
}
}
37 changes: 10 additions & 27 deletions src/ResultPrinter.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,19 @@
namespace Http\Client\Tests;

use PHPUnit\Framework\Test;
use PHPUnit\TextUI\ResultPrinter as BaseResultPrinter;

// If PHPUnit 6
if (class_exists('\\PHPUnit\\TextUI\\ResultPrinter')) {
class ResultPrinter extends \PHPUnit\TextUI\ResultPrinter
{
use FeatureTestListener;

public function startTest(Test $test)
{
return $this->doStartTest($test);
}
class ResultPrinter extends BaseResultPrinter
{
use FeatureTestListener;

public function endTest(Test $test, $time)
{
return $this->doEndTest($test, $time);
}
}
} else {
class ResultPrinter extends \PHPUnit_TextUI_ResultPrinter
public function startTest(Test $test): void
{
use FeatureTestListener;

public function startTest(\PHPUnit_Framework_Test $test)
{
return $this->doStartTest($test);
}
return $this->doStartTest($test);
}

public function endTest(\PHPUnit_Framework_Test $test, $time)
{
return $this->doEndTest($test, $time);
}
public function endTest(Test $test, float $time): void
{
return $this->doEndTest($test, $time);
}
}