8
8
9
9
namespace Magento \Customer \Test \Fixture ;
10
10
11
- use Magento \Customer \Api \AddressRepositoryInterface ;
12
11
use Magento \Customer \Api \CustomerRepositoryInterface ;
13
12
use Magento \Customer \Api \Data \AddressInterface ;
14
- use Magento \Customer \Api \Data \AddressInterfaceFactory ;
15
13
use Magento \Customer \Api \Data \CustomerInterface ;
16
14
use Magento \Customer \Model \CustomerFactory ;
15
+ use Magento \Customer \Model \CustomerRegistry ;
17
16
use Magento \Framework \DataObject ;
18
17
use Magento \Framework \Exception \LocalizedException ;
19
18
use Magento \Framework \Exception \NoSuchEntityException ;
@@ -90,14 +89,9 @@ class Customer implements RevertibleDataFixtureInterface
90
89
private $ customerFactory ;
91
90
92
91
/**
93
- * @var AddressRepositoryInterface
92
+ * @var CustomerRegistry
94
93
*/
95
- private $ addressRepository ;
96
-
97
- /**
98
- * @var AddressInterfaceFactory
99
- */
100
- private $ addressDataFactory ;
94
+ private $ customerRegistry ;
101
95
102
96
/**
103
97
* @var ProcessorInterface
@@ -118,25 +112,22 @@ class Customer implements RevertibleDataFixtureInterface
118
112
* @param ServiceFactory $serviceFactory
119
113
* @param CustomerRepositoryInterface $customerRepository
120
114
* @param CustomerFactory $customerFactory
121
- * @param AddressRepositoryInterface $addressRepository
122
- * @param AddressInterfaceFactory $addressDataFactory
115
+ * @param CustomerRegistry $customerRegistry
123
116
* @param ProcessorInterface $dataProcessor
124
117
* @param DataMerger $dataMerger
125
118
*/
126
119
public function __construct (
127
120
ServiceFactory $ serviceFactory ,
128
121
CustomerRepositoryInterface $ customerRepository ,
129
122
CustomerFactory $ customerFactory ,
130
- AddressRepositoryInterface $ addressRepository ,
131
- AddressInterfaceFactory $ addressDataFactory ,
123
+ CustomerRegistry $ customerRegistry ,
132
124
ProcessorInterface $ dataProcessor ,
133
125
DataMerger $ dataMerger ,
134
126
) {
135
127
$ this ->serviceFactory = $ serviceFactory ;
136
128
$ this ->customerRepository = $ customerRepository ;
137
129
$ this ->customerFactory = $ customerFactory ;
138
- $ this ->addressRepository = $ addressRepository ;
139
- $ this ->addressDataFactory = $ addressDataFactory ;
130
+ $ this ->customerRegistry = $ customerRegistry ;
140
131
$ this ->dataProcessor = $ dataProcessor ;
141
132
$ this ->dataMerger = $ dataMerger ;
142
133
$ this ->customer = null ;
@@ -157,20 +148,25 @@ public function apply(array $data = []): ?DataObject
157
148
$ addresses = $ this ->prepareCustomerAddress ($ data [CustomerInterface::KEY_ADDRESSES ]);
158
149
$ data [CustomerInterface::KEY_ADDRESSES ] = $ addresses ;
159
150
}
160
- return $ customerSaveService ->execute (
161
- ['customer ' => $ data , 'passwordHash ' => $ this ->customer ->getPasswordHash ()]
151
+ $ customerSaveService ->execute (
152
+ [
153
+ 'customer ' => $ data ,
154
+ 'passwordHash ' => $ this ->customer ->getPasswordHash ()
155
+ ]
162
156
);
157
+ return $ this ->customerRegistry ->retrieveByEmail ($ data ['email ' ], $ data ['website_id ' ]);
163
158
}
164
159
165
160
/**
166
161
* @inheritdoc
167
162
*/
168
163
public function revert (DataObject $ data ): void
169
164
{
165
+ $ data ->setCustomerId ($ data ->getId ());
170
166
$ service = $ this ->serviceFactory ->create (CustomerRepositoryInterface::class, 'deleteById ' );
171
167
$ service ->execute (
172
168
[
173
- 'id ' => $ data ->getId ()
169
+ 'customerId ' => $ data ->getId ()
174
170
]
175
171
);
176
172
}
@@ -185,7 +181,7 @@ private function prepareData(array $data): array
185
181
{
186
182
$ data = $ this ->dataMerger ->merge (self ::DEFAULT_DATA , $ data , false );
187
183
188
- $ this ->customer = $ this ->customerFactory ->create ()-> setData ( $ data );
184
+ $ this ->customer = $ this ->customerFactory ->create ([ ' data ' => $ data] );
189
185
$ this ->customer ->setPassword ($ data ['password ' ]);
190
186
if (isset ($ data ['password ' ])) {
191
187
unset($ data ['password ' ]);
0 commit comments