Skip to content

Commit 65d6251

Browse files
author
Pavel Batanov
committed
Fix php 7.2 test error
1 parent 799998f commit 65d6251

File tree

2 files changed

+54
-17
lines changed

2 files changed

+54
-17
lines changed

JsonRpc/Tests/AbstractJsonRpcClientTest.php

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use GuzzleHttp\Client;
66
use GuzzleHttp\ClientInterface;
77
use GuzzleHttp\Exception\GuzzleException;
8-
use GuzzleHttp\Handler\MockHandler;
98
use GuzzleHttp\HandlerStack;
109
use GuzzleHttp\Psr7\Response;
1110
use ScayTrase\Api\JsonRpc\JsonRpcNotification;
@@ -21,14 +20,16 @@ abstract class AbstractJsonRpcClientTest extends \PHPUnit_Framework_TestCase
2120

2221
protected function setUp()
2322
{
24-
$this->queue = null;
23+
$this->queue = null;
2524
$this->client = null;
2625
parent::setUp();
2726
}
2827

2928
protected function tearDown()
3029
{
31-
self::assertEquals(0, $this->getQueue()->count());
30+
if (null !== $this->queue) {
31+
self::assertEquals(0, $this->getQueue()->count());
32+
}
3233
parent::tearDown();
3334
}
3435

@@ -38,14 +39,15 @@ protected function getQueue()
3839
if (null === $this->queue) {
3940
$this->queue = new MockHandler();
4041
}
42+
4143
return $this->queue;
4244
}
4345

4446
/** @return ClientInterface */
4547
protected function getClient()
4648
{
4749
if (null === $this->client) {
48-
$handler = HandlerStack::create($this->getQueue());
50+
$handler = HandlerStack::create($this->getQueue());
4951
$this->client = new Client(['handler' => $handler]);
5052
}
5153

@@ -66,14 +68,16 @@ protected function createRequestForSingleInvocation($method, array $parameters,
6668
200,
6769
[],
6870
json_encode(
69-
[[
70-
'jsonrpc' => '2.0',
71-
'id' => $hash,
72-
'error' => [
73-
'code' => $result->getCode(),
74-
'message' => $result->getMessage()
75-
]
76-
]]
71+
[
72+
[
73+
'jsonrpc' => '2.0',
74+
'id' => $hash,
75+
'error' => [
76+
'code' => $result->getCode(),
77+
'message' => $result->getMessage(),
78+
],
79+
],
80+
]
7781
)
7882
)
7983
);
@@ -83,11 +87,13 @@ protected function createRequestForSingleInvocation($method, array $parameters,
8387
200,
8488
[],
8589
json_encode(
86-
[[
87-
'jsonrpc' => '2.0',
88-
'id' => $hash,
89-
'result' => $result
90-
]]
90+
[
91+
[
92+
'jsonrpc' => '2.0',
93+
'id' => $hash,
94+
'result' => $result,
95+
],
96+
]
9197
)
9298
)
9399
);

JsonRpc/Tests/MockHandler.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
namespace ScayTrase\Api\JsonRpc\Tests;
4+
5+
use GuzzleHttp\Handler\MockHandler as GuzzleMockHandler;
6+
7+
class MockHandler extends GuzzleMockHandler
8+
{
9+
private $append = false;
10+
11+
/**
12+
* Prevent empty queue being countable (PHP 7.2)
13+
*
14+
* @see https://github.com/guzzle/guzzle/pull/1809
15+
*/
16+
public function append()
17+
{
18+
$this->append = true;
19+
20+
return call_user_func_array(['parent', 'append'], func_get_args());
21+
}
22+
23+
public function count()
24+
{
25+
if (!$this->append) {
26+
return 0;
27+
}
28+
29+
return parent::count();
30+
}
31+
}

0 commit comments

Comments
 (0)