Completed
Push — master ( bd4c23...b341c0 )
by Filipe
10:29
created

UriGeneratorSpec::it_is_initializable()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace spec\Slick\Mvc\Service;
4
5
use PhpSpec\ObjectBehavior;
6
use Psr\Http\Message\ServerRequestInterface;
7
use Slick\Http\Uri;
8
use Slick\Mvc\Service\UriGenerator;
9
use Slick\Mvc\Service\UriGeneratorInterface;
10
11
/**
12
 * UriGeneratorSpec
13
 *
14
 * @package spec\Slick\Mvc\Service
15
 * @author  Filipe Silva <[email protected]>
16
 */
17
class UriGeneratorSpec extends ObjectBehavior
18
{
19
    function it_is_initializable()
20
    {
21
        $this->shouldHaveType(UriGenerator::class);
22
    }
23
24
    function its_a_uri_generator()
25
    {
26
        $this->shouldImplement(UriGeneratorInterface::class);
27
    }
28
29
    function it_has_a_collection_of_location_transformers(
30
        UriGenerator\LocationTransformerInterface $transformer
31
    )
32
    {
33
        $this->addTransformer($transformer)->shouldBe($this->getWrappedObject());
34
    }
35
36
    function it_has_a_collection_of_uri_decorators(
37
        UriGenerator\UriDecoratorInterface $decorator
38
    )
39
    {
40
        $this->addDecorator($decorator)->shouldBe($this->getWrappedObject());
41
    }
42
43
    function it_cycles_through_the_transformers_to_generate_the_uri(
44
        UriGenerator\LocationTransformerInterface $transformerInactive,
45
        UriGenerator\LocationTransformerInterface $transformerActive,
46
        UriGenerator\UriDecoratorInterface $decorator
47
    )
48
    {
49
        $location = 'test';
50
        $options = ['foo' => 'bar'];
51
        $uri = new Uri();
52
        $transformerActive->transform($location, $options)
53
            ->shouldBeCalled()
54
            ->willReturn($uri);
55
56
        $this->addTransformer($transformerInactive)
57
            ->addTransformer($transformerActive);
58
        $this->addDecorator($decorator);
59
60
        $this->generate($location, $options)->shouldBe($uri);
61
62
        $transformerInactive->transform($location, $options)->shouldHaveBeenCalled();
63
        $decorator->decorate($uri)->shouldHaveBeenCalled();
64
    }
65
66
    function it_may_have_an_http_request_as_a_context(
67
        ServerRequestInterface $request,
68
        UriGenerator\LocationTransformerInterface $transformer
69
    )
70
    {
71
        $location = 'test';
72
        $options = ['foo' => 'bar'];
73
        $uri = new Uri();
74
        $transformer->transform($location, $options)
75
            ->shouldBeCalled()
76
            ->willReturn($uri);
77
        $transformer->setRequest($request)->shouldBeCalled();
78
79
        $this->setRequest($request)->shouldBe($this->getWrappedObject());
80
        $this->addTransformer($transformer);
81
        $this->generate($location, $options);
82
    }
83
}
84