Completed
Push — scalar-types/currency ( d4a290...08e1db )
by Kamil
25:05 queued 02:52
created

CompositeChannelContextSpec   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 3
dl 0
loc 56
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A it_implements_channel_context_interface() 0 4 1
A it_throws_a_channel_not_found_exception_if_there_are_no_nested_channel_contexts_defined() 0 4 1
A it_throws_a_channel_not_found_exception_if_none_of_nested_channel_contexts_returned_a_channel() 0 9 1
A it_returns_first_result_returned_by_nested_request_resolvers() 0 16 1
A its_nested_request_resolvers_can_have_priority() 0 16 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
declare(strict_types=1);
13
14
namespace spec\Sylius\Component\Channel\Context;
15
16
use PhpSpec\ObjectBehavior;
17
use Sylius\Component\Channel\Context\ChannelContextInterface;
18
use Sylius\Component\Channel\Context\ChannelNotFoundException;
19
use Sylius\Component\Channel\Model\ChannelInterface;
20
21
/**
22
 * @author Kamil Kokot <[email protected]>
23
 */
24
final class CompositeChannelContextSpec extends ObjectBehavior
25
{
26
    function it_implements_channel_context_interface(): void
27
    {
28
        $this->shouldImplement(ChannelContextInterface::class);
29
    }
30
31
    function it_throws_a_channel_not_found_exception_if_there_are_no_nested_channel_contexts_defined(): void
32
    {
33
        $this->shouldThrow(ChannelNotFoundException::class)->during('getChannel');
34
    }
35
36
    function it_throws_a_channel_not_found_exception_if_none_of_nested_channel_contexts_returned_a_channel(
37
        ChannelContextInterface $channelContext
38
    ): void {
39
        $channelContext->getChannel()->willThrow(ChannelNotFoundException::class);
40
41
        $this->addContext($channelContext);
42
43
        $this->shouldThrow(ChannelNotFoundException::class)->during('getChannel');
44
    }
45
46
    function it_returns_first_result_returned_by_nested_request_resolvers(
47
        ChannelContextInterface $firstChannelContext,
48
        ChannelContextInterface $secondChannelContext,
49
        ChannelContextInterface $thirdChannelContext,
50
        ChannelInterface $channel
51
    ): void {
52
        $firstChannelContext->getChannel()->willThrow(ChannelNotFoundException::class);
53
        $secondChannelContext->getChannel()->willReturn($channel);
54
        $thirdChannelContext->getChannel()->shouldNotBeCalled();
55
56
        $this->addContext($firstChannelContext);
57
        $this->addContext($secondChannelContext);
58
        $this->addContext($thirdChannelContext);
59
60
        $this->getChannel()->shouldReturn($channel);
61
    }
62
63
    function its_nested_request_resolvers_can_have_priority(
64
        ChannelContextInterface $firstChannelContext,
65
        ChannelContextInterface $secondChannelContext,
66
        ChannelContextInterface $thirdChannelContext,
67
        ChannelInterface $channel
68
    ): void {
69
        $firstChannelContext->getChannel()->shouldNotBeCalled();
70
        $secondChannelContext->getChannel()->willReturn($channel);
71
        $thirdChannelContext->getChannel()->willThrow(ChannelNotFoundException::class);
72
73
        $this->addContext($firstChannelContext, -5);
74
        $this->addContext($secondChannelContext, 0);
75
        $this->addContext($thirdChannelContext, 5);
76
77
        $this->getChannel()->shouldReturn($channel);
78
    }
79
}
80