Passed
Branch master (f61680)
by Pavel
02:38
created

LazyClientTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 5
dl 0
loc 41
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace ScayTrase\Api\Rpc\Tests;
4
5
use PHPUnit\Framework\TestCase;
6
use ScayTrase\Api\Rpc\Decorators\LazyRpcClient;
7
use ScayTrase\Api\Rpc\RpcRequestInterface;
8
use ScayTrase\Api\Rpc\RpcResponseInterface;
9
10
final class LazyClientTest extends TestCase
11
{
12
    use RpcRequestTrait;
13
14
    public function testLazyRequets()
15
    {
16
        $rq1 = $this->getRequestMock('/test1', ['param1' => 'test']);
17
        $rq2 = $this->getRequestMock('/test2', ['param2' => 'test']);
18
        $rq3 = $this->getRequestMock('/test3', ['param3' => 'test']);
19
20
        $rs1 = $this->getResponseMock(true, (object)['param1' => 'test']);
21
        $rs2 = $this->getResponseMock(true, (object)['param2' => 'test']);
22
        $rs3 = $this->getResponseMock(true, (object)['param3' => 'test']);
23
24
        /** @var RpcRequestInterface[] $requests */
25
        $requests = [$rq1, $rq2, $rq3];
26
        /** @var RpcResponseInterface[] $responses */
27
        $responses = [$rs1, $rs2, $rs3];
28
29
        $client = $this->getClientMock($requests, $responses);
30
31
        $lazyClient = new LazyRpcClient($client);
32
33
        $c1 = $lazyClient->invoke($rq1);
34
        $c2 = $lazyClient->invoke($rq2);
35
        $c3 = $lazyClient->invoke($rq3);
36
37
        self::assertEquals($c1, $c2);
38
        self::assertEquals($c1, $c3);
39
40
        foreach ($requests as $id => $request) {
41
42
            $response = $c1->getResponse($request);
43
44
            self::assertNotNull($response);
45
            self::assertTrue($c1->isFrozen());
46
            self::assertEquals($response, $responses[$id]);
47
            self::assertTrue($response->isSuccessful());
48
            self::assertInstanceOf(\stdClass::class, $response->getBody());
49
            self::assertEquals($request->getParameters(), $response->getBody());
50
        }
51
    }
52
}
53