1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
namespace TddWizard\Fixtures\Sales; |
5
|
|
|
|
6
|
|
|
use Magento\Catalog\Api\ProductRepositoryInterface; |
7
|
|
|
use Magento\Customer\Api\CustomerRepositoryInterface; |
8
|
|
|
use Magento\Framework\Exception\LocalizedException; |
9
|
|
|
use Magento\Framework\Exception\NoSuchEntityException; |
10
|
|
|
use Magento\Framework\Registry; |
11
|
|
|
use Magento\Sales\Api\Data\OrderItemInterface; |
12
|
|
|
use Magento\Sales\Api\OrderRepositoryInterface; |
13
|
|
|
use Magento\Sales\Model\OrderRepository; |
14
|
|
|
use Magento\TestFramework\Helper\Bootstrap; |
|
|
|
|
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @internal Use OrderFixture::rollback() or OrderFixturePool::rollback() instead |
18
|
|
|
*/ |
19
|
|
|
class OrderFixtureRollback |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* @var Registry |
23
|
|
|
*/ |
24
|
|
|
private $registry; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var OrderRepository |
28
|
|
|
*/ |
29
|
|
|
private $orderRepository; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var CustomerRepositoryInterface |
33
|
|
|
*/ |
34
|
|
|
private $customerRepository; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @var ProductRepositoryInterface |
38
|
|
|
*/ |
39
|
|
|
private $productRepository; |
40
|
|
|
|
41
|
17 |
|
public function __construct( |
42
|
|
|
Registry $registry, |
43
|
|
|
OrderRepository $orderRepository, |
44
|
|
|
CustomerRepositoryInterface $customerRepository, |
45
|
|
|
ProductRepositoryInterface $productRepository |
46
|
|
|
) { |
47
|
17 |
|
$this->registry = $registry; |
48
|
17 |
|
$this->orderRepository = $orderRepository; |
49
|
17 |
|
$this->customerRepository = $customerRepository; |
50
|
17 |
|
$this->productRepository = $productRepository; |
51
|
17 |
|
} |
52
|
|
|
|
53
|
17 |
|
public static function create(): OrderFixtureRollback |
54
|
|
|
{ |
55
|
17 |
|
$objectManager = Bootstrap::getObjectManager(); |
56
|
|
|
|
57
|
17 |
|
return new self( |
58
|
17 |
|
$objectManager->get(Registry::class), |
59
|
17 |
|
$objectManager->get(OrderRepositoryInterface::class), |
60
|
17 |
|
$objectManager->get(CustomerRepositoryInterface::class), |
61
|
17 |
|
$objectManager->get(ProductRepositoryInterface::class) |
62
|
|
|
); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Roll back orders with associated customers and products. |
67
|
|
|
* |
68
|
|
|
* @param OrderFixture ...$orderFixtures |
69
|
|
|
* @throws LocalizedException |
70
|
|
|
* @throws NoSuchEntityException |
71
|
|
|
*/ |
72
|
17 |
|
public function execute(OrderFixture ...$orderFixtures): void |
73
|
|
|
{ |
74
|
17 |
|
$this->registry->unregister('isSecureArea'); |
|
|
|
|
75
|
17 |
|
$this->registry->register('isSecureArea', true); |
|
|
|
|
76
|
|
|
|
77
|
17 |
|
foreach ($orderFixtures as $orderFixture) { |
78
|
17 |
|
$orderItems = $this->orderRepository->get($orderFixture->getId())->getItems(); |
79
|
|
|
|
80
|
17 |
|
$this->orderRepository->deleteById($orderFixture->getId()); |
81
|
17 |
|
$this->customerRepository->deleteById($orderFixture->getCustomerId()); |
82
|
17 |
|
array_walk( |
83
|
17 |
|
$orderItems, |
84
|
|
|
function (OrderItemInterface $orderItem) { |
85
|
|
|
try { |
86
|
17 |
|
$this->productRepository->deleteById($orderItem->getSku()); |
87
|
|
|
} catch (\Magento\Framework\Exception\NoSuchEntityException $e) { |
88
|
|
|
// ignore if already deleted |
89
|
|
|
} |
90
|
17 |
|
} |
91
|
|
|
); |
92
|
|
|
} |
93
|
|
|
|
94
|
17 |
|
$this->registry->unregister('isSecureArea'); |
|
|
|
|
95
|
17 |
|
} |
96
|
|
|
} |
97
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths