Skip to content

Commit ad1be29

Browse files
committed
ACP2E-894: wip adding parametrized data fixtures
1 parent 2cf7b3a commit ad1be29

File tree

1 file changed

+15
-19
lines changed

1 file changed

+15
-19
lines changed

app/code/Magento/Customer/Test/Fixture/Customer.php

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,11 @@
88

99
namespace Magento\Customer\Test\Fixture;
1010

11-
use Magento\Customer\Api\AddressRepositoryInterface;
1211
use Magento\Customer\Api\CustomerRepositoryInterface;
1312
use Magento\Customer\Api\Data\AddressInterface;
14-
use Magento\Customer\Api\Data\AddressInterfaceFactory;
1513
use Magento\Customer\Api\Data\CustomerInterface;
1614
use Magento\Customer\Model\CustomerFactory;
15+
use Magento\Customer\Model\CustomerRegistry;
1716
use Magento\Framework\DataObject;
1817
use Magento\Framework\Exception\LocalizedException;
1918
use Magento\Framework\Exception\NoSuchEntityException;
@@ -90,14 +89,9 @@ class Customer implements RevertibleDataFixtureInterface
9089
private $customerFactory;
9190

9291
/**
93-
* @var AddressRepositoryInterface
92+
* @var CustomerRegistry
9493
*/
95-
private $addressRepository;
96-
97-
/**
98-
* @var AddressInterfaceFactory
99-
*/
100-
private $addressDataFactory;
94+
private $customerRegistry;
10195

10296
/**
10397
* @var ProcessorInterface
@@ -118,25 +112,22 @@ class Customer implements RevertibleDataFixtureInterface
118112
* @param ServiceFactory $serviceFactory
119113
* @param CustomerRepositoryInterface $customerRepository
120114
* @param CustomerFactory $customerFactory
121-
* @param AddressRepositoryInterface $addressRepository
122-
* @param AddressInterfaceFactory $addressDataFactory
115+
* @param CustomerRegistry $customerRegistry
123116
* @param ProcessorInterface $dataProcessor
124117
* @param DataMerger $dataMerger
125118
*/
126119
public function __construct(
127120
ServiceFactory $serviceFactory,
128121
CustomerRepositoryInterface $customerRepository,
129122
CustomerFactory $customerFactory,
130-
AddressRepositoryInterface $addressRepository,
131-
AddressInterfaceFactory $addressDataFactory,
123+
CustomerRegistry $customerRegistry,
132124
ProcessorInterface $dataProcessor,
133125
DataMerger $dataMerger,
134126
) {
135127
$this->serviceFactory = $serviceFactory;
136128
$this->customerRepository = $customerRepository;
137129
$this->customerFactory = $customerFactory;
138-
$this->addressRepository = $addressRepository;
139-
$this->addressDataFactory = $addressDataFactory;
130+
$this->customerRegistry = $customerRegistry;
140131
$this->dataProcessor = $dataProcessor;
141132
$this->dataMerger = $dataMerger;
142133
$this->customer = null;
@@ -157,20 +148,25 @@ public function apply(array $data = []): ?DataObject
157148
$addresses = $this->prepareCustomerAddress($data[CustomerInterface::KEY_ADDRESSES]);
158149
$data[CustomerInterface::KEY_ADDRESSES] = $addresses;
159150
}
160-
return $customerSaveService->execute(
161-
['customer' => $data, 'passwordHash' => $this->customer->getPasswordHash()]
151+
$customerSaveService->execute(
152+
[
153+
'customer' => $data,
154+
'passwordHash' => $this->customer->getPasswordHash()
155+
]
162156
);
157+
return $this->customerRegistry->retrieveByEmail($data['email'], $data['website_id']);
163158
}
164159

165160
/**
166161
* @inheritdoc
167162
*/
168163
public function revert(DataObject $data): void
169164
{
165+
$data->setCustomerId($data->getId());
170166
$service = $this->serviceFactory->create(CustomerRepositoryInterface::class, 'deleteById');
171167
$service->execute(
172168
[
173-
'id' => $data->getId()
169+
'customerId' => $data->getId()
174170
]
175171
);
176172
}
@@ -185,7 +181,7 @@ private function prepareData(array $data): array
185181
{
186182
$data = $this->dataMerger->merge(self::DEFAULT_DATA, $data, false);
187183

188-
$this->customer = $this->customerFactory->create()->setData($data);
184+
$this->customer = $this->customerFactory->create(['data' => $data]);
189185
$this->customer->setPassword($data['password']);
190186
if (isset($data['password'])) {
191187
unset($data['password']);

0 commit comments

Comments
 (0)