Completed
Push — 1.0-reliable-behat ( 67387b )
by Kamil
55:32 queued 21:17
created

it_implements_channel_context_interface()   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
nc 1
cc 1
eloc 2
nop 0
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
final class CompositeChannelContextSpec extends ObjectBehavior
22
{
23
    function it_implements_channel_context_interface(): void
24
    {
25
        $this->shouldImplement(ChannelContextInterface::class);
26
    }
27
28
    function it_throws_a_channel_not_found_exception_if_there_are_no_nested_channel_contexts_defined(): void
29
    {
30
        $this->shouldThrow(ChannelNotFoundException::class)->during('getChannel');
31
    }
32
33
    function it_throws_a_channel_not_found_exception_if_none_of_nested_channel_contexts_returned_a_channel(
34
        ChannelContextInterface $channelContext
35
    ): void {
36
        $channelContext->getChannel()->willThrow(ChannelNotFoundException::class);
37
38
        $this->addContext($channelContext);
39
40
        $this->shouldThrow(ChannelNotFoundException::class)->during('getChannel');
41
    }
42
43
    function it_returns_first_result_returned_by_nested_request_resolvers(
44
        ChannelContextInterface $firstChannelContext,
45
        ChannelContextInterface $secondChannelContext,
46
        ChannelContextInterface $thirdChannelContext,
47
        ChannelInterface $channel
48
    ): void {
49
        $firstChannelContext->getChannel()->willThrow(ChannelNotFoundException::class);
50
        $secondChannelContext->getChannel()->willReturn($channel);
51
        $thirdChannelContext->getChannel()->shouldNotBeCalled();
52
53
        $this->addContext($firstChannelContext);
54
        $this->addContext($secondChannelContext);
55
        $this->addContext($thirdChannelContext);
56
57
        $this->getChannel()->shouldReturn($channel);
58
    }
59
60
    function its_nested_request_resolvers_can_have_priority(
61
        ChannelContextInterface $firstChannelContext,
62
        ChannelContextInterface $secondChannelContext,
63
        ChannelContextInterface $thirdChannelContext,
64
        ChannelInterface $channel
65
    ): void {
66
        $firstChannelContext->getChannel()->shouldNotBeCalled();
67
        $secondChannelContext->getChannel()->willReturn($channel);
68
        $thirdChannelContext->getChannel()->willThrow(ChannelNotFoundException::class);
69
70
        $this->addContext($firstChannelContext, -5);
71
        $this->addContext($secondChannelContext, 0);
72
        $this->addContext($thirdChannelContext, 5);
73
74
        $this->getChannel()->shouldReturn($channel);
75
    }
76
}
77