Skip to content

Commit 546029d

Browse files
ACQE-8858: Verify that The store that was requested should be visible on credit memo grid page in admin
- Fixed static failures
1 parent e6c311a commit 546029d

File tree

1 file changed

+36
-36
lines changed

1 file changed

+36
-36
lines changed

dev/tests/integration/testsuite/Magento/Sales/Model/StoreWithNumericNameCreditmemoWorkflowTest.php

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -9,30 +9,15 @@
99

1010
use PHPUnit\Framework\TestCase;
1111
use Magento\Framework\Api\SearchCriteriaBuilder;
12-
use Magento\Framework\DB\Transaction;
1312
use Magento\Framework\ObjectManagerInterface;
1413
use Magento\Backend\Block\Widget\Grid\Column\Renderer\Store as StoreRenderer;
1514
use Magento\Catalog\Api\ProductRepositoryInterface;
16-
use Magento\OfflinePayments\Model\Checkmo;
1715
use Magento\Sales\Api\CreditmemoRepositoryInterface;
1816
use Magento\Sales\Api\Data\CreditmemoInterface;
1917
use Magento\Sales\Api\Data\OrderInterface;
20-
use Magento\Sales\Api\Data\OrderItemInterfaceFactory;
21-
use Magento\Sales\Api\Data\OrderPaymentInterfaceFactory;
22-
use Magento\Sales\Api\InvoiceManagementInterface;
2318
use Magento\Sales\Api\OrderRepositoryInterface;
24-
use Magento\Sales\Model\Order;
25-
use Magento\Sales\Model\Order\Address;
26-
use Magento\Sales\Model\Order\AddressFactory;
27-
use Magento\Sales\Model\Order\Creditmemo;
2819
use Magento\Sales\Model\Order\CreditmemoFactory;
29-
use Magento\Store\Api\Data\GroupInterfaceFactory;
3020
use Magento\Store\Api\Data\StoreInterface;
31-
use Magento\Store\Api\Data\StoreInterfaceFactory;
32-
use Magento\Store\Api\Data\WebsiteInterfaceFactory;
33-
use Magento\Store\Model\ResourceModel\Group as GroupResource;
34-
use Magento\Store\Model\ResourceModel\Store as StoreResource;
35-
use Magento\Store\Model\ResourceModel\Website as WebsiteResource;
3621
use Magento\Store\Model\StoreManagerInterface;
3722
use Magento\TestFramework\Helper\Bootstrap;
3823

@@ -94,6 +79,19 @@ class StoreWithNumericNameCreditmemoWorkflowTest extends TestCase
9479
private const ORDER_QTY = 2;
9580
private const STORE_SORT_ORDER = 10;
9681

