33 * Copyright © Magento, Inc. All rights reserved.
44 * See COPYING.txt for license details.
55 */
6+ declare (strict_types=1 );
7+
68namespace Magento \Sales \Model \Order ;
79
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
921{
1022 /**
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
1244 */
13- private $ _collection ;
45+ private $ searchCriteriaBuilder ;
1446
47+ /**
48+ * @inheritDoc
49+ */
1550 protected function setUp (): void
1651 {
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);
2057 }
2158
2259 /**
@@ -27,9 +64,27 @@ public function testOrderTotalItemCount()
2764 $ expectedResult = [['total_item_count ' => 1 ]];
2865 $ actualResult = [];
2966 /** @var \Magento\Sales\Model\Order $order */
30- foreach ($ this ->_collection ->getItems () as $ order ) {
67+ foreach ($ this ->collection ->getItems () as $ order ) {
3168 $ actualResult [] = ['total_item_count ' => $ order ->getData ('total_item_count ' )];
3269 }
3370 $ this ->assertEquals ($ expectedResult , $ actualResult );
3471 }
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+ }
3590}
0 commit comments