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