Skip to content

Improve tests no2 #51

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 1 commit into from
Dec 27, 2018
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
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
.gitattributes export-ignore
.gitignore export-ignore
.scrutinizer.yml export-ignore
.styleci.yml export-ignore
.php_cs.yml export-ignore
.travis.yml export-ignore
CONDUCT.md export-ignore
CONTRIBUTING.md export-ignore
Expand Down
17 changes: 3 additions & 14 deletions tests/BaseUnitTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace Http\Client\Curl\Tests;

use Http\Client\Curl\PromiseCore;
use Http\Discovery\MessageFactoryDiscovery;
use PHPUnit\Framework\TestCase;
use Psr\Http\Message\RequestInterface;
Expand Down Expand Up @@ -37,11 +36,11 @@ protected function tearDown()
* Create new request.
*
* @param string $method
* @param mixed $uri
* @param mixed $uri
*
* @return RequestInterface
*/
protected function createRequest($method, $uri)
protected function createRequest(string $method, $uri): RequestInterface
{
return MessageFactoryDiscovery::find()->createRequest($method, $uri);
}
Expand All @@ -51,18 +50,8 @@ protected function createRequest($method, $uri)
*
* @return ResponseInterface
*/
protected function createResponse()
protected function createResponse(): ResponseInterface
{
return MessageFactoryDiscovery::find()->createResponse();
}

/**
* Create PromiseCore mock.
*
* @return PromiseCore|\PHPUnit_Framework_MockObject_MockObject
*/
protected function createPromiseCore()
{
return $this->getMockBuilder(PromiseCore::class)->disableOriginalConstructor()->getMock();
}
}
8 changes: 4 additions & 4 deletions tests/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class ClientTest extends TestCase
*/
public function testExpectHeader()
{
$client = $this->getMockBuilder(Client::class)->disableOriginalConstructor()->getMock();
$client = $this->createMock(Client::class);

$createHeaders = new \ReflectionMethod(Client::class, 'createHeaders');
$createHeaders->setAccessible(true);
Expand All @@ -44,7 +44,7 @@ public function testExpectHeader()
*/
public function testWithNullPostFields()
{
$client = $this->getMockBuilder(Client::class)->disableOriginalConstructor()->getMock();
$client = $this->createMock(Client::class);

$createHeaders = new \ReflectionMethod(Client::class, 'createHeaders');
$createHeaders->setAccessible(true);
Expand All @@ -59,7 +59,7 @@ public function testWithNullPostFields()

public function testRewindStream()
{
$client = $this->getMockBuilder(Client::class)->disableOriginalConstructor()->getMock();
$client = $this->createMock(Client::class);

$bodyOptions = new \ReflectionMethod(Client::class, 'addRequestBodyOptions');
$bodyOptions->setAccessible(true);
Expand All @@ -74,7 +74,7 @@ public function testRewindStream()

public function testRewindLargeStream()
{
$client = $this->getMockBuilder(Client::class)->disableOriginalConstructor()->getMock();
$client = $this->createMock(Client::class);

$bodyOptions = new \ReflectionMethod(Client::class, 'addRequestBodyOptions');
$bodyOptions->setAccessible(true);
Expand Down
21 changes: 10 additions & 11 deletions tests/CurlPromiseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Http\Client\Curl\CurlPromise;
use Http\Client\Curl\MultiRunner;
use Http\Client\Curl\PromiseCore;
use Http\Client\Exception\TransferException;
use Http\Promise\Promise;

Expand All @@ -21,10 +22,9 @@ class CurlPromiseTest extends BaseUnitTestCase
*/
public function testCoreCalls()
{
$core = $this->createPromiseCore();
$runner = $this->getMockBuilder(MultiRunner::class)->disableOriginalConstructor()
->setMethods(['wait'])->getMock();
/** @var MultiRunner|\PHPUnit_Framework_MockObject_MockObject $runner */
$core = $this->createMock(PromiseCore::class);
$runner = $this->createMock(MultiRunner::class);

$promise = new CurlPromise($core, $runner);

$onFulfill = function () {
Expand All @@ -42,10 +42,9 @@ public function testCoreCalls()

public function testCoreCallWaitFulfilled()
{
$core = $this->createPromiseCore();
$runner = $this->getMockBuilder(MultiRunner::class)->disableOriginalConstructor()
->setMethods(['wait'])->getMock();
/** @var MultiRunner|\PHPUnit_Framework_MockObject_MockObject $runner */
$core = $this->createMock(PromiseCore::class);
$runner = $this->createMock(MultiRunner::class);

$promise = new CurlPromise($core, $runner);

$runner->expects(static::once())->method('wait')->with($core);
Expand All @@ -56,9 +55,9 @@ public function testCoreCallWaitFulfilled()

public function testCoreCallWaitRejected()
{
$core = $this->createPromiseCore();
$runner = $this->getMockBuilder(MultiRunner::class)->disableOriginalConstructor()->getMock();
/** @var MultiRunner|\PHPUnit_Framework_MockObject_MockObject $runner */
$core = $this->createMock(PromiseCore::class);
$runner = $this->createMock(MultiRunner::class);

$promise = new CurlPromise($core, $runner);

$runner->expects(static::once())->method('wait')->with($core);
Expand Down
16 changes: 1 addition & 15 deletions tests/HttpAsyncClientTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,8 @@ abstract class HttpAsyncClientTestCase extends HttpAsyncClientTest
*/
public function testAsyncSendRequest($method, $uri, array $headers, $body)
{
if (defined('HHVM_VERSION')) {
static::markTestSkipped('This test can not run under HHVM');
}
if (null !== $body && in_array($method, ['GET', 'HEAD', 'TRACE'], true)) {
static::markTestSkipped('cURL can not send body using '.$method);
static::markTestSkipped('cURL can not send body using ' . $method);
}
parent::testAsyncSendRequest(
$method,
Expand All @@ -41,9 +38,6 @@ public function testSendAsyncRequestWithOutcome(
array $headers,
$body
) {
if (defined('HHVM_VERSION')) {
static::markTestSkipped('This test can not run under HHVM');
}
if (null !== $body) {
static::markTestSkipped('cURL can not send body using GET');
}
Expand All @@ -54,12 +48,4 @@ public function testSendAsyncRequestWithOutcome(
$body
);
}

public function testSuccessiveCallMustUseResponseInterface()
{
if (defined('HHVM_VERSION')) {
static::markTestSkipped('This test can not run under HHVM');
}
parent::testSuccessiveCallMustUseResponseInterface();
}
}
6 changes: 0 additions & 6 deletions tests/HttpClientTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ abstract class HttpClientTestCase extends HttpClientTest
*/
public function testSendRequest($method, $uri, array $headers, $body)
{
if (defined('HHVM_VERSION')) {
static::markTestSkipped('This test can not run under HHVM');
}
if (null !== $body && in_array($method, ['GET', 'HEAD', 'TRACE'], true)) {
static::markTestSkipped('cURL can not send body using '.$method);
}
Expand All @@ -50,9 +47,6 @@ public function testSendRequestWithOutcome(
array $headers,
$body
) {
if (defined('HHVM_VERSION')) {
static::markTestSkipped('This test can not run under HHVM');
}
if (null !== $body) {
static::markTestSkipped('cURL can not send body using GET');
}
Expand Down