33 * Copyright © Magento, Inc. All rights reserved.
44 * See COPYING.txt for license details.
55 */
6-
76declare (strict_types=1 );
87
98namespace Magento \Customer \Test \Fixture ;
109
1110use Magento \Customer \Api \Data \GroupInterface ;
1211use Magento \Customer \Api \GroupRepositoryInterface ;
13- use Magento \Framework \Api \SearchCriteriaBuilder ;
1412use Magento \Framework \DataObject ;
1513use 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 ;
1915use Magento \TestFramework \Fixture \Api \ServiceFactory ;
16+ use Magento \TestFramework \Fixture \Data \ProcessorInterface ;
2017use Magento \TestFramework \Fixture \RevertibleDataFixtureInterface ;
2118
2219/**
@@ -35,50 +32,46 @@ class CustomerGroup implements RevertibleDataFixtureInterface
3532 private ServiceFactory $ serviceFactory ;
3633
3734 /**
38- * @var TaxClassRepositoryInterface
35+ * @var Hydrator
3936 */
40- private TaxClassRepositoryInterface $ taxClassRepository ;
41-
42- /** @var Hydrator */
4337 private Hydrator $ hydrator ;
4438
39+ /**
40+ * @var DataMerger
41+ */
42+ private DataMerger $ dataMerger ;
43+
44+ /**
45+ * @var ProcessorInterface
46+ */
47+ private ProcessorInterface $ dataProcessor ;
48+
4549 /**
4650 * @param ServiceFactory $serviceFactory
47- * @param TaxClassRepositoryInterface $taxClassRepository
48- * @param SearchCriteriaBuilder $searchCriteriaBuilder
4951 * @param Hydrator $hydrator
52+ * @param DataMerger $dataMerger
53+ * @param ProcessorInterface $dataProcessor
5054 */
5155 public function __construct (
5256 ServiceFactory $ serviceFactory ,
53- TaxClassRepositoryInterface $ taxClassRepository ,
54- Hydrator $ hydrator
57+ Hydrator $ hydrator ,
58+ DataMerger $ dataMerger ,
59+ ProcessorInterface $ dataProcessor
5560 ) {
5661 $ this ->serviceFactory = $ serviceFactory ;
57- $ this ->taxClassRepository = $ taxClassRepository ;
5862 $ this ->hydrator = $ hydrator ;
63+ $ this ->dataMerger = $ dataMerger ;
64+ $ this ->dataProcessor = $ dataProcessor ;
5965 }
6066
6167 /**
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
6769 */
6870 public function apply (array $ data = []): ?DataObject
6971 {
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 (
8073 [
81- 'group ' => $ data ,
74+ 'group ' => $ this -> dataProcessor -> process ( $ this , $ this -> dataMerger -> merge ( self :: DEFAULT_DATA , $ data ))
8275 ]
8376 );
8477
@@ -90,8 +83,7 @@ public function apply(array $data = []): ?DataObject
9083 */
9184 public function revert (DataObject $ data ): void
9285 {
93- $ service = $ this ->serviceFactory ->create (GroupRepositoryInterface::class, 'deleteById ' );
94- $ service ->execute (
86+ $ this ->serviceFactory ->create (GroupRepositoryInterface::class, 'deleteById ' )->execute (
9587 [
9688 'id ' => $ data ->getId ()
9789 ]
0 commit comments