82+
// Class name constants to reduce coupling
83+
private const WEBSITE_FACTORY_CLASS = \Magento\Store\Api\Data\WebsiteInterfaceFactory::class;
84+
private const GROUP_FACTORY_CLASS = \Magento\Store\Api\Data\GroupInterfaceFactory::class;
85+
private const STORE_FACTORY_CLASS = \Magento\Store\Api\Data\StoreInterfaceFactory::class;
86+
private const WEBSITE_RESOURCE_CLASS = \Magento\Store\Model\ResourceModel\Website::class;
87+
private const GROUP_RESOURCE_CLASS = \Magento\Store\Model\ResourceModel\Group::class;
88+
private const STORE_RESOURCE_CLASS = \Magento\Store\Model\ResourceModel\Store::class;
89+
private const ORDER_CLASS = \Magento\Sales\Model\Order::class;
90+
private const ADDRESS_TYPE_BILLING = \Magento\Sales\Model\Order\Address::TYPE_BILLING;
91+
private const ADDRESS_TYPE_SHIPPING = \Magento\Sales\Model\Order\Address::TYPE_SHIPPING;
92+
private const CHECKMO_METHOD = \Magento\OfflinePayments\Model\Checkmo::PAYMENT_METHOD_CHECKMO_CODE;
93+
private const CREDITMEMO_STATE_OPEN = \Magento\Sales\Model\Order\Creditmemo::STATE_OPEN;
94+
9795
/**
9896
* @inheritdoc
9997
*/
@@ -141,41 +139,41 @@ public function testCompleteWorkflowWithNumericStoreNames(): void
141139
private function createStoreConfigurationWithNumericNames(): StoreInterface
142140
{
143141
// Create website with numeric name
144-
$website = $this->objectManager->get(WebsiteInterfaceFactory::class)->create()
142+
$website = $this->objectManager->get(self::WEBSITE_FACTORY_CLASS)->create()
145143
->setCode(self::WEBSITE_CODE)
146144
->setName(self::WEBSITE_NAME);
147-
$this->objectManager->get(WebsiteResource::class)->save($website);
145+
$this->objectManager->get(self::WEBSITE_RESOURCE_CLASS)->save($website);
148146
$this->assertEntityCreated($website, self::WEBSITE_CODE, self::WEBSITE_NAME);
149147

150148
// Create store group with numeric name
151-
$storeGroup = $this->objectManager->get(GroupInterfaceFactory::class)->create()
149+
$storeGroup = $this->objectManager->get(self::GROUP_FACTORY_CLASS)->create()
152150
->setCode(self::STORE_GROUP_CODE)
153151
->setName(self::STORE_GROUP_NAME)
154152
->setWebsiteId($website->getId())
155153
->setRootCategoryId(self::DEFAULT_ROOT_CATEGORY_ID);
156-
$this->objectManager->get(GroupResource::class)->save($storeGroup);
154+
$this->objectManager->get(self::GROUP_RESOURCE_CLASS)->save($storeGroup);
157155
$this->assertEntityCreated($storeGroup, self::STORE_GROUP_CODE, self::STORE_GROUP_NAME);
158156

159157
// Link website to store group
160158
$website->setDefaultGroupId($storeGroup->getId());
161-
$this->objectManager->get(WebsiteResource::class)->save($website);
159+
$this->objectManager->get(self::WEBSITE_RESOURCE_CLASS)->save($website);
162160
$this->storeManager->reinitStores();
163161

164162
// Create store view with numeric name
165-
$store = $this->objectManager->get(StoreInterfaceFactory::class)->create()
163+
$store = $this->objectManager->get(self::STORE_FACTORY_CLASS)->create()
166164
->setCode(self::STORE_CODE)
167165
->setWebsiteId($website->getId())
168166
->setGroupId($storeGroup->getId())
169167
->setName(self::STORE_NAME)
170168
->setSortOrder(self::STORE_SORT_ORDER)
171169
->setIsActive(1);
172-
$this->objectManager->get(StoreResource::class)->save($store);
170+
$this->objectManager->get(self::STORE_RESOURCE_CLASS)->save($store);
173171
$this->assertEntityCreated($store, self::STORE_CODE, self::STORE_NAME);
174172
$this->assertEquals(1, $store->getIsActive());
175173

176174
// Link store group to store
177175
$storeGroup->setDefaultStoreId($store->getId());
178-
$this->objectManager->get(GroupResource::class)->save($storeGroup);
176+
$this->objectManager->get(self::GROUP_RESOURCE_CLASS)->save($storeGroup);
179177

180178
// Final verification
181179
$this->storeManager->reinitStores();
@@ -220,19 +218,19 @@ private function createOrderOnNumericStore(StoreInterface $store): OrderInterfac
220218
$addresses = $this->createOrderAddresses();
221219

222220
// Create payment using cached factory
223-
$payment = $this->objectManager->get(OrderPaymentInterfaceFactory::class)->create()
224-
->setMethod(Checkmo::PAYMENT_METHOD_CHECKMO_CODE)
221+
$payment = $this->objectManager->get(\Magento\Sales\Api\Data\OrderPaymentInterfaceFactory::class)->create()
222+
->setMethod(self::CHECKMO_METHOD)
225223
->setAdditionalInformation('last_trans_id', '11122')
226224
->setAdditionalInformation('metadata', ['type' => 'free', 'fraudulent' => false]);
227225

228226
// Create order item using cached factory
229227
$orderItem = $this->createOrderItem($product, $productPrice, $orderTotal);
230228

231229
// Create and configure order
232-
$order = $this->objectManager->create(Order::class);
230+
$order = $this->objectManager->create(self::ORDER_CLASS);
233231
$order->setIncrementId(self::ORDER_INCREMENT_ID)
234-
->setState(Order::STATE_PROCESSING)
235-
->setStatus($order->getConfig()->getStateDefaultStatus(Order::STATE_PROCESSING))
232+
->setState(\Magento\Sales\Model\Order::STATE_PROCESSING)
233+
->setStatus($order->getConfig()->getStateDefaultStatus(\Magento\Sales\Model\Order::STATE_PROCESSING))
236234
->setSubtotal($orderTotal)
237235
->setBaseSubtotal($orderTotal)
238236
->setGrandTotal($orderTotal)
@@ -273,7 +271,8 @@ private function createOrderOnNumericStore(StoreInterface $store): OrderInterfac
273271
*/
274272
private function createOrderAddresses(): array
275273
{
276-
$billingAddress = $this->objectManager->get(AddressFactory::class)->create()->setData([
274+
$billingAddress = $this->objectManager->get(\Magento\Sales\Model\Order\AddressFactory::class)
275+
->create()->setData([
277276
'region' => 'CA',
278277
'region_id' => '12',
279278
'postcode' => '11111',
@@ -284,11 +283,11 @@ private function createOrderAddresses(): array
284283
'email' => 'admin@example.com',
285284
'telephone' => '11111111',
286285
'country_id' => 'US',
287-
'address_type' => Address::TYPE_BILLING
286+
'address_type' => self::ADDRESS_TYPE_BILLING
288287
]);
289288

290289
$shippingAddress = clone $billingAddress;
291-
$shippingAddress->setId(null)->setAddressType(Address::TYPE_SHIPPING);
290+
$shippingAddress->setId(null)->setAddressType(self::ADDRESS_TYPE_SHIPPING);
292291

293292
return [
294293
'billing' => $billingAddress,
@@ -306,7 +305,7 @@ private function createOrderAddresses(): array
306305
*/
307306
private function createOrderItem($product, float $productPrice, float $orderTotal)
308307
{
309-
return $this->objectManager->get(OrderItemInterfaceFactory::class)->create()
308+
return $this->objectManager->get(\Magento\Sales\Api\Data\OrderItemInterfaceFactory::class)->create()
310309
->setProductId($product->getId())
311310
->setQtyOrdered(self::ORDER_QTY)
312311
->setBasePrice($productPrice)
@@ -327,13 +326,14 @@ private function createOrderItem($product, float $productPrice, float $orderTota
327326
*/
328327
private function createAndSaveInvoice(OrderInterface $order): void
329328
{
330-
$invoice = $this->objectManager->get(InvoiceManagementInterface::class)->prepareInvoice($order);
329+
$invoice = $this->objectManager->get(\Magento\Sales\Api\InvoiceManagementInterface::class)
330+
->prepareInvoice($order);
331331
$invoice->register();
332332
$invoice->setIncrementId($order->getIncrementId());
333333
$order = $invoice->getOrder();
334334
$order->setIsInProcess(true);
335335

336-
$transactionSave = $this->objectManager->create(Transaction::class);
336+
$transactionSave = $this->objectManager->create(\Magento\Framework\DB\Transaction::class);
337337
$transactionSave->addObject($invoice)->addObject($order)->save();
338338
}
339339

@@ -350,14 +350,14 @@ private function createCreditmemoForOrder(OrderInterface $order): CreditmemoInte
350350

351351
$creditmemo = $this->creditmemoFactory->createByOrder($order, $order->getData());
352352
$creditmemo->setOrder($order);
353-
$creditmemo->setState(Creditmemo::STATE_OPEN);
353+
$creditmemo->setState(self::CREDITMEMO_STATE_OPEN);
354354
$creditmemo->setIncrementId($order->getIncrementId() . '-CM');
355355

356356
$this->creditmemoRepository->save($creditmemo);
357357

358358
$this->assertNotNull($creditmemo->getId());
359359
$this->assertEquals($order->getId(), $creditmemo->getOrderId());
360-
$this->assertEquals(Creditmemo::STATE_OPEN, $creditmemo->getState());
360+
$this->assertEquals(self::CREDITMEMO_STATE_OPEN, $creditmemo->getState());
361361
$this->assertGreaterThan(0, $creditmemo->getGrandTotal());
362362

363363
return $creditmemo;

0 commit comments

Comments
 (0)