Completed
Push — master ( 5bd0a6...5cfde8 )
by Kamil
20:21
created

FakeChannelCodeProviderSpec   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 0
cbo 3
dl 0
loc 48
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A it_is_initializable() 0 4 1
A it_implements_channel_code_provider_interface() 0 4 1
A it_returns_fake_channel_code_from_query_string() 0 7 1
A it_returns_fake_channel_code_from_cookie_if_there_is_none_in_query_string() 0 13 1
A it_returns_null_channel_code_if_no_fake_channel_code_was_found() 0 13 1
1
<?php
2
3
/*
4
 * This file is part of the Sylius package.
5
 *
6
 * (c) Paweł Jędrzejewski
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace spec\Sylius\Bundle\ChannelBundle\Context\FakeChannel;
13
14
use PhpSpec\ObjectBehavior;
15
use Sylius\Bundle\ChannelBundle\Context\FakeChannel\FakeChannelCodeProvider;
16
use Sylius\Bundle\ChannelBundle\Context\FakeChannel\FakeChannelCodeProviderInterface;
17
use Symfony\Component\HttpFoundation\ParameterBag;
18
use Symfony\Component\HttpFoundation\Request;
19
20
/**
21
 * @mixin FakeChannelCodeProvider
22
 *
23
 * @author Kamil Kokot <[email protected]>
24
 */
25
class FakeChannelCodeProviderSpec extends ObjectBehavior
26
{
27
    function it_is_initializable()
28
    {
29
        $this->shouldHaveType('Sylius\Bundle\ChannelBundle\Context\FakeChannel\FakeChannelCodeProvider');
30
    }
31
32
    function it_implements_channel_code_provider_interface()
33
    {
34
        $this->shouldImplement(FakeChannelCodeProviderInterface::class);
35
    }
36
37
    function it_returns_fake_channel_code_from_query_string(Request $request, ParameterBag $queryBag)
38
    {
39
        $queryBag->get('_channel_code')->willReturn('channel_code_form_get');
40
        $request->query = $queryBag;
41
42
        $this->getCode($request)->shouldReturn('channel_code_form_get');
43
    }
44
45
    function it_returns_fake_channel_code_from_cookie_if_there_is_none_in_query_string(
46
        Request $request,
47
        ParameterBag $queryBag,
48
        ParameterBag $cookiesBag
49
    ) {
50
        $queryBag->get('_channel_code')->willReturn(null);
51
        $request->query = $queryBag;
52
53
        $cookiesBag->get('_channel_code')->willReturn('channel_code_form_cookie');
54
        $request->cookies = $cookiesBag;
55
56
        $this->getCode($request)->shouldReturn('channel_code_form_cookie');
57
    }
58
59
    function it_returns_null_channel_code_if_no_fake_channel_code_was_found(
60
        Request $request,
61
        ParameterBag $queryBag,
62
        ParameterBag $cookiesBag
63
    ) {
64
        $queryBag->get('_channel_code')->willReturn(null);
65
        $request->query = $queryBag;
66
67
        $cookiesBag->get('_channel_code')->willReturn(null);
68
        $request->cookies = $cookiesBag;
69
70
        $this->getCode($request)->shouldReturn(null);
71
    }
72
}
73