1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
namespace TddWizard\Fixtures\Customer; |
5
|
|
|
|
6
|
|
|
use Faker\Factory as FakerFactory; |
7
|
|
|
use Magento\Customer\Api\AddressRepositoryInterface; |
8
|
|
|
use Magento\Customer\Api\Data\AddressInterface; |
9
|
|
|
use Magento\Directory\Model\Region; |
10
|
|
|
use Magento\Framework\Exception\LocalizedException; |
11
|
|
|
use Magento\TestFramework\Helper\Bootstrap; |
|
|
|
|
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Builder to be used by fixtures |
15
|
|
|
*/ |
16
|
|
|
class AddressBuilder |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* @var AddressInterface |
20
|
|
|
*/ |
21
|
|
|
private $address; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @var AddressRepositoryInterface |
25
|
|
|
*/ |
26
|
|
|
private $addressRepository; |
27
|
|
|
|
28
|
18 |
|
public function __construct(AddressRepositoryInterface $addressRepository, AddressInterface $address) |
29
|
|
|
{ |
30
|
18 |
|
$this->address = $address; |
31
|
18 |
|
$this->addressRepository = $addressRepository; |
32
|
18 |
|
} |
33
|
|
|
|
34
|
18 |
|
public function __clone() |
35
|
|
|
{ |
36
|
18 |
|
$this->address = clone $this->address; |
37
|
18 |
|
} |
38
|
|
|
|
39
|
18 |
|
public static function anAddress( |
40
|
|
|
string $locale = 'de_DE' |
41
|
|
|
): AddressBuilder { |
42
|
18 |
|
$objectManager = Bootstrap::getObjectManager(); |
43
|
18 |
|
$faker = FakerFactory::create($locale); |
44
|
18 |
|
$countryCode = substr($locale, -2); |
45
|
|
|
|
46
|
|
|
try { |
47
|
18 |
|
$region = $faker->province; |
48
|
18 |
|
} catch (\InvalidArgumentException $exception) { |
|
|
|
|
49
|
18 |
|
$region = $faker->state; |
50
|
|
|
} |
51
|
|
|
|
52
|
18 |
|
$regionId = $objectManager->create(Region::class)->loadByName($region, $countryCode)->getId(); |
53
|
|
|
|
54
|
|
|
/** @var AddressInterface $address */ |
55
|
18 |
|
$address = $objectManager->create(AddressInterface::class); |
56
|
|
|
$address |
57
|
18 |
|
->setTelephone($faker->phoneNumber) |
58
|
18 |
|
->setPostcode($faker->postcode) |
59
|
18 |
|
->setCountryId($countryCode) |
60
|
18 |
|
->setCity($faker->city) |
61
|
18 |
|
->setCompany($faker->company) |
62
|
18 |
|
->setStreet([$faker->streetAddress]) |
63
|
18 |
|
->setLastname($faker->lastName) |
64
|
18 |
|
->setFirstname($faker->firstName) |
65
|
18 |
|
->setRegionId($regionId); |
66
|
|
|
|
67
|
18 |
|
return new self($objectManager->create(AddressRepositoryInterface::class), $address); |
68
|
|
|
} |
69
|
|
|
|
70
|
18 |
|
public function asDefaultShipping(): AddressBuilder |
71
|
|
|
{ |
72
|
18 |
|
$builder = clone $this; |
73
|
18 |
|
$builder->address->setIsDefaultShipping(true); |
74
|
18 |
|
return $builder; |
75
|
|
|
} |
76
|
|
|
|
77
|
18 |
|
public function asDefaultBilling(): AddressBuilder |
78
|
|
|
{ |
79
|
18 |
|
$builder = clone $this; |
80
|
18 |
|
$builder->address->setIsDefaultBilling(true); |
81
|
18 |
|
return $builder; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
public function withPrefix(string $prefix): AddressBuilder |
85
|
|
|
{ |
86
|
|
|
$builder = clone $this; |
87
|
|
|
$builder->address->setPrefix($prefix); |
88
|
|
|
return $builder; |
89
|
|
|
} |
90
|
|
|
|
91
|
1 |
|
public function withFirstname(string $firstname): AddressBuilder |
92
|
|
|
{ |
93
|
1 |
|
$builder = clone $this; |
94
|
1 |
|
$builder->address->setFirstname($firstname); |
95
|
1 |
|
return $builder; |
96
|
|
|
} |
97
|
|
|
|
98
|
1 |
|
public function withLastname(string $lastname): AddressBuilder |
99
|
|
|
{ |
100
|
1 |
|
$builder = clone $this; |
101
|
1 |
|
$builder->address->setLastname($lastname); |
102
|
1 |
|
return $builder; |
103
|
|
|
} |
104
|
|
|
|
105
|
1 |
|
public function withStreet(string $street): AddressBuilder |
106
|
|
|
{ |
107
|
1 |
|
$builder = clone $this; |
108
|
1 |
|
$builder->address->setStreet((array)$street); |
109
|
1 |
|
return $builder; |
110
|
|
|
} |
111
|
|
|
|
112
|
1 |
|
public function withCompany(string $company): AddressBuilder |
113
|
|
|
{ |
114
|
1 |
|
$builder = clone $this; |
115
|
1 |
|
$builder->address->setCompany($company); |
116
|
1 |
|
return $builder; |
117
|
|
|
} |
118
|
|
|
|
119
|
1 |
|
public function withTelephone(string $telephone): AddressBuilder |
120
|
|
|
{ |
121
|
1 |
|
$builder = clone $this; |
122
|
1 |
|
$builder->address->setTelephone($telephone); |
123
|
1 |
|
return $builder; |
124
|
|
|
} |
125
|
|
|
|
126
|
1 |
|
public function withPostcode(string $postcode): AddressBuilder |
127
|
|
|
{ |
128
|
1 |
|
$builder = clone $this; |
129
|
1 |
|
$builder->address->setPostcode($postcode); |
130
|
1 |
|
return $builder; |
131
|
|
|
} |
132
|
|
|
|
133
|
1 |
|
public function withCity(string $city): AddressBuilder |
134
|
|
|
{ |
135
|
1 |
|
$builder = clone $this; |
136
|
1 |
|
$builder->address->setCity($city); |
137
|
1 |
|
return $builder; |
138
|
|
|
} |
139
|
|
|
|
140
|
1 |
|
public function withCountryId(string $countryId): AddressBuilder |
141
|
|
|
{ |
142
|
1 |
|
$builder = clone $this; |
143
|
1 |
|
$builder->address->setCountryId($countryId); |
144
|
1 |
|
return $builder; |
145
|
|
|
} |
146
|
|
|
|
147
|
1 |
|
public function withRegionId(int $regionId): AddressBuilder |
148
|
|
|
{ |
149
|
1 |
|
$builder = clone $this; |
150
|
1 |
|
$builder->address->setRegionId($regionId); |
151
|
1 |
|
return $builder; |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
/** |
155
|
|
|
* @param mixed[] $values |
156
|
|
|
* @return AddressBuilder |
157
|
|
|
*/ |
158
|
|
|
public function withCustomAttributes(array $values): AddressBuilder |
159
|
|
|
{ |
160
|
|
|
$builder = clone $this; |
161
|
|
|
foreach ($values as $code => $value) { |
162
|
|
|
$builder->address->setCustomAttribute($code, $value); |
163
|
|
|
} |
164
|
|
|
return $builder; |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
/** |
168
|
|
|
* @return AddressInterface |
169
|
|
|
* @throws LocalizedException |
170
|
|
|
*/ |
171
|
|
|
public function build(): AddressInterface |
172
|
|
|
{ |
173
|
|
|
return $this->addressRepository->save($this->address); |
174
|
|
|
} |
175
|
|
|
|
176
|
18 |
|
public function buildWithoutSave(): AddressInterface |
177
|
|
|
{ |
178
|
18 |
|
return clone $this->address; |
179
|
|
|
} |
180
|
|
|
} |
181
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths