|
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'); |
|
|
|
|
|
|
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
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.