NotificationFunctionalTest   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 43
c 1
b 0
f 0
dl 0
loc 72
rs 10
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A testAsyncNotifyRequestWithInvalidParams() 0 15 1
A testAsyncNotifyRequest() 0 15 1
A setUp() 0 3 1
A testNotifyRequestWithInvalidParams() 0 13 1
A testNotifyRequest() 0 13 1
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
    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
    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
    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
    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