Completed
Push — 1.0-conflict-with-twig10 ( 2d43e5 )
by Kamil
73:48 queued 41:54
created

ChannelBasedThemeContextSpec::let()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
nc 1
cc 1
eloc 2
nop 2
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\CoreBundle\Theme;
15
16
use PhpSpec\ObjectBehavior;
17
use Sylius\Bundle\ThemeBundle\Context\ThemeContextInterface;
18
use Sylius\Bundle\ThemeBundle\Model\ThemeInterface;
19
use Sylius\Bundle\ThemeBundle\Repository\ThemeRepositoryInterface;
20
use Sylius\Component\Channel\Context\ChannelContextInterface;
21
use Sylius\Component\Channel\Context\ChannelNotFoundException;
22
use Sylius\Component\Core\Model\ChannelInterface;
23
24
final class ChannelBasedThemeContextSpec extends ObjectBehavior
25
{
26
    function let(ChannelContextInterface $channelContext, ThemeRepositoryInterface $themeRepository): void
27
    {
28
        $this->beConstructedWith($channelContext, $themeRepository);
29
    }
30
31
    function it_implements_theme_context_interface(): void
32
    {
33
        $this->shouldImplement(ThemeContextInterface::class);
34
    }
35
36
    function it_returns_a_theme(
37
        ChannelContextInterface $channelContext,
38
        ThemeRepositoryInterface $themeRepository,
39
        ChannelInterface $channel,
40
        ThemeInterface $theme
41
    ): void {
42
        $channelContext->getChannel()->willReturn($channel);
43
        $channel->getThemeName()->willReturn('theme/name');
44
        $themeRepository->findOneByName('theme/name')->willReturn($theme);
45
46
        $this->getTheme()->shouldReturn($theme);
47
    }
48
49
    function it_returns_null_if_channel_has_no_theme(
50
        ChannelContextInterface $channelContext,
51
        ThemeRepositoryInterface $themeRepository,
52
        ChannelInterface $channel
53
    ): void {
54
        $channelContext->getChannel()->willReturn($channel);
55
        $channel->getThemeName()->willReturn(null);
56
        $themeRepository->findOneByName(null)->willReturn(null);
57
58
        $this->getTheme()->shouldReturn(null);
59
    }
60
61
    function it_returns_null_if_there_is_no_channel(
62
        ChannelContextInterface $channelContext
63
    ): void {
64
        $channelContext->getChannel()->willThrow(ChannelNotFoundException::class);
65
66
        $this->getTheme()->shouldReturn(null);
67
    }
68
69
    function it_returns_null_if_any_exception_is_thrown_during_getting_the_channel(
70
        ChannelContextInterface $channelContext
71
    ): void {
72
        $channelContext->getChannel()->willThrow(\Exception::class);
73
74
        $this->getTheme()->shouldReturn(null);
75
    }
76
}
77