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\Component\Channel\Context; |
13
|
|
|
|
14
|
|
|
use PhpSpec\ObjectBehavior; |
15
|
|
|
use Sylius\Component\Channel\Context\CachedPerRequestChannelContext; |
16
|
|
|
use Sylius\Component\Channel\Context\ChannelContextInterface; |
17
|
|
|
use Sylius\Component\Channel\Model\ChannelInterface; |
18
|
|
|
use Symfony\Component\HttpFoundation\Request; |
19
|
|
|
use Symfony\Component\HttpFoundation\RequestStack; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @mixin CachedPerRequestChannelContext |
23
|
|
|
* |
24
|
|
|
* @author Kamil Kokot <[email protected]> |
25
|
|
|
*/ |
26
|
|
|
class CachedPerRequestChannelContextSpec extends ObjectBehavior |
27
|
|
|
{ |
28
|
|
|
function let(ChannelContextInterface $decoratedChannelContext, RequestStack $requestStack) |
29
|
|
|
{ |
30
|
|
|
$this->beConstructedWith($decoratedChannelContext, $requestStack); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
function it_is_initializable() |
34
|
|
|
{ |
35
|
|
|
$this->shouldHaveType('Sylius\Component\Channel\Context\CachedPerRequestChannelContext'); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
function it_implements_channel_context_interface() |
39
|
|
|
{ |
40
|
|
|
$this->shouldImplement(ChannelContextInterface::class); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
function it_caches_channels_for_the_same_request( |
44
|
|
|
ChannelContextInterface $decoratedChannelContext, |
45
|
|
|
RequestStack $requestStack, |
46
|
|
|
Request $request, |
47
|
|
|
ChannelInterface $channel |
48
|
|
|
) { |
49
|
|
|
$requestStack->getMasterRequest()->willReturn($request, $request); |
50
|
|
|
|
51
|
|
|
$decoratedChannelContext->getChannel()->willReturn($channel)->shouldBeCalledTimes(1); |
52
|
|
|
|
53
|
|
|
$this->getChannel()->shouldReturn($channel); |
54
|
|
|
$this->getChannel()->shouldReturn($channel); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
function it_does_not_cache_channels_for_different_requests( |
58
|
|
|
ChannelContextInterface $decoratedChannelContext, |
59
|
|
|
RequestStack $requestStack, |
60
|
|
|
Request $firstRequest, |
61
|
|
|
Request $secondRequest, |
62
|
|
|
ChannelInterface $firstChannel, |
63
|
|
|
ChannelInterface $secondChannel |
64
|
|
|
) { |
65
|
|
|
$requestStack->getMasterRequest()->willReturn($firstRequest, $secondRequest); |
66
|
|
|
|
67
|
|
|
$decoratedChannelContext->getChannel()->willReturn($firstChannel, $secondChannel); |
68
|
|
|
|
69
|
|
|
$this->getChannel()->shouldReturn($firstChannel); |
70
|
|
|
$this->getChannel()->shouldReturn($secondChannel); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
function it_caches_channels_for_the_same_request_even_if_there_are_other_request_in_between( |
74
|
|
|
ChannelContextInterface $decoratedChannelContext, |
75
|
|
|
RequestStack $requestStack, |
76
|
|
|
Request $firstRequest, |
77
|
|
|
Request $secondRequest, |
78
|
|
|
ChannelInterface $firstChannel, |
79
|
|
|
ChannelInterface $secondChannel |
80
|
|
|
) { |
81
|
|
|
$requestStack->getMasterRequest()->willReturn($firstRequest, $secondRequest, $firstRequest); |
82
|
|
|
|
83
|
|
|
$decoratedChannelContext->getChannel()->willReturn($firstChannel, $secondChannel)->shouldBeCalledTimes(2); |
84
|
|
|
|
85
|
|
|
$this->getChannel()->shouldReturn($firstChannel); |
86
|
|
|
$this->getChannel()->shouldReturn($secondChannel); |
87
|
|
|
$this->getChannel()->shouldReturn($firstChannel); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
function it_does_not_cache_results_while_there_are_no_master_requests( |
91
|
|
|
ChannelContextInterface $decoratedChannelContext, |
92
|
|
|
RequestStack $requestStack, |
93
|
|
|
ChannelInterface $firstChannel, |
94
|
|
|
ChannelInterface $secondChannel |
95
|
|
|
) { |
96
|
|
|
$requestStack->getMasterRequest()->willReturn(null, null); |
97
|
|
|
|
98
|
|
|
$decoratedChannelContext->getChannel()->willReturn($firstChannel, $secondChannel)->shouldBeCalledTimes(2); |
99
|
|
|
|
100
|
|
|
$this->getChannel()->shouldReturn($firstChannel); |
101
|
|
|
$this->getChannel()->shouldReturn($secondChannel); |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
|