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 Sylius\Behat\Context\Transform; |
13
|
|
|
|
14
|
|
|
use Behat\Behat\Context\Context; |
15
|
|
|
use Sylius\Component\Addressing\Converter\CountryNameConverterInterface; |
16
|
|
|
use Sylius\Component\Addressing\Model\CountryInterface; |
17
|
|
|
use Sylius\Component\Core\Model\AddressInterface; |
18
|
|
|
use Sylius\Component\Resource\Factory\FactoryInterface; |
19
|
|
|
use Sylius\Component\Resource\Repository\RepositoryInterface; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @author Łukasz Chruściel <[email protected]> |
23
|
|
|
*/ |
24
|
|
|
final class AddressingContext implements Context |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* @var FactoryInterface |
28
|
|
|
*/ |
29
|
|
|
private $addressFactory; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var CountryNameConverterInterface |
33
|
|
|
*/ |
34
|
|
|
private $countryNameConverter; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @param FactoryInterface $addressFactory |
38
|
|
|
* @param CountryNameConverterInterface $countryNameConverter |
39
|
|
|
*/ |
40
|
|
|
public function __construct(FactoryInterface $addressFactory, CountryNameConverterInterface $countryNameConverter) |
41
|
|
|
{ |
42
|
|
|
$this->addressFactory = $addressFactory; |
43
|
|
|
$this->countryNameConverter = $countryNameConverter; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @Transform /^to "([^"]+)"$/ |
48
|
|
|
*/ |
49
|
|
|
public function createNewAddress($countryName) |
50
|
|
|
{ |
51
|
|
|
$countryCode = $this->countryNameConverter->convertToCode($countryName); |
52
|
|
|
|
53
|
|
|
return $this->createAddress($countryCode); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @param string $countryCode |
58
|
|
|
* @param string $firstName |
59
|
|
|
* @param string $lastName |
60
|
|
|
* @param string $city |
61
|
|
|
* @param string $street |
62
|
|
|
* |
63
|
|
|
* @return AddressInterface |
64
|
|
|
*/ |
65
|
|
|
private function createAddress( |
66
|
|
|
$countryCode = 'FR', |
67
|
|
|
$firstName = 'John', |
68
|
|
|
$lastName = 'Doe', |
69
|
|
|
$city = 'Ankh Morpork', |
70
|
|
|
$street = 'Frost Alley', |
71
|
|
|
$postCode = '90210' |
72
|
|
|
) { |
73
|
|
|
/** @var AddressInterface $address */ |
74
|
|
|
$address = $this->addressFactory->createNew(); |
75
|
|
|
$address->setCountryCode($countryCode); |
76
|
|
|
$address->setFirstName($firstName); |
77
|
|
|
$address->setLastName($lastName); |
78
|
|
|
$address->setCity($city); |
79
|
|
|
$address->setStreet($street); |
80
|
|
|
$address->setPostcode($postCode); |
81
|
|
|
|
82
|
|
|
return $address; |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|