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
|
|
|
|
17
|
|
|
class NotificationFunctionalTest extends FunctionalTestCase |
18
|
|
|
{ |
19
|
|
|
public function setUp() |
20
|
|
|
{ |
21
|
|
|
$this->client = $this->createClient(); |
|
|
|
|
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
public function tearDown() |
25
|
|
|
{ |
26
|
|
|
if (isset($this->promise)) { |
27
|
|
|
$this->promise->wait(false); // Stop PHPUnit closing before async assertions |
|
|
|
|
28
|
|
|
unset($this->promise); |
29
|
|
|
} |
30
|
|
|
} |
31
|
|
|
|
32
|
|
View Code Duplication |
public function testNotifyRequest() |
|
|
|
|
33
|
|
|
{ |
34
|
|
|
$method = 'notify'; |
35
|
|
|
$params = ['foo'=>true]; |
36
|
|
|
$request = $this->client->notification($method, $params); |
37
|
|
|
$response = $this->client->send($request); |
38
|
|
|
|
39
|
|
|
$this->assertEquals(ClientInterface::SPEC, $request->getRpcVersion()); |
40
|
|
|
$this->assertEquals(null, $request->getRpcId()); |
41
|
|
|
$this->assertEquals($method, $request->getRpcMethod()); |
42
|
|
|
$this->assertEquals($params, $request->getRpcParams()); |
43
|
|
|
|
44
|
|
|
$this->assertNull($response); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
View Code Duplication |
public function testAsyncNotifyRequest() |
|
|
|
|
48
|
|
|
{ |
49
|
|
|
$method = 'notify'; |
50
|
|
|
$params = ['foo'=>true]; |
51
|
|
|
$request = $this->client->notification($method, $params); |
52
|
|
|
$this->promise = $this->client->sendAsync($request); |
53
|
|
|
|
54
|
|
|
$this->promise->then(function ($response) use ($request, $method, $params) { |
55
|
|
|
$this->assertEquals(ClientInterface::SPEC, $request->getRpcVersion()); |
56
|
|
|
$this->assertEquals(null, $request->getRpcId()); |
57
|
|
|
$this->assertEquals($method, $request->getRpcMethod()); |
58
|
|
|
$this->assertEquals($params, $request->getRpcParams()); |
59
|
|
|
|
60
|
|
|
$this->assertNull($response); |
61
|
|
|
}); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
View Code Duplication |
public function testNotifyRequestWithInvalidParams() |
|
|
|
|
65
|
|
|
{ |
66
|
|
|
$method = 'notify'; |
67
|
|
|
$params = ['foo'=>'bar']; |
68
|
|
|
$request = $this->client->notification($method, $params); |
69
|
|
|
$response = $this->client->send($request); |
70
|
|
|
|
71
|
|
|
$this->assertEquals(ClientInterface::SPEC, $request->getRpcVersion()); |
72
|
|
|
$this->assertEquals(null, $request->getRpcId()); |
73
|
|
|
$this->assertEquals($method, $request->getRpcMethod()); |
74
|
|
|
$this->assertEquals($params, $request->getRpcParams()); |
75
|
|
|
|
76
|
|
|
$this->assertNull($response); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
View Code Duplication |
public function testAsyncNotifyRequestWithInvalidParams() |
|
|
|
|
80
|
|
|
{ |
81
|
|
|
$method = 'notify'; |
82
|
|
|
$params = ['foo'=>'bar']; |
83
|
|
|
$request = $this->client->notification($method, $params); |
84
|
|
|
$this->promise = $this->client->sendAsync($request); |
85
|
|
|
|
86
|
|
|
$this->promise->then(function ($response) use ($request, $method, $params) { |
87
|
|
|
$this->assertEquals(ClientInterface::SPEC, $request->getRpcVersion()); |
88
|
|
|
$this->assertEquals(null, $request->getRpcId()); |
89
|
|
|
$this->assertEquals($method, $request->getRpcMethod()); |
90
|
|
|
$this->assertEquals($params, $request->getRpcParams()); |
91
|
|
|
|
92
|
|
|
$this->assertNull($response); |
93
|
|
|
}); |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
|
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: