Completed
Push — master ( c85e73...41284f )
by Dmitry
02:55
created

DispatcherTest   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 1
lcom 1
cbo 7
dl 0
loc 49
rs 10
c 1
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B test() 0 44 1
1
<?php
2
3
namespace Test;
4
5
use Basis\Test;
6
use GuzzleHttp\Client;
7
use GuzzleHttp\Exception\RequestException;
8
use GuzzleHttp\Handler\MockHandler;
9
use GuzzleHttp\HandlerStack;
10
use GuzzleHttp\Middleware;
11
use GuzzleHttp\Psr7\Request;
12
use GuzzleHttp\Psr7\Response;
13
14
class DispatcherTest extends Test
15
{
16
    public $disableRemote = false;
17
18
    public function test()
19
    {
20
        $container = [];
21
        $mock = new MockHandler();
22
23
        $handler = HandlerStack::create($mock);
24
        $handler->push(Middleware::history($container));
25
26
        $client = new Client(['handler' => $handler]);
27
        $this->app->share(Client::class, $client);
28
29
        $mock->append(
30
            new Response(200, [], json_encode([
31
                'success' => true,
32
                'data' => ['mocked' => true]
33
            ]))
34
        );
35
36
        $result = $this->app->dispatch('service.hello');
0 ignored issues
show
Unused Code introduced by
$result is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
37
38
        $mock->append(
39
            new Response(200, [], json_encode([
40
                'success' => true,
41
                'data' => [
42
                    ['message' => 'hello, nekufa'],
43
                    ['message' => 'hello, rybakit'],
44
                ]
45
            ]))
46
        );
47
48
        $results = $this->app->dispatch('service.hello', [['name' => 'nekufa'], ['name' => 'rybakit']]);
49
        $this->assertCount(2, $results);
50
51
        $this->assertCount(2, $container);
52
        $body = json_encode([
53
            'job' => 'service.hello',
54
            'params' => [
55
                ['name' => 'nekufa'],
56
                ['name' => 'rybakit']
57
            ]
58
        ]);
59
60
        $this->assertNotEquals(-1, strpos($container[1]['request']->getBody(), $body));
61
    }
62
}
63