Completed
Push — master ( c4d705...5571d6 )
by Filipe
03:31
created

FullUrlTransformerSpec::getMatchers()   A

Complexity

Conditions 3
Paths 1

Size

Total Lines 21
Code Lines 12

Duplication

Lines 21
Ratio 100 %

Importance

Changes 0
Metric Value
dl 21
loc 21
rs 9.3142
c 0
b 0
f 0
cc 3
eloc 12
nc 1
nop 0
1
<?php
2
3
/**
4
 * This file is part of slick/web_stack package
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
namespace spec\Slick\WebStack\Service\UriGenerator\Transformer;
11
12
use PhpSpec\Exception\Example\FailureException;
13
use Psr\Http\Message\UriInterface;
14
use Slick\WebStack\Service\UriGenerator\LocationTransformerInterface;
15
use Slick\WebStack\Service\UriGenerator\Transformer\FullUrlTransformer;
16
use PhpSpec\ObjectBehavior;
17
18
/**
19
 * FullUrlTransformerSpec specs
20
 *
21
 * @package spec\Slick\WebStack\Service\UriGenerator\Transformer
22
 */
23
class FullUrlTransformerSpec extends ObjectBehavior
24
{
25
    function it_is_initializable()
26
    {
27
        $this->shouldHaveType(FullUrlTransformer::class);
28
    }
29
30
    function its_a_location_transformer()
31
    {
32
        $this->shouldBeAnInstanceOf(LocationTransformerInterface::class);
33
    }
34
35
    function it_returns_the_passed_location_when_its_a_full_URL()
36
    {
37
        $this->transform('http://test.com/path')
38
            ->shouldBeAnUriLike('http://test.com/path');
39
    }
40
41
    public function getMatchers()
42
    {
43
        return [
44
            'beAnUriLike' => function ($uri, $path)
45
            {
46
                if (!$uri instanceof UriInterface) {
47
                    $class = UriInterface::class;
48
                    $type = gettype($uri);
49
                    throw new FailureException(
50
                        "Expected {$class} instance, but got '{$type}'"
51
                    );
52
                }
53
                if ($uri->__toString() !== $path) {
54
                    throw new FailureException(
55
                        "Expected URI with path '{$path}', but got '{$uri}'"
56
                    );
57
                }
58
                return true;
59
            }
60
        ];
61
    }
62
}