Completed
Push — scalar-types/currency ( d4a290...08e1db )
by Kamil
25:05 queued 02:52
created

FakeChannelContextSpec   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 6
dl 0
loc 68
rs 10
c 0
b 0
f 0

6 Methods

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