|
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\FakeChannelCodeProviderInterface; |
|
16
|
|
|
use Sylius\Bundle\ChannelBundle\Context\FakeChannel\FakeChannelContext; |
|
17
|
|
|
use Sylius\Component\Channel\Context\ChannelContextInterface; |
|
18
|
|
|
use Sylius\Component\Channel\Context\ChannelNotFoundException; |
|
19
|
|
|
use Sylius\Component\Channel\Model\ChannelInterface; |
|
20
|
|
|
use Sylius\Component\Channel\Repository\ChannelRepositoryInterface; |
|
21
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
22
|
|
|
use Symfony\Component\HttpFoundation\RequestStack; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @mixin FakeChannelContext |
|
26
|
|
|
* |
|
27
|
|
|
* @author Kamil Kokot <[email protected]> |
|
28
|
|
|
*/ |
|
29
|
|
|
class FakeChannelContextSpec extends ObjectBehavior |
|
30
|
|
|
{ |
|
31
|
|
|
function let( |
|
32
|
|
|
FakeChannelCodeProviderInterface $fakeChannelCodeProvider, |
|
33
|
|
|
ChannelRepositoryInterface $channelRepository, |
|
34
|
|
|
RequestStack $requestStack |
|
35
|
|
|
) { |
|
36
|
|
|
$this->beConstructedWith($fakeChannelCodeProvider, $channelRepository, $requestStack); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
function it_is_initializable() |
|
40
|
|
|
{ |
|
41
|
|
|
$this->shouldHaveType('Sylius\Bundle\ChannelBundle\Context\FakeChannel\FakeChannelContext'); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
function it_implements_channel_context_interface() |
|
45
|
|
|
{ |
|
46
|
|
|
$this->shouldImplement(ChannelContextInterface::class); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
function it_returns_a_fake_channel_with_the_given_code( |
|
50
|
|
|
FakeChannelCodeProviderInterface $fakeChannelCodeProvider, |
|
51
|
|
|
ChannelRepositoryInterface $channelRepository, |
|
52
|
|
|
RequestStack $requestStack, |
|
53
|
|
|
Request $request, |
|
54
|
|
|
ChannelInterface $channel |
|
55
|
|
|
) { |
|
56
|
|
|
$requestStack->getMasterRequest()->willReturn($request); |
|
57
|
|
|
|
|
58
|
|
|
$fakeChannelCodeProvider->getCode($request)->willReturn('CHANNEL_CODE'); |
|
59
|
|
|
|
|
60
|
|
|
$channelRepository->findOneByCode('CHANNEL_CODE')->willReturn($channel); |
|
61
|
|
|
|
|
62
|
|
|
$this->getChannel()->shouldReturn($channel); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
function it_throws_a_channel_not_found_exception_if_there_is_no_master_request(RequestStack $requestStack) |
|
66
|
|
|
{ |
|
67
|
|
|
$requestStack->getMasterRequest()->willReturn(null); |
|
68
|
|
|
|
|
69
|
|
|
$this->shouldThrow(ChannelNotFoundException::class)->during('getChannel'); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
function it_throws_a_channel_not_found_exception_if_channel_with_given_code_was_not_found( |
|
73
|
|
|
FakeChannelCodeProviderInterface $fakeChannelCodeProvider, |
|
74
|
|
|
ChannelRepositoryInterface $channelRepository, |
|
75
|
|
|
RequestStack $requestStack, |
|
76
|
|
|
Request $request |
|
77
|
|
|
) { |
|
78
|
|
|
$requestStack->getMasterRequest()->willReturn($request); |
|
79
|
|
|
|
|
80
|
|
|
$fakeChannelCodeProvider->getCode($request)->willReturn('CHANNEL_CODE'); |
|
81
|
|
|
|
|
82
|
|
|
$channelRepository->findOneByCode('CHANNEL_CODE')->willReturn(null); |
|
83
|
|
|
|
|
84
|
|
|
$this->shouldThrow(ChannelNotFoundException::class)->during('getChannel'); |
|
85
|
|
|
} |
|
86
|
|
|
} |
|
87
|
|
|
|