|
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\RequestBased; |
|
15
|
|
|
|
|
16
|
|
|
use PhpSpec\ObjectBehavior; |
|
17
|
|
|
use Sylius\Component\Channel\Context\ChannelContextInterface; |
|
18
|
|
|
use Sylius\Component\Channel\Context\ChannelNotFoundException; |
|
19
|
|
|
use Sylius\Component\Channel\Context\RequestBased\RequestResolverInterface; |
|
20
|
|
|
use Sylius\Component\Channel\Model\ChannelInterface; |
|
21
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
22
|
|
|
use Symfony\Component\HttpFoundation\RequestStack; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @author Kamil Kokot <[email protected]> |
|
26
|
|
|
*/ |
|
27
|
|
|
final class ChannelContextSpec extends ObjectBehavior |
|
28
|
|
|
{ |
|
29
|
|
|
function let(RequestResolverInterface $requestResolver, RequestStack $requestStack): void |
|
30
|
|
|
{ |
|
31
|
|
|
$this->beConstructedWith($requestResolver, $requestStack); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
function it_implements_channel_context_interface(): void |
|
35
|
|
|
{ |
|
36
|
|
|
$this->shouldImplement(ChannelContextInterface::class); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
function it_proxies_master_request_to_request_resolver( |
|
40
|
|
|
RequestResolverInterface $requestResolver, |
|
41
|
|
|
RequestStack $requestStack, |
|
42
|
|
|
Request $masterRequest, |
|
43
|
|
|
ChannelInterface $channel |
|
44
|
|
|
): void { |
|
45
|
|
|
$requestStack->getMasterRequest()->willReturn($masterRequest); |
|
46
|
|
|
|
|
47
|
|
|
$requestResolver->findChannel($masterRequest)->willReturn($channel); |
|
48
|
|
|
|
|
49
|
|
|
$this->getChannel()->shouldReturn($channel); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
function it_throws_a_channel_not_found_exception_if_request_resolver_returns_null( |
|
53
|
|
|
RequestResolverInterface $requestResolver, |
|
54
|
|
|
RequestStack $requestStack, |
|
55
|
|
|
Request $masterRequest |
|
56
|
|
|
): void { |
|
57
|
|
|
$requestStack->getMasterRequest()->willReturn($masterRequest); |
|
58
|
|
|
|
|
59
|
|
|
$requestResolver->findChannel($masterRequest)->willReturn(null); |
|
60
|
|
|
|
|
61
|
|
|
$this->shouldThrow(ChannelNotFoundException::class)->during('getChannel'); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
function it_throws_a_channel_not_found_exception_if_there_is_no_master_request( |
|
65
|
|
|
RequestStack $requestStack |
|
66
|
|
|
): void { |
|
67
|
|
|
$requestStack->getMasterRequest()->willReturn(null); |
|
68
|
|
|
|
|
69
|
|
|
$this->shouldThrow(ChannelNotFoundException::class)->during('getChannel'); |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
|