Skip to content

Commit 5e4adb8

Browse files
committed
GraphQL-432: Created separate class GetMaskedQuoteIdByReversedQuoteId and replaced method in one api-functional test
1 parent c427332 commit 5e4adb8

File tree

2 files changed

+72
-16
lines changed

2 files changed

+72
-16
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\QuoteGraphQl\Model;
9+
10+
use Magento\Quote\Model\ResourceModel\Quote as QuoteResource;
11+
use Magento\Quote\Model\QuoteIdToMaskedQuoteIdInterface;
12+
use Magento\Quote\Model\QuoteFactory;
13+
14+
class GetMaskedQuoteIdByReversedQuoteId
15+
{
16+
/**
17+
* @var QuoteFactory
18+
*/
19+
private $quoteFactory;
20+
21+
/**
22+
* @var QuoteResource
23+
*/
24+
private $quoteResource;
25+
26+
/**
27+
* @var QuoteIdToMaskedQuoteIdInterface
28+
*/
29+
private $quoteIdToMaskedId;
30+
31+
/**
32+
* @param QuoteFactory $quoteFactory
33+
* @param QuoteResource $quoteResource
34+
* @param QuoteIdToMaskedQuoteIdInterface $quoteIdToMaskedId
35+
*/
36+
public function __construct(
37+
QuoteFactory $quoteFactory,
38+
QuoteResource $quoteResource,
39+
QuoteIdToMaskedQuoteIdInterface $quoteIdToMaskedId
40+
) {
41+
$this->quoteFactory = $quoteFactory;
42+
$this->quoteResource = $quoteResource;
43+
$this->quoteIdToMaskedId = $quoteIdToMaskedId;
44+
}
45+
46+
/**
47+
* @param string $reversedQuoteId
48+
* @return string
49+
* @throws \Magento\Framework\Exception\NoSuchEntityException
50+
*/
51+
public function execute(string $reversedQuoteId): string
52+
{
53+
$quote = $this->quoteFactory->create();
54+
$this->quoteResource->load($quote, $reversedQuoteId, 'reserved_order_id');
55+
56+
return $this->quoteIdToMaskedId->execute((int)$quote->getId());
57+
}
58+
}

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

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Magento\Quote\Model\QuoteFactory;
1414
use Magento\Quote\Model\QuoteIdToMaskedQuoteIdInterface;
1515
use Magento\Quote\Model\ResourceModel\Quote as QuoteResource;
16+
use Magento\QuoteGraphQl\Model\GetMaskedQuoteIdByReversedQuoteId;
1617
use Magento\TestFramework\Helper\Bootstrap;
1718
use Magento\TestFramework\TestCase\GraphQlAbstract;
1819
use Magento\TestFramework\ObjectManager;
@@ -37,6 +38,11 @@ class SetShippingAddressOnCartTest extends GraphQlAbstract
3738
*/
3839
private $quoteIdToMaskedId;
3940

41+
/**
42+
* @var GetMaskedQuoteIdByReversedQuoteId
43+
*/
44+
private $getMaskedQuoteIdByReversedQuoteId;
45+
4046
/**
4147
* @var CustomerTokenServiceInterface
4248
*/
@@ -47,16 +53,20 @@ protected function setUp()
4753
$objectManager = Bootstrap::getObjectManager();
4854
$this->quoteResource = $objectManager->get(QuoteResource::class);
4955
$this->quoteFactory = $objectManager->get(QuoteFactory::class);
56+
$this->getMaskedQuoteIdByReversedQuoteId = $objectManager->get(GetMaskedQuoteIdByReversedQuoteId::class);
5057
$this->quoteIdToMaskedId = $objectManager->get(QuoteIdToMaskedQuoteIdInterface::class);
5158
$this->customerTokenService = $objectManager->get(CustomerTokenServiceInterface::class);
5259
}
5360

5461
/**
5562
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php
63+
*
64+
* @throws \Exception
65+
* @throws \Magento\Framework\Exception\NoSuchEntityException
5666
*/
5767
public function testSetNewShippingAddressByGuest()
5868
{
59-
$maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId('test_order_with_simple_product_without_address');
69+
$maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId->execute('test_order_with_simple_product_without_address');
6070

6171
$query = <<<QUERY
6272
mutation {
@@ -116,7 +126,7 @@ public function testSetNewShippingAddressByGuest()
116126
*/
117127
public function testSetShippingAddressFromAddressBookByGuest()
118128
{
119-
$maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId('test_order_with_simple_product_without_address');
129+
$maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId->execute('test_order_with_simple_product_without_address');
120130

121131
$query = <<<QUERY
122132
mutation {
@@ -284,7 +294,7 @@ public function testSetNotExistedShippingAddressFromAddressBook()
284294
*/
285295
public function testSetShippingAddressWithoutAddresses()
286296
{
287-
$maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId('test_order_with_simple_product_without_address');
297+
$maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId->execute('test_order_with_simple_product_without_address');
288298

289299
$query = <<<QUERY
290300
mutation {
@@ -361,7 +371,7 @@ public function testSetNewShippingAddressAndFromAddressBookAtSameTime()
361371
*/
362372
public function testSetMultipleNewShippingAddresses()
363373
{
364-
$maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId('test_order_with_simple_product_without_address');
374+
$maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId->execute('test_order_with_simple_product_without_address');
365375

366376
$query = <<<QUERY
367377
mutation {
@@ -512,18 +522,6 @@ private function getHeaderMap(string $username = '[email protected]', string
512522
return $headerMap;
513523
}
514524

515-
/**
516-
* @param string $reversedQuoteId
517-
* @return string
518-
*/
519-
private function getMaskedQuoteIdByReversedQuoteId(string $reversedQuoteId): string
520-
{
521-
$quote = $this->quoteFactory->create();
522-
$this->quoteResource->load($quote, $reversedQuoteId, 'reserved_order_id');
523-
524-
return $this->quoteIdToMaskedId->execute((int)$quote->getId());
525-
}
526-
527525
/**
528526
* @param string $reversedQuoteId
529527
* @param int $customerId

0 commit comments

Comments
 (0)