Skip to content

Commit c0df80b

Browse files
committed
Tests refactoring
1 parent 74b20cb commit c0df80b

File tree

4 files changed

+45
-48
lines changed

4 files changed

+45
-48
lines changed

dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/AddSimpleProductToCartTest.php

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77

88
namespace Magento\GraphQl\Quote;
99

10-
use Magento\TestFramework\Helper\Bootstrap;
11-
use Magento\TestFramework\TestCase\GraphQlAbstract;
10+
use Magento\Catalog\Api\ProductCustomOptionRepositoryInterface;
1211
use Magento\Quote\Model\QuoteFactory;
1312
use Magento\Quote\Model\QuoteIdToMaskedQuoteIdInterface;
1413
use Magento\Quote\Model\ResourceModel\Quote as QuoteResource;
15-
use Magento\Catalog\Api\ProductCustomOptionRepositoryInterface;
14+
use Magento\TestFramework\Helper\Bootstrap;
15+
use Magento\TestFramework\TestCase\GraphQlAbstract;
1616

1717
class AddSimpleProductToCartTest extends GraphQlAbstract
1818
{
@@ -65,13 +65,7 @@ public function testAddSimpleProductWithOptions()
6565
/* Generate customizable options fragment for GraphQl request */
6666
$queryCustomizableOptions = preg_replace('/"([^"]+)"\s*:\s*/', '$1:', json_encode($customOptionsValues));
6767

68-
$this->quoteResource->load(
69-
$this->quote,
70-
'test_order_1',
71-
'reserved_order_id'
72-
);
73-
74-
$maskedQuoteId = $this->quoteIdToMaskedId->execute((int)$this->quote->getId());
68+
$maskedQuoteId = $this->getMaskedQuoteId();
7569

7670
$query = <<<QUERY
7771
mutation {
@@ -157,7 +151,7 @@ public function testAddSimpleProductToCartWithNegativeQty()
157151
/**
158152
* @return string
159153
*/
160-
public function getMaskedQuoteId() : string
154+
private function getMaskedQuoteId() : string
161155
{
162156
$quote = $this->quoteFactory->create();
163157
$this->quoteResource->load($quote, 'test_order_1', 'reserved_order_id');
@@ -251,13 +245,7 @@ public function testAddSimpleProductWithNoRequiredOptionsSet()
251245
$sku = 'simple';
252246
$qty = 1;
253247

254-
$this->quoteResource->load(
255-
$this->quote,
256-
'test_order_1',
257-
'reserved_order_id'
258-
);
259-
260-
$maskedQuoteId = $this->quoteIdToMaskedId->execute((int)$this->quote->getId());
248+
$maskedQuoteId = $this->getMaskedQuoteId();
261249

262250
$query = <<<QUERY
263251
mutation {

dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/AddVirtualProductToCartTest.php

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,23 @@
77

88
namespace Magento\GraphQl\Quote;
99

10+
use Magento\Quote\Model\QuoteFactory;
1011
use Magento\TestFramework\Helper\Bootstrap;
1112
use Magento\TestFramework\TestCase\GraphQlAbstract;
12-
use Magento\Quote\Model\Quote;
1313
use Magento\Quote\Model\QuoteIdToMaskedQuoteIdInterface;
1414
use Magento\Quote\Model\ResourceModel\Quote as QuoteResource;
1515
use Magento\Catalog\Api\ProductCustomOptionRepositoryInterface;
1616

1717
class AddVirtualProductToCartTest extends GraphQlAbstract
1818
{
1919
/**
20-
* @var QuoteResource
20+
* @var QuoteFactory
2121
*/
22-
private $quoteResource;
22+
private $quoteFactory;
2323
/**
24-
* @var Quote
24+
* @var QuoteResource
2525
*/
26-
private $quote;
26+
private $quoteResource;
2727

2828
/**
2929
* @var QuoteIdToMaskedQuoteIdInterface
@@ -42,7 +42,7 @@ protected function setUp()
4242
{
4343
$objectManager = Bootstrap::getObjectManager();
4444
$this->quoteResource = $objectManager->get(QuoteResource::class);
45-
$this->quote = $objectManager->create(Quote::class);
45+
$this->quoteFactory = $objectManager->get(QuoteFactory::class);
4646
$this->quoteIdToMaskedId = $objectManager->get(QuoteIdToMaskedQuoteIdInterface::class);
4747
$this->productCustomOptionsRepository = $objectManager->get(ProductCustomOptionRepositoryInterface::class);
4848
}
@@ -64,13 +64,7 @@ public function testAddVirtualProductWithOptions()
6464
/* Generate customizable options fragment for GraphQl request */
6565
$queryCustomizableOptions = preg_replace('/"([^"]+)"\s*:\s*/', '$1:', json_encode($customOptionsValues));
6666

67-
$this->quoteResource->load(
68-
$this->quote,
69-
'test_order_1',
70-
'reserved_order_id'
71-
);
72-
73-
$maskedQuoteId = $this->quoteIdToMaskedId->execute((int)$this->quote->getId());
67+
$maskedQuoteId = $this->getMaskedQuoteId();
7468

7569
$query = <<<QUERY
7670
mutation {
@@ -130,13 +124,7 @@ public function testAddVirtualProductWithNoRequiredOptionsSet()
130124
$sku = 'virtual';
131125
$qty = 1;
132126

133-
$this->quoteResource->load(
134-
$this->quote,
135-
'test_order_1',
136-
'reserved_order_id'
137-
);
138-
139-
$maskedQuoteId = $this->quoteIdToMaskedId->execute((int)$this->quote->getId());
127+
$maskedQuoteId = $this->getMaskedQuoteId();
140128

141129
$query = <<<QUERY
142130
mutation {
@@ -206,4 +194,15 @@ private function getCustomOptionsValuesForQuery(string $sku): array
206194

207195
return $customOptionsValues;
208196
}
197+
198+
/**
199+
* @return string
200+
*/
201+
public function getMaskedQuoteId() : string
202+
{
203+
$quote = $this->quoteFactory->create();
204+
$this->quoteResource->load($quote, 'test_order_1', 'reserved_order_id');
205+
206+
return $this->quoteIdToMaskedId->execute((int)$quote->getId());
207+
}
209208
}

dev/tests/integration/testsuite/Magento/Catalog/_files/product_virtual.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,12 @@
44
* See COPYING.txt for license details.
55
*/
66

7-
/** @var $product \Magento\Catalog\Model\Product */
8-
$product = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(\Magento\Catalog\Model\Product::class);
7+
use Magento\Catalog\Model\ProductFactory;
8+
use Magento\TestFramework\Helper\Bootstrap;
9+
use Magento\Catalog\Model\ResourceModel\Product as ProductResource;
10+
11+
$productFactory = Bootstrap::getObjectManager()->get(ProductFactory::class);
12+
$product = $productFactory->create();
913
$product->setTypeId(\Magento\Catalog\Model\Product\Type::TYPE_VIRTUAL)
1014
->setId(21)
1115
->setAttributeSetId(4)
@@ -22,4 +26,7 @@
2226
'is_in_stock' => 1,
2327
'manage_stock' => 1,
2428
]
25-
)->save();
29+
);
30+
/** @var ProductResource $productResource */
31+
$productResource = Bootstrap::getObjectManager()->create(ProductResource::class);
32+
$productResource->save($product);

dev/tests/integration/testsuite/Magento/Catalog/_files/product_virtual_rollback.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,25 @@
44
* See COPYING.txt for license details.
55
*/
66

7-
/** @var \Magento\Framework\Registry $registry */
8-
$registry = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(\Magento\Framework\Registry::class);
7+
use Magento\Catalog\Api\ProductRepositoryInterface;
8+
use Magento\Framework\Exception\NoSuchEntityException;
9+
use Magento\Framework\Exception\StateException;
10+
use Magento\TestFramework\Helper\Bootstrap;
11+
12+
$registry = Bootstrap::getObjectManager()->get(\Magento\Framework\Registry::class);
913

1014
$registry->unregister('isSecureArea');
1115
$registry->register('isSecureArea', true);
1216

13-
/** @var \Magento\Catalog\Api\ProductRepositoryInterface $productRepository */
14-
$productRepository = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
15-
->create(\Magento\Catalog\Api\ProductRepositoryInterface::class);
17+
$productRepository = Bootstrap::getObjectManager()
18+
->create(ProductRepositoryInterface::class);
1619

1720
try {
1821
$product = $productRepository->get('virtual-product', false, null, true);
1922
$productRepository->delete($product);
20-
} catch (\Magento\Framework\Exception\NoSuchEntityException $exception) {
23+
} catch (NoSuchEntityException $exception) {
2124
//Product already removed
22-
} catch (\Magento\Framework\Exception\StateException $exception) {
25+
} catch (StateException $exception) {
2326
}
2427

2528
$registry->unregister('isSecureArea');

0 commit comments

Comments
 (0)