Skip to content

Commit 78f9844

Browse files
authored
Refactor: Update CustomerGroup fixture to be able to use different customer groups on single scenarios (#89)
1 parent 4a41ec4 commit 78f9844

File tree

1 file changed

+24
-32
lines changed

1 file changed

+24
-32
lines changed

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

Lines changed: 24 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,17 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6-
76
declare(strict_types=1);
87

98
namespace Magento\Customer\Test\Fixture;
109

1110
use Magento\Customer\Api\Data\GroupInterface;
1211
use Magento\Customer\Api\GroupRepositoryInterface;
13-
use Magento\Framework\Api\SearchCriteriaBuilder;
1412
use Magento\Framework\DataObject;
1513
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;
1915
use Magento\TestFramework\Fixture\Api\ServiceFactory;
16+
use Magento\TestFramework\Fixture\Data\ProcessorInterface;
2017
use 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

Comments
 (0)