|
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
|
|
|
|