1919use Magento \Framework \Exception \LocalizedException ;
2020use Magento \Framework \Exception \NoSuchEntityException ;
2121use Magento \Framework \Exception \StateException ;
22+ use Magento \Framework \Registry ;
2223use Magento \Framework \View \LayoutInterface ;
2324use Magento \Quote \Api \CartManagementInterface ;
2425use Magento \Quote \Test \Fixture \AddProductToCart as AddProductToCartFixture ;
2526use Magento \Quote \Test \Fixture \CustomerCart ;
2627use Magento \Sales \Api \InvoiceOrderInterface ;
27- use Magento \Sales \Api \InvoiceRepositoryInterface ;
28- use Magento \Sales \Api \OrderManagementInterface ;
29- use Magento \Sales \Api \OrderRepositoryInterface ;
28+ use Magento \Sales \Model \ResourceModel \Order \CollectionFactory as OrderCollectionFactory ;
29+ use Magento \Sales \Model \ResourceModel \Order \Invoice \CollectionFactory as InvoiceCollectionFactory ;
3030use Magento \Store \Model \ScopeInterface ;
3131use Magento \Store \Model \StoreManagerInterface ;
3232use Magento \Store \Test \Fixture \Group as StoreGroupFixture ;
@@ -65,35 +65,40 @@ class AdminOrderReportsTest extends AbstractBackendController
6565 */
6666 private $ storeManager ;
6767
68- /**
69- * @var OrderRepositoryInterface
70- */
71- private $ orderRepository ;
72-
73- /**
74- * @var OrderManagementInterface
75- */
76- private $ orderManagement ;
77-
78- /**
79- * @var InvoiceRepositoryInterface
80- */
81- private $ invoiceRepository ;
82-
83- private int $ orderId ;
84-
85- private int $ invoiceId ;
86-
8768 protected function setUp (): void
8869 {
8970 parent ::setUp ();
9071 $ this ->cartManagement = $ this ->_objectManager ->get (CartManagementInterface::class);
9172 $ this ->invoiceOrder = $ this ->_objectManager ->get (InvoiceOrderInterface::class);
9273 $ this ->fixtures = $ this ->_objectManager ->get (DataFixtureStorageManager::class)->getStorage ();
9374 $ this ->storeManager = $ this ->_objectManager ->get (StoreManagerInterface::class);
94- $ this ->orderRepository = $ this ->_objectManager ->get (OrderRepositoryInterface::class);
95- $ this ->orderManagement = $ this ->_objectManager ->get (OrderManagementInterface::class);
96- $ this ->invoiceRepository = $ this ->_objectManager ->get (InvoiceRepositoryInterface::class);
75+ }
76+
77+ protected function tearDown (): void
78+ {
79+ $ store = $ this ->storeManager ->getStore ();
80+ $ store ->setCurrentCurrencyCode ('USD ' );
81+
82+ $ registry = $ this ->_objectManager ->get (Registry::class);
83+ $ registry ->unregister ('isSecureArea ' );
84+ $ registry ->register ('isSecureArea ' , true );
85+
86+ $ orderCollection = $ this ->_objectManager ->create (OrderCollectionFactory::class)->create ();
87+ foreach ($ orderCollection as $ order ) {
88+ $ order ->delete ();
89+ }
90+
91+ $ invoiceCollection = $ this ->_objectManager ->create (InvoiceCollectionFactory::class)->create ();
92+ foreach ($ invoiceCollection as $ invoice ) {
93+ $ invoice ->delete ();
94+ }
95+
96+ $ this ->_objectManager ->create ('Magento\Sales\Model\ResourceModel\Report\Order ' )->aggregate ();
97+
98+ $ registry ->unregister ('isSecureArea ' );
99+ $ registry ->register ('isSecureArea ' , false );
100+
101+ parent ::tearDown ();
97102 }
98103
99104 /**
@@ -134,10 +139,10 @@ public function testAdminOrderReportsForMultiWebsiteWithDifferentDisplayCurrency
134139 $ store = $ this ->storeManager ->getStore ();
135140 $ store ->setCurrentCurrencyCode ('EUR ' );
136141
137- $ this -> orderId = $ this ->cartManagement ->placeOrder ($ cart ->getId ());
138- $ this ->assertNotEmpty ($ this -> orderId );
139- $ this -> invoiceId = $ this ->invoiceOrder ->execute ($ this -> orderId );
140- $ this ->assertNotEmpty ($ this -> invoiceId );
142+ $ orderId = $ this ->cartManagement ->placeOrder ($ cart ->getId ());
143+ $ this ->assertNotEmpty ($ orderId );
144+ $ invoiceId = $ this ->invoiceOrder ->execute ($ orderId );
145+ $ this ->assertNotEmpty ($ invoiceId );
141146
142147 $ this ->_objectManager ->create ('Magento\Sales\Model\ResourceModel\Report\Order ' )->aggregate ();
143148
@@ -161,26 +166,4 @@ public function testAdminOrderReportsForMultiWebsiteWithDifferentDisplayCurrency
161166 $ blockHtml = $ salesReportGrid ->toHtml ();
162167 $ this ->assertStringContainsString ('€ ' , $ blockHtml );
163168 }
164-
165- /**
166- * @inheritdoc
167- */
168- protected function tearDown (): void
169- {
170- $ store = $ this ->storeManager ->getStore ();
171- $ store ->setCurrentCurrencyCode ('USD ' );
172-
173- $ order = $ this ->orderRepository ->get ($ this ->orderId );
174- if ($ order ) {
175- $ this ->orderManagement ->cancel ($ this ->orderId );
176- $ this ->orderRepository ->delete ($ order );
177- }
178-
179- $ invoice = $ this ->invoiceRepository ->get ($ this ->invoiceId );
180- $ this ->invoiceRepository ->delete ($ invoice );
181-
182- $ this ->_objectManager ->create ('Magento\Sales\Model\ResourceModel\Report\Order ' )->aggregate ();
183-
184- parent ::tearDown ();
185- }
186169}
0 commit comments