Completed
Push — locale-in-url ( 151bbf...6507a9 )
by Kamil
20:45
created

StorageBasedLocaleContextSpec   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 4
dl 0
loc 50
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A let() 0 7 1
A it_is_initializable() 0 4 1
A it_is_a_locale_context() 0 4 1
A it_returns_an_available_active_locale() 0 14 1
A it_throws_an_exception_if_locale_taken_from_storage_is_not_available() 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
namespace spec\Sylius\Component\Core\Context;
13
14
use PhpSpec\ObjectBehavior;
15
use Sylius\Component\Channel\Context\ChannelContextInterface;
16
use Sylius\Component\Channel\Model\ChannelInterface;
17
use Sylius\Component\Core\Locale\Context\StorageBasedLocaleContext;
18
use Sylius\Component\Core\Locale\LocaleStorageInterface;
19
use Sylius\Component\Locale\Context\LocaleContextInterface;
20
use Sylius\Component\Locale\Context\LocaleNotFoundException;
21
use Sylius\Component\Resource\Provider\LocaleProviderInterface;
22
23
/**
24
 * @author Kamil Kokot <[email protected]>
25
 */
26
final class StorageBasedLocaleContextSpec extends ObjectBehavior
27
{
28
    function let(
29
        ChannelContextInterface $channelContext,
30
        LocaleStorageInterface $localeStorage,
31
        LocaleProviderInterface $localeProvider
32
    ) {
33
        $this->beConstructedWith($channelContext, $localeStorage, $localeProvider);
34
    }
35
36
    function it_is_initializable()
37
    {
38
        $this->shouldHaveType(StorageBasedLocaleContext::class);
39
    }
40
41
    function it_is_a_locale_context()
42
    {
43
        $this->shouldImplement(LocaleContextInterface::class);
44
    }
45
46
    function it_returns_an_available_active_locale(
47
        ChannelContextInterface $channelContext,
48
        LocaleStorageInterface $localeStorage,
49
        LocaleProviderInterface $localeProvider,
50
        ChannelInterface $channel
51
    ) {
52
        $channelContext->getChannel()->willReturn($channel);
53
54
        $localeStorage->get($channel)->willReturn('pl_PL');
55
56
        $localeProvider->getAvailableLocalesCodes()->willReturn(['pl_PL', 'en_US']);
57
58
        $this->getLocaleCode()->shouldReturn('pl_PL');
59
    }
60
61
    function it_throws_an_exception_if_locale_taken_from_storage_is_not_available(
62
        ChannelContextInterface $channelContext,
63
        LocaleStorageInterface $localeStorage,
64
        LocaleProviderInterface $localeProvider,
65
        ChannelInterface $channel
66
    ) {
67
        $channelContext->getChannel()->willReturn($channel);
68
69
        $localeStorage->get($channel)->willReturn('pl_PL');
70
71
        $localeProvider->getAvailableLocalesCodes()->willReturn(['en_US', 'en_UK']);
72
73
        $this->shouldThrow(LocaleNotFoundException::class)->during('getLocaleCode');
74
    }
75
}
76