|
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
|
|
|
|