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

SingleChannelContextSpec   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 3
dl 0
loc 44
c 0
b 0
f 0
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A let() 0 4 1
A it_implements_channel_context_interface() 0 4 1
A it_returns_a_channel_if_it_is_the_only_one_defined() 0 8 1
A it_throws_a_channel_not_found_exception_if_there_are_no_channels_defined() 0 7 1
A it_throws_a_channel_not_found_exception_if_there_are_many_channels_defined() 0 9 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\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
use Sylius\Component\Channel\Repository\ChannelRepositoryInterface;
21
22
/**
23
 * @author Kamil Kokot <[email protected]>
24
 */
25
final class SingleChannelContextSpec extends ObjectBehavior
26
{
27
    function let(ChannelRepositoryInterface $channelRepository): void
28
    {
29
        $this->beConstructedWith($channelRepository);
30
    }
31
32
    function it_implements_channel_context_interface(): void
33
    {
34
        $this->shouldImplement(ChannelContextInterface::class);
35
    }
36
37
    function it_returns_a_channel_if_it_is_the_only_one_defined(
38
        ChannelRepositoryInterface $channelRepository,
39
        ChannelInterface $channel
40
    ): void {
41
        $channelRepository->findAll()->willReturn([$channel]);
42
43
        $this->getChannel()->shouldReturn($channel);
44
    }
45
46
    function it_throws_a_channel_not_found_exception_if_there_are_no_channels_defined(
47
        ChannelRepositoryInterface $channelRepository
48
    ): void {
49
        $channelRepository->findAll()->willReturn([]);
50
51
        $this->shouldThrow(ChannelNotFoundException::class)->during('getChannel');
52
    }
53
54
    function it_throws_a_channel_not_found_exception_if_there_are_many_channels_defined(
55
        ChannelRepositoryInterface $channelRepository,
56
        ChannelInterface $firstChannel,
57
        ChannelInterface $secondChannel
58
    ): void {
59
        $channelRepository->findAll()->willReturn([$firstChannel, $secondChannel]);
60
61
        $this->shouldThrow(ChannelNotFoundException::class)->during('getChannel');
62
    }
63
}
64