1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace TddWizard\Fixtures\Sales; |
4
|
|
|
|
5
|
|
|
use Magento\Framework\ObjectManagerInterface; |
6
|
|
|
use Magento\Sales\Api\Data\InvoiceInterface; |
7
|
|
|
use Magento\Sales\Api\Data\InvoiceItemCreationInterfaceFactory; |
|
|
|
|
8
|
|
|
use Magento\Sales\Api\Data\OrderInterface; |
9
|
|
|
use Magento\Sales\Api\InvoiceOrderInterface; |
10
|
|
|
use Magento\Sales\Api\InvoiceRepositoryInterface; |
11
|
|
|
use Magento\TestFramework\Helper\Bootstrap; |
|
|
|
|
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Builder to be used by fixtures |
15
|
|
|
*/ |
16
|
|
|
class InvoiceBuilder |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* @var InvoiceItemCreationInterfaceFactory |
20
|
|
|
*/ |
21
|
|
|
private $itemFactory; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @var InvoiceOrderInterface |
25
|
|
|
*/ |
26
|
|
|
private $invoiceOrder; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var InvoiceRepositoryInterface |
30
|
|
|
*/ |
31
|
|
|
private $invoiceRepository; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @var OrderInterface |
35
|
|
|
*/ |
36
|
|
|
private $order; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @var int[] |
40
|
|
|
*/ |
41
|
|
|
private $orderItems; |
42
|
|
|
|
43
|
|
|
public function __construct( |
44
|
|
|
InvoiceItemCreationInterfaceFactory $itemFactory, |
45
|
|
|
InvoiceOrderInterface $invoiceOrder, |
46
|
|
|
InvoiceRepositoryInterface $invoiceRepository, |
47
|
|
|
OrderInterface $order |
48
|
|
|
) { |
49
|
|
|
$this->itemFactory = $itemFactory; |
50
|
|
|
$this->invoiceOrder = $invoiceOrder; |
51
|
|
|
$this->invoiceRepository = $invoiceRepository; |
52
|
|
|
$this->order = $order; |
53
|
|
|
|
54
|
|
|
$this->orderItems = []; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public static function forOrder( |
58
|
|
|
OrderInterface $order, |
59
|
|
|
ObjectManagerInterface $objectManager = null |
60
|
|
|
): InvoiceBuilder { |
61
|
|
|
if ($objectManager === null) { |
62
|
|
|
$objectManager = Bootstrap::getObjectManager(); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
return new static( |
66
|
|
|
$objectManager->create(InvoiceItemCreationInterfaceFactory::class), |
67
|
|
|
$objectManager->create(InvoiceOrderInterface::class), |
68
|
|
|
$objectManager->create(InvoiceRepositoryInterface::class), |
69
|
|
|
$order |
70
|
|
|
); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
public function withItem(int $orderItemId, int $qty): InvoiceBuilder |
74
|
|
|
{ |
75
|
|
|
$builder = clone $this; |
76
|
|
|
|
77
|
|
|
$builder->orderItems[$orderItemId] = $qty; |
78
|
|
|
|
79
|
|
|
return $builder; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
public function build(): InvoiceInterface |
83
|
|
|
{ |
84
|
|
|
$invoiceItems = []; |
85
|
|
|
|
86
|
|
|
foreach ($this->orderItems as $orderItemId => $qty) { |
87
|
|
|
$invoiceItem = $this->itemFactory->create(); |
88
|
|
|
$invoiceItem->setOrderItemId($orderItemId); |
89
|
|
|
$invoiceItem->setQty($qty); |
90
|
|
|
$invoiceItems[] = $invoiceItem; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
$invoiceId = $this->invoiceOrder->execute($this->order->getEntityId(), false, $invoiceItems); |
94
|
|
|
|
95
|
|
|
return $this->invoiceRepository->get($invoiceId); |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
|
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