Completed
Branch master (5571d6)
by Filipe
01:34
created

UriGeneratorSpec   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

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