Completed
Push — master ( b70f30...259e2d )
by Kamil
32:06
created

CountryContextSpec   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
c 1
b 0
f 0
lcom 0
cbo 5
dl 0
loc 47
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A let() 0 6 1
A it_is_initializable() 0 4 1
A it_implements_context_interface() 0 4 1
A it_gets_country_based_on_given_country_name() 0 11 1
A it_throws_invalid_argument_exception_when_country_is_missing() 0 9 1
A it_throws_invalid_argument_exception_when_cannot_convert_name_to_code() 0 6 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\Behat\Context\Transform;
13
14
use Behat\Behat\Context\Context;
15
use PhpSpec\ObjectBehavior;
16
use Sylius\Component\Addressing\Converter\CountryNameConverterInterface;
17
use Sylius\Component\Addressing\Model\CountryInterface;
18
use Sylius\Component\Resource\Repository\RepositoryInterface;
19
20
/**
21
 * @author Łukasz Chruściel <[email protected]>
22
 */
23
class CountryContextSpec extends ObjectBehavior
24
{
25
    function let(
26
        CountryNameConverterInterface $countryNameConverter,
27
        RepositoryInterface $countryRepository
28
    ) {
29
        $this->beConstructedWith($countryNameConverter, $countryRepository);
30
    }
31
32
    function it_is_initializable()
33
    {
34
        $this->shouldHaveType('Sylius\Behat\Context\Transform\CountryContext');
35
    }
36
37
    function it_implements_context_interface()
38
    {
39
        $this->shouldImplement(Context::class);
40
    }
41
    function it_gets_country_based_on_given_country_name(
42
        CountryNameConverterInterface $countryNameConverter,
43
        RepositoryInterface $countryRepository,
44
        CountryInterface $country
45
    ) {
46
        $countryNameConverter->convertToCode('France')->willReturn('FR');
47
        $countryRepository->findOneBy(['code' => 'FR'])->willReturn($country);
48
        $country->getCode()->willReturn('FR');
49
50
        $this->getCountryByName('France')->shouldReturn($country);
51
    }
52
53
    function it_throws_invalid_argument_exception_when_country_is_missing(
54
        CountryNameConverterInterface $countryNameConverter,
55
        RepositoryInterface $countryRepository
56
    ) {
57
        $countryNameConverter->convertToCode('France')->willReturn('FR');
58
        $countryRepository->findOneBy(['code' => 'FR'])->willReturn(null);
59
60
        $this->shouldThrow(\InvalidArgumentException::class)->during('getCountryByName', ['France']);
61
    }
62
63
    function it_throws_invalid_argument_exception_when_cannot_convert_name_to_code(CountryNameConverterInterface $countryNameConverter)
64
    {
65
        $countryNameConverter->convertToCode('France')->willThrow(\InvalidArgumentException::class);
66
67
        $this->shouldThrow(\InvalidArgumentException::class)->during('getCountryByName', ['France']);
68
    }
69
}
70