MockHttpAdapter   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 1
dl 0
loc 64
ccs 18
cts 18
cp 1
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A reset() 0 5 1
A getReceivedRequests() 0 4 1
A getQueuedResponses() 0 4 1
A appendResponse() 0 4 1
A getName() 0 4 1
A sendInternalRequest() 0 10 2
1
<?php
2
3
/*
4
 * This file is part of the Ivory Http Adapter package.
5
 *
6
 * (c) Eric GELOEN <[email protected]>
7
 *
8
 * For the full copyright and license information, please read the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Ivory\HttpAdapter;
13
14
use Ivory\HttpAdapter\Message\InternalRequestInterface;
15
use Psr\Http\Message\ResponseInterface;
16
17
/**
18
 * @author GeLo <[email protected]>
19
 * @author Timothée Barray <[email protected]>
20
 */
21
class MockHttpAdapter extends AbstractHttpAdapter
22
{
23
    /**
24
     * @var array
25
     */
26
    private $queuedResponses = [];
27
28
    /**
29
     * @var array
30
     */
31
    private $receivedRequests = [];
32
33 9
    public function reset()
34
    {
35 9
        $this->receivedRequests = [];
36 9
        $this->queuedResponses = [];
37 9
    }
38
39
    /**
40
     * @return array
41
     */
42 27
    public function getReceivedRequests()
43
    {
44 27
        return $this->receivedRequests;
45
    }
46
47
    /**
48
     * @return array
49
     */
50 36
    public function getQueuedResponses()
51
    {
52 36
        return $this->queuedResponses;
53
    }
54
55
    /**
56
     * @param ResponseInterface $response
57
     */
58 27
    public function appendResponse(ResponseInterface $response)
59
    {
60 27
        $this->queuedResponses[] = $response;
61 27
    }
62
63
    /**
64
     * {@inheritdoc}
65
     */
66 9
    public function getName()
67
    {
68 9
        return 'mock';
69
    }
70
71
    /**
72
     * {@inheritdoc}
73
     */
74 27
    protected function sendInternalRequest(InternalRequestInterface $internalRequest)
75
    {
76 27
        if (count($this->queuedResponses) <= 0) {
77 9
            throw new \OutOfBoundsException('You must append a response in the queue before sending a request.');
78
        }
79
80 18
        $this->receivedRequests[] = $internalRequest;
81
82 18
        return array_shift($this->queuedResponses);
83
    }
84
}
85