Passed
Push — 4 ( 35dfb3...cb05e5 )
by Maxime
07:42 queued 14s
created

MockResponse   A

Complexity

Total Complexity 16

Size/Duplication

Total Lines 81
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 18
c 1
b 0
f 0
dl 0
loc 81
rs 10
wmc 16

15 Methods

Rating   Name   Duplication   Size   Complexity  
A getReasonPhrase() 0 2 1
A withBody() 0 3 1
A getBody() 0 8 2
A withAddedHeader() 0 3 1
A hasHeader() 0 2 1
A __construct() 0 5 1
A getHeaderLine() 0 2 1
A withStatus() 0 3 1
A withProtocolVersion() 0 3 1
A getHeader() 0 2 1
A withHeader() 0 3 1
A withoutHeader() 0 3 1
A getProtocolVersion() 0 2 1
A getStatusCode() 0 3 1
A getHeaders() 0 2 1
1
<?php
2
3
namespace SilverStripe\View\Tests\Embed;
4
5
use Psr\Http\Message\ResponseInterface;
6
use Psr\Http\Message\StreamInterface;
7
8
class MockResponse implements ResponseInterface
9
{
10
    private EmbedUnitTest $unitTest;
11
    private string $firstReponse;
0 ignored issues
show
introduced by
The private property $firstReponse is not used, and could be removed.
Loading history...
12
    private string $secondResponse;
13
14
    public function __construct(EmbedUnitTest $unitTest, string $firstResponse, string $secondResponse)
15
    {
16
        $this->unitTest = $unitTest;
17
        $this->firstResponse = $firstResponse;
0 ignored issues
show
Bug Best Practice introduced by
The property firstResponse does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
18
        $this->secondResponse = $secondResponse;
19
    }
20
21
    public function getStatusCode()
22
    {
23
        return 200;
24
    }
25
26
    public function getBody()
27
    {
28
        // first request is to the video HTML to get to find the oembed link
29
        // second request is to the oembed endpoint to fetch JSON
30
        if ($this->unitTest->getFirstRequest()) {
31
            return $this->firstResponse;
32
        } else {
33
            return $this->secondResponse;
34
        }
35
    }
36
37
    public function getReasonPhrase()
38
    {
39
    }
40
41
    public function getProtocolVersion()
42
    {
43
    }
44
45
    public function getHeaders()
46
    {
47
    }
48
49
    public function getHeader($name)
50
    {
51
    }
52
53
    public function getHeaderLine($name)
54
    {
55
    }
56
57
    public function hasHeader($name)
58
    {
59
    }
60
61
    public function withHeader($name, $value)
62
    {
63
        return $this;
64
    }
65
66
    public function withAddedHeader($name, $value)
67
    {
68
        return $this;
69
    }
70
71
    public function withBody(StreamInterface $body)
72
    {
73
        return $this;
74
    }
75
76
    public function withoutHeader($name)
77
    {
78
        return $this;
79
    }
80
81
    public function withProtocolVersion($version)
82
    {
83
        return $this;
84
    }
85
86
    public function withStatus($code, $reasonPhrase = '')
87
    {
88
        return $this;
89
    }
90
}
91