1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace TddWizard\Fixtures\Sales; |
4
|
|
|
|
5
|
|
|
use Magento\Catalog\Api\ProductRepositoryInterface; |
6
|
|
|
use Magento\Customer\Api\CustomerRepositoryInterface; |
7
|
|
|
use Magento\Framework\Exception\LocalizedException; |
8
|
|
|
use Magento\Framework\ObjectManagerInterface; |
9
|
|
|
use Magento\Framework\Registry; |
10
|
|
|
use Magento\Sales\Api\Data\OrderItemInterface; |
11
|
|
|
use Magento\Sales\Api\OrderRepositoryInterface; |
12
|
|
|
|
13
|
|
|
class OrderFixtureRollback |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* @var Registry |
17
|
|
|
*/ |
18
|
|
|
private $registry; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @var OrderRepositoryInterface |
22
|
|
|
*/ |
23
|
|
|
private $orderRepository; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @var CustomerRepositoryInterface |
27
|
|
|
*/ |
28
|
|
|
private $customerRepository; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var ProductRepositoryInterface |
32
|
|
|
*/ |
33
|
|
|
private $productRepository; |
34
|
|
|
|
35
|
|
|
public function __construct( |
36
|
|
|
Registry $registry, |
37
|
|
|
OrderRepositoryInterface $orderRepository, |
38
|
|
|
CustomerRepositoryInterface $customerRepository, |
39
|
|
|
ProductRepositoryInterface $productRepository |
40
|
|
|
) { |
41
|
|
|
$this->registry = $registry; |
42
|
|
|
$this->orderRepository = $orderRepository; |
43
|
|
|
$this->customerRepository = $customerRepository; |
44
|
|
|
$this->productRepository = $productRepository; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public static function create(ObjectManagerInterface $objectManager = null) |
48
|
|
|
{ |
49
|
|
|
if ($objectManager === null) { |
50
|
|
|
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); |
|
|
|
|
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
return new self( |
54
|
|
|
$objectManager->get(Registry::class), |
55
|
|
|
$objectManager->get(OrderRepositoryInterface::class), |
56
|
|
|
$objectManager->get(CustomerRepositoryInterface::class), |
57
|
|
|
$objectManager->get(ProductRepositoryInterface::class) |
58
|
|
|
); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Roll back orders with associated customers and products. |
63
|
|
|
* |
64
|
|
|
* @param OrderFixture ...$orderFixtures |
65
|
|
|
* @throws \Magento\Framework\Exception\LocalizedException |
66
|
|
|
* @throws \Magento\Framework\Exception\NoSuchEntityException |
67
|
|
|
*/ |
68
|
|
|
public function execute(OrderFixture ...$orderFixtures) |
69
|
|
|
{ |
70
|
|
|
$this->registry->unregister('isSecureArea'); |
71
|
|
|
$this->registry->register('isSecureArea', true); |
72
|
|
|
|
73
|
|
|
foreach ($orderFixtures as $orderFixture) { |
74
|
|
|
$orderItems = $this->orderRepository->get($orderFixture->getId())->getItems(); |
75
|
|
|
|
76
|
|
|
$this->orderRepository->deleteById($orderFixture->getId()); |
|
|
|
|
77
|
|
|
$this->customerRepository->deleteById($orderFixture->getCustomerId()); |
78
|
|
|
array_walk( |
79
|
|
|
$orderItems, |
80
|
|
|
function (OrderItemInterface $orderItem) { |
81
|
|
|
$this->productRepository->deleteById($orderItem->getSku()); |
82
|
|
|
} |
83
|
|
|
); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
$this->registry->unregister('isSecureArea'); |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|
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