1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* This file is part of Guzzle HTTP JSON-RPC |
4
|
|
|
* |
5
|
|
|
* Copyright (c) 2014 Nature Delivered Ltd. <http://graze.com> |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
* |
10
|
|
|
* @see http://github.com/graze/guzzle-jsonrpc/blob/master/LICENSE |
11
|
|
|
* @link http://github.com/graze/guzzle-jsonrpc |
12
|
|
|
*/ |
13
|
|
|
namespace Graze\GuzzleHttp\JsonRpc; |
14
|
|
|
|
15
|
|
|
use Graze\GuzzleHttp\JsonRpc\Test\FunctionalTestCase; |
16
|
|
|
use GuzzleHttp\Promise\PromiseInterface; |
17
|
|
|
|
18
|
|
|
class NotificationFunctionalTest extends FunctionalTestCase |
19
|
|
|
{ |
20
|
|
|
/** @var Client */ |
21
|
|
|
private $client; |
22
|
|
|
|
23
|
|
|
public function setUp() |
24
|
|
|
{ |
25
|
|
|
$this->client = $this->createClient(); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
View Code Duplication |
public function testNotifyRequest() |
|
|
|
|
29
|
|
|
{ |
30
|
|
|
$method = 'notify'; |
31
|
|
|
$params = ['foo'=>true]; |
32
|
|
|
$request = $this->client->notification($method, $params); |
33
|
|
|
$response = $this->client->send($request); |
34
|
|
|
|
35
|
|
|
$this->assertEquals(ClientInterface::SPEC, $request->getRpcVersion()); |
36
|
|
|
$this->assertEquals(null, $request->getRpcId()); |
37
|
|
|
$this->assertEquals($method, $request->getRpcMethod()); |
38
|
|
|
$this->assertEquals($params, $request->getRpcParams()); |
39
|
|
|
|
40
|
|
|
$this->assertNull($response); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
View Code Duplication |
public function testAsyncNotifyRequest() |
|
|
|
|
44
|
|
|
{ |
45
|
|
|
$method = 'notify'; |
46
|
|
|
$params = ['foo'=>true]; |
47
|
|
|
$request = $this->client->notification($method, $params); |
48
|
|
|
$promise = $this->client->sendAsync($request); |
49
|
|
|
|
50
|
|
|
$promise->then(function ($response) use ($request, $method, $params) { |
51
|
|
|
$this->assertEquals(ClientInterface::SPEC, $request->getRpcVersion()); |
52
|
|
|
$this->assertEquals(null, $request->getRpcId()); |
53
|
|
|
$this->assertEquals($method, $request->getRpcMethod()); |
54
|
|
|
$this->assertEquals($params, $request->getRpcParams()); |
55
|
|
|
|
56
|
|
|
$this->assertNull($response); |
57
|
|
|
})->wait(); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
View Code Duplication |
public function testNotifyRequestWithInvalidParams() |
|
|
|
|
61
|
|
|
{ |
62
|
|
|
$method = 'notify'; |
63
|
|
|
$params = ['foo'=>'bar']; |
64
|
|
|
$request = $this->client->notification($method, $params); |
65
|
|
|
$response = $this->client->send($request); |
66
|
|
|
|
67
|
|
|
$this->assertEquals(ClientInterface::SPEC, $request->getRpcVersion()); |
68
|
|
|
$this->assertEquals(null, $request->getRpcId()); |
69
|
|
|
$this->assertEquals($method, $request->getRpcMethod()); |
70
|
|
|
$this->assertEquals($params, $request->getRpcParams()); |
71
|
|
|
|
72
|
|
|
$this->assertNull($response); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
View Code Duplication |
public function testAsyncNotifyRequestWithInvalidParams() |
|
|
|
|
76
|
|
|
{ |
77
|
|
|
$method = 'notify'; |
78
|
|
|
$params = ['foo'=>'bar']; |
79
|
|
|
$request = $this->client->notification($method, $params); |
80
|
|
|
$promise = $this->client->sendAsync($request); |
81
|
|
|
|
82
|
|
|
$promise->then(function ($response) use ($request, $method, $params) { |
83
|
|
|
$this->assertEquals(ClientInterface::SPEC, $request->getRpcVersion()); |
84
|
|
|
$this->assertEquals(null, $request->getRpcId()); |
85
|
|
|
$this->assertEquals($method, $request->getRpcMethod()); |
86
|
|
|
$this->assertEquals($params, $request->getRpcParams()); |
87
|
|
|
|
88
|
|
|
$this->assertNull($response); |
89
|
|
|
})->wait(); |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.