3
3
* Copyright © Magento, Inc. All rights reserved.
4
4
* See COPYING.txt for license details.
5
5
*/
6
-
7
6
declare (strict_types=1 );
8
7
9
8
namespace Magento \Customer \Test \Fixture ;
10
9
11
10
use Magento \Customer \Api \Data \GroupInterface ;
12
11
use Magento \Customer \Api \GroupRepositoryInterface ;
13
- use Magento \Framework \Api \SearchCriteriaBuilder ;
14
12
use Magento \Framework \DataObject ;
15
13
use Magento \Framework \EntityManager \Hydrator ;
16
- use Magento \Framework \Exception \LocalizedException ;
17
- use Magento \Framework \Exception \NoSuchEntityException ;
18
- use Magento \Tax \Api \TaxClassRepositoryInterface ;
14
+ use Magento \TestFramework \Fixture \Api \DataMerger ;
19
15
use Magento \TestFramework \Fixture \Api \ServiceFactory ;
16
+ use Magento \TestFramework \Fixture \Data \ProcessorInterface ;
20
17
use Magento \TestFramework \Fixture \RevertibleDataFixtureInterface ;
21
18
22
19
/**
@@ -35,50 +32,46 @@ class CustomerGroup implements RevertibleDataFixtureInterface
35
32
private ServiceFactory $ serviceFactory ;
36
33
37
34
/**
38
- * @var TaxClassRepositoryInterface
35
+ * @var Hydrator
39
36
*/
40
- private TaxClassRepositoryInterface $ taxClassRepository ;
41
-
42
- /** @var Hydrator */
43
37
private Hydrator $ hydrator ;
44
38
39
+ /**
40
+ * @var DataMerger
41
+ */
42
+ private DataMerger $ dataMerger ;
43
+
44
+ /**
45
+ * @var ProcessorInterface
46
+ */
47
+ private ProcessorInterface $ dataProcessor ;
48
+
45
49
/**
46
50
* @param ServiceFactory $serviceFactory
47
- * @param TaxClassRepositoryInterface $taxClassRepository
48
- * @param SearchCriteriaBuilder $searchCriteriaBuilder
49
51
* @param Hydrator $hydrator
52
+ * @param DataMerger $dataMerger
53
+ * @param ProcessorInterface $dataProcessor
50
54
*/
51
55
public function __construct (
52
56
ServiceFactory $ serviceFactory ,
53
- TaxClassRepositoryInterface $ taxClassRepository ,
54
- Hydrator $ hydrator
57
+ Hydrator $ hydrator ,
58
+ DataMerger $ dataMerger ,
59
+ ProcessorInterface $ dataProcessor
55
60
) {
56
61
$ this ->serviceFactory = $ serviceFactory ;
57
- $ this ->taxClassRepository = $ taxClassRepository ;
58
62
$ this ->hydrator = $ hydrator ;
63
+ $ this ->dataMerger = $ dataMerger ;
64
+ $ this ->dataProcessor = $ dataProcessor ;
59
65
}
60
66
61
67
/**
62
- * {@inheritdoc}
63
- * @param array $data Parameters. Same format as Customer::DEFAULT_DATA.
64
- * @return DataObject|null
65
- * @throws LocalizedException
66
- * @throws NoSuchEntityException
68
+ * @inheritdoc
67
69
*/
68
70
public function apply (array $ data = []): ?DataObject
69
71
{
70
- $ customerGroupSaveService = $ this ->serviceFactory ->create (
71
- GroupRepositoryInterface::class,
72
- 'save '
73
- );
74
- $ data = self ::DEFAULT_DATA ;
75
- if (!empty ($ data ['tax_class_id ' ])) {
76
- $ data [GroupInterface::TAX_CLASS_ID ] = $ this ->taxClassRepository ->get ($ data ['tax_class_id ' ])->getClassId ();
77
- }
78
-
79
- $ customerGroup = $ customerGroupSaveService ->execute (
72
+ $ customerGroup = $ this ->serviceFactory ->create (GroupRepositoryInterface::class, 'save ' )->execute (
80
73
[
81
- 'group ' => $ data ,
74
+ 'group ' => $ this -> dataProcessor -> process ( $ this , $ this -> dataMerger -> merge ( self :: DEFAULT_DATA , $ data ))
82
75
]
83
76
);
84
77
@@ -90,8 +83,7 @@ public function apply(array $data = []): ?DataObject
90
83
*/
91
84
public function revert (DataObject $ data ): void
92
85
{
93
- $ service = $ this ->serviceFactory ->create (GroupRepositoryInterface::class, 'deleteById ' );
94
- $ service ->execute (
86
+ $ this ->serviceFactory ->create (GroupRepositoryInterface::class, 'deleteById ' )->execute (
95
87
[
96
88
'id ' => $ data ->getId ()
97
89
]
0 commit comments