Skip to content

Commit cc9e183

Browse files
authored
Merge pull request #51 from gmponos/improve_tests_2
Improve tests no2
2 parents 8ac288b + 15d4ff9 commit cc9e183

6 files changed

+20
-50
lines changed

.gitattributes

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
.gitattributes export-ignore
44
.gitignore export-ignore
55
.scrutinizer.yml export-ignore
6+
.styleci.yml export-ignore
7+
.php_cs.yml export-ignore
68
.travis.yml export-ignore
79
CONDUCT.md export-ignore
810
CONTRIBUTING.md export-ignore

tests/BaseUnitTestCase.php

+3-14
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
namespace Http\Client\Curl\Tests;
66

7-
use Http\Client\Curl\PromiseCore;
87
use Http\Discovery\MessageFactoryDiscovery;
98
use PHPUnit\Framework\TestCase;
109
use Psr\Http\Message\RequestInterface;
@@ -37,11 +36,11 @@ protected function tearDown()
3736
* Create new request.
3837
*
3938
* @param string $method
40-
* @param mixed $uri
39+
* @param mixed $uri
4140
*
4241
* @return RequestInterface
4342
*/
44-
protected function createRequest($method, $uri)
43+
protected function createRequest(string $method, $uri): RequestInterface
4544
{
4645
return MessageFactoryDiscovery::find()->createRequest($method, $uri);
4746
}
@@ -51,18 +50,8 @@ protected function createRequest($method, $uri)
5150
*
5251
* @return ResponseInterface
5352
*/
54-
protected function createResponse()
53+
protected function createResponse(): ResponseInterface
5554
{
5655
return MessageFactoryDiscovery::find()->createResponse();
5756
}
58-
59-
/**
60-
* Create PromiseCore mock.
61-
*
62-
* @return PromiseCore|\PHPUnit_Framework_MockObject_MockObject
63-
*/
64-
protected function createPromiseCore()
65-
{
66-
return $this->getMockBuilder(PromiseCore::class)->disableOriginalConstructor()->getMock();
67-
}
6857
}

tests/ClientTest.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class ClientTest extends TestCase
2525
*/
2626
public function testExpectHeader()
2727
{
28-
$client = $this->getMockBuilder(Client::class)->disableOriginalConstructor()->getMock();
28+
$client = $this->createMock(Client::class);
2929

3030
$createHeaders = new \ReflectionMethod(Client::class, 'createHeaders');
3131
$createHeaders->setAccessible(true);
@@ -44,7 +44,7 @@ public function testExpectHeader()
4444
*/
4545
public function testWithNullPostFields()
4646
{
47-
$client = $this->getMockBuilder(Client::class)->disableOriginalConstructor()->getMock();
47+
$client = $this->createMock(Client::class);
4848

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

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

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

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

7979
$bodyOptions = new \ReflectionMethod(Client::class, 'addRequestBodyOptions');
8080
$bodyOptions->setAccessible(true);

tests/CurlPromiseTest.php

+10-11
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use Http\Client\Curl\CurlPromise;
88
use Http\Client\Curl\MultiRunner;
9+
use Http\Client\Curl\PromiseCore;
910
use Http\Client\Exception\TransferException;
1011
use Http\Promise\Promise;
1112

@@ -21,10 +22,9 @@ class CurlPromiseTest extends BaseUnitTestCase
2122
*/
2223
public function testCoreCalls()
2324
{
24-
$core = $this->createPromiseCore();
25-
$runner = $this->getMockBuilder(MultiRunner::class)->disableOriginalConstructor()
26-
->setMethods(['wait'])->getMock();
27-
/** @var MultiRunner|\PHPUnit_Framework_MockObject_MockObject $runner */
25+
$core = $this->createMock(PromiseCore::class);
26+
$runner = $this->createMock(MultiRunner::class);
27+
2828
$promise = new CurlPromise($core, $runner);
2929

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

4343
public function testCoreCallWaitFulfilled()
4444
{
45-
$core = $this->createPromiseCore();
46-
$runner = $this->getMockBuilder(MultiRunner::class)->disableOriginalConstructor()
47-
->setMethods(['wait'])->getMock();
48-
/** @var MultiRunner|\PHPUnit_Framework_MockObject_MockObject $runner */
45+
$core = $this->createMock(PromiseCore::class);
46+
$runner = $this->createMock(MultiRunner::class);
47+
4948
$promise = new CurlPromise($core, $runner);
5049

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

5756
public function testCoreCallWaitRejected()
5857
{
59-
$core = $this->createPromiseCore();
60-
$runner = $this->getMockBuilder(MultiRunner::class)->disableOriginalConstructor()->getMock();
61-
/** @var MultiRunner|\PHPUnit_Framework_MockObject_MockObject $runner */
58+
$core = $this->createMock(PromiseCore::class);
59+
$runner = $this->createMock(MultiRunner::class);
60+
6261
$promise = new CurlPromise($core, $runner);
6362

6463
$runner->expects(static::once())->method('wait')->with($core);

tests/HttpAsyncClientTestCase.php

+1-15
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,8 @@ abstract class HttpAsyncClientTestCase extends HttpAsyncClientTest
1717
*/
1818
public function testAsyncSendRequest($method, $uri, array $headers, $body)
1919
{
20-
if (defined('HHVM_VERSION')) {
21-
static::markTestSkipped('This test can not run under HHVM');
22-
}
2320
if (null !== $body && in_array($method, ['GET', 'HEAD', 'TRACE'], true)) {
24-
static::markTestSkipped('cURL can not send body using '.$method);
21+
static::markTestSkipped('cURL can not send body using ' . $method);
2522
}
2623
parent::testAsyncSendRequest(
2724
$method,
@@ -41,9 +38,6 @@ public function testSendAsyncRequestWithOutcome(
4138
array $headers,
4239
$body
4340
) {
44-
if (defined('HHVM_VERSION')) {
45-
static::markTestSkipped('This test can not run under HHVM');
46-
}
4741
if (null !== $body) {
4842
static::markTestSkipped('cURL can not send body using GET');
4943
}
@@ -54,12 +48,4 @@ public function testSendAsyncRequestWithOutcome(
5448
$body
5549
);
5650
}
57-
58-
public function testSuccessiveCallMustUseResponseInterface()
59-
{
60-
if (defined('HHVM_VERSION')) {
61-
static::markTestSkipped('This test can not run under HHVM');
62-
}
63-
parent::testSuccessiveCallMustUseResponseInterface();
64-
}
6551
}

tests/HttpClientTestCase.php

-6
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@ abstract class HttpClientTestCase extends HttpClientTest
2626
*/
2727
public function testSendRequest($method, $uri, array $headers, $body)
2828
{
29-
if (defined('HHVM_VERSION')) {
30-
static::markTestSkipped('This test can not run under HHVM');
31-
}
3229
if (null !== $body && in_array($method, ['GET', 'HEAD', 'TRACE'], true)) {
3330
static::markTestSkipped('cURL can not send body using '.$method);
3431
}
@@ -50,9 +47,6 @@ public function testSendRequestWithOutcome(
5047
array $headers,
5148
$body
5249
) {
53-
if (defined('HHVM_VERSION')) {
54-
static::markTestSkipped('This test can not run under HHVM');
55-
}
5650
if (null !== $body) {
5751
static::markTestSkipped('cURL can not send body using GET');
5852
}

0 commit comments

Comments
 (0)