3
3
* Copyright © Magento, Inc. All rights reserved.
4
4
* See COPYING.txt for license details.
5
5
*/
6
+ declare (strict_types=1 );
7
+
6
8
namespace Magento \Sales \Model \Order ;
7
9
8
- class InvoiceTest extends \PHPUnit \Framework \TestCase
10
+ use PHPUnit \Framework \TestCase ;
11
+ use Magento \TestFramework \Helper \Bootstrap ;
12
+ use Magento \Sales \Model \ResourceModel \Order \Collection as OrderCollection ;
13
+ use Magento \Sales \Api \InvoiceManagementInterface ;
14
+ use Magento \Sales \Api \OrderRepositoryInterface ;
15
+ use Magento \Framework \Api \SearchCriteriaBuilder ;
16
+
17
+ /**
18
+ * Invoice model test.
19
+ */
20
+ class InvoiceTest extends TestCase
9
21
{
10
22
/**
11
- * @var \Magento\Sales\Model\ResourceModel\Order\Collection
23
+ * @var \Magento\Framework\ObjectManagerInterface
24
+ */
25
+ private $ objectManager ;
26
+
27
+ /**
28
+ * @var OrderCollection
29
+ */
30
+ private $ collection ;
31
+
32
+ /**
33
+ * @var InvoiceManagementInterface
34
+ */
35
+ private $ invoiceManagement ;
36
+
37
+ /**
38
+ * @var OrderRepositoryInterface
39
+ */
40
+ private $ orderRepository ;
41
+
42
+ /**
43
+ * @var SearchCriteriaBuilder
12
44
*/
13
- private $ _collection ;
45
+ private $ searchCriteriaBuilder ;
14
46
47
+ /**
48
+ * @inheritDoc
49
+ */
15
50
protected function setUp (): void
16
51
{
17
- $ this ->_collection = \Magento \TestFramework \Helper \Bootstrap::getObjectManager ()->create (
18
- \Magento \Sales \Model \ResourceModel \Order \Collection::class
19
- );
52
+ $ this ->objectManager = Bootstrap::getObjectManager ();
53
+ $ this ->collection = $ this ->objectManager ->create (OrderCollection::class);
54
+ $ this ->invoiceManagement = $ this ->objectManager ->get (InvoiceManagementInterface::class);
55
+ $ this ->orderRepository = $ this ->objectManager ->get (OrderRepositoryInterface::class);
56
+ $ this ->searchCriteriaBuilder = $ this ->objectManager ->get (SearchCriteriaBuilder::class);
20
57
}
21
58
22
59
/**
@@ -27,9 +64,27 @@ public function testOrderTotalItemCount()
27
64
$ expectedResult = [['total_item_count ' => 1 ]];
28
65
$ actualResult = [];
29
66
/** @var \Magento\Sales\Model\Order $order */
30
- foreach ($ this ->_collection ->getItems () as $ order ) {
67
+ foreach ($ this ->collection ->getItems () as $ order ) {
31
68
$ actualResult [] = ['total_item_count ' => $ order ->getData ('total_item_count ' )];
32
69
}
33
70
$ this ->assertEquals ($ expectedResult , $ actualResult );
34
71
}
72
+
73
+ /**
74
+ * Test order with exactly one configurable.
75
+ *
76
+ * @return void
77
+ * @magentoDataFixture Magento/Sales/_files/order_configurable_product.php
78
+ */
79
+ public function testLastInvoiceWithConfigurable (): void
80
+ {
81
+ $ searchCriteria = $ this ->searchCriteriaBuilder ->addFilter ('increment_id ' , '100000001 ' )
82
+ ->create ();
83
+ $ orders = $ this ->orderRepository ->getList ($ searchCriteria );
84
+ $ orders = $ orders ->getItems ();
85
+ $ order = array_shift ($ orders );
86
+ $ invoice = $ this ->invoiceManagement ->prepareInvoice ($ order );
87
+
88
+ self ::assertEquals ($ invoice ->isLast (), true );
89
+ }
35
90
}
0 commit comments