Completed
Push — scalar-types/customer ( db66a3...ff9fd6 )
by Kamil
24:23
created

CompositeLocaleContextSpec   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 3
dl 0
loc 54
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A it_implements_locale_context_interface() 0 4 1
A it_throws_a_locale_not_found_exception_if_there_are_no_nested_locale_contexts_defined() 0 4 1
A it_throws_a_locale_not_found_exception_if_none_of_nested_locale_contexts_returned_a_locale() 0 9 1
A it_returns_first_result_returned_by_nested_request_resolvers() 0 15 1
A its_nested_request_resolvers_can_have_priority() 0 15 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\Locale\Context;
15
16
use PhpSpec\ObjectBehavior;
17
use Sylius\Component\Locale\Context\LocaleContextInterface;
18
use Sylius\Component\Locale\Context\LocaleNotFoundException;
19
20
/**
21
 * @author Kamil Kokot <[email protected]>
22
 */
23
class CompositeLocaleContextSpec extends ObjectBehavior
24
{
25
    function it_implements_locale_context_interface(): void
26
    {
27
        $this->shouldImplement(LocaleContextInterface::class);
28
    }
29
30
    function it_throws_a_locale_not_found_exception_if_there_are_no_nested_locale_contexts_defined(): void
31
    {
32
        $this->shouldThrow(LocaleNotFoundException::class)->during('getLocaleCode');
33
    }
34
35
    function it_throws_a_locale_not_found_exception_if_none_of_nested_locale_contexts_returned_a_locale(
36
        LocaleContextInterface $localeContext
37
    ): void {
38
        $localeContext->getLocaleCode()->willThrow(LocaleNotFoundException::class);
39
40
        $this->addContext($localeContext);
41
42
        $this->shouldThrow(LocaleNotFoundException::class)->during('getLocaleCode');
43
    }
44
45
    function it_returns_first_result_returned_by_nested_request_resolvers(
46
        LocaleContextInterface $firstLocaleContext,
47
        LocaleContextInterface $secondLocaleContext,
48
        LocaleContextInterface $thirdLocaleContext
49
    ): void {
50
        $firstLocaleContext->getLocaleCode()->willThrow(LocaleNotFoundException::class);
51
        $secondLocaleContext->getLocaleCode()->willReturn('en_US');
52
        $thirdLocaleContext->getLocaleCode()->shouldNotBeCalled();
53
54
        $this->addContext($firstLocaleContext);
55
        $this->addContext($secondLocaleContext);
56
        $this->addContext($thirdLocaleContext);
57
58
        $this->getLocaleCode()->shouldReturn('en_US');
59
    }
60
61
    function its_nested_request_resolvers_can_have_priority(
62
        LocaleContextInterface $firstLocaleContext,
63
        LocaleContextInterface $secondLocaleContext,
64
        LocaleContextInterface $thirdLocaleContext
65
    ): void {
66
        $firstLocaleContext->getLocaleCode()->shouldNotBeCalled();
67
        $secondLocaleContext->getLocaleCode()->willReturn('pl_PL');
68
        $thirdLocaleContext->getLocaleCode()->willThrow(LocaleNotFoundException::class);
69
70
        $this->addContext($firstLocaleContext, -5);
71
        $this->addContext($secondLocaleContext, 0);
72
        $this->addContext($thirdLocaleContext, 5);
73
74
        $this->getLocaleCode()->shouldReturn('pl_PL');
75
    }
76
}
77