Completed
Pull Request — master (#30)
by Harry
02:53 queued 01:19
created

NotificationFunctionalTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
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();
0 ignored issues
show
Bug introduced by
The property client does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
22
    }
23
24
    public function tearDown()
25
    {
26
        if (isset($this->promise)) {
27
            $this->promise->wait(false); // Stop PHPUnit closing before async assertions
0 ignored issues
show
Bug introduced by
The property promise does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
28
            unset($this->promise);
29
        }
30
    }
31
32 View Code Duplication
    public function testNotifyRequest()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
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()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
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()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
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()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
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