Completed
Push — master ( 15b4cf...ad9d4e )
by
unknown
08:03
created

MockResolver::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 2
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace SilverStripe\View\Tests\Shortcodes;
4
5
use Embed\Http\DispatcherInterface;
6
use Embed\Http\ImageResponse;
7
use Embed\Http\Response;
8
use Embed\Http\Url;
9
use InvalidArgumentException;
10
11
class MockResolver implements DispatcherInterface
12
{
13
    protected $url = null;
14
15
    protected $expectedContent = null;
16
17
    /**
18
     * Constructor. Sets the url.
19
     *
20
     * @param string $url The url value
21
     * @param array $config The resolver configuration
22
     */
23
    public function __construct($url, array $config)
24
    {
25
        $this->url = $url;
26
        if (empty($config['expectedContent'])) {
27
            throw new InvalidArgumentException("Mock resolvers need expectedContent");
28
        }
29
        $this->expectedContent = $config['expectedContent'];
30
    }
31
32
    /**
33
     * Dispatch an url.
34
     *
35
     * @param Url $url
36
     *
37
     * @return Response
38
     */
39
    public function dispatch(Url $url)
40
    {
41
        return new Response(
42
            $url,
43
            $url,
44
            200,
45
            'application/json',
46
            $this->expectedContent,
47
            [],
48
            []
49
        );
50
    }
51
52
    /**
53
     * Resolve multiple image urls at once.
54
     *
55
     * @param Url[] $urls
56
     *
57
     * @return ImageResponse[]
58
     */
59
    public function dispatchImages(array $urls)
60
    {
61
        return [];
62
    }
63
}
64