Skip to content

Commit 54433cd

Browse files
rachanarachana
authored andcommitted
BUG#AC-6920:Fix with unit test covered
1 parent 8c1e386 commit 54433cd

File tree

2 files changed

+123
-2
lines changed

2 files changed

+123
-2
lines changed

app/code/Magento/QuoteGraphQl/Model/Resolver/MaskedCartId.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class MaskedCartId implements ResolverInterface
4444
*/
4545
public function __construct(
4646
QuoteIdToMaskedQuoteIdInterface $quoteIdToMaskedQuoteId,
47-
QuoteIdMaskFactory $quoteIdMaskFactory,
47+
QuoteIdMaskFactory $quoteIdMaskFactory,
4848
QuoteIdMaskResourceModel $quoteIdMaskResourceModel
4949
) {
5050
$this->quoteIdToMaskedQuoteId = $quoteIdToMaskedQuoteId;
@@ -78,7 +78,6 @@ private function getQuoteMaskId(int $quoteId): string
7878
{
7979
try {
8080
$maskedId =$this->ensureQuoteMaskExist($quoteId);
81-
//$maskedId = $this->quoteIdToMaskedQuoteId->execute($quoteId);
8281
} catch (NoSuchEntityException $exception) {
8382
throw new GraphQlNoSuchEntityException(__('Current user does not have an active cart.'));
8483
}
@@ -109,3 +108,4 @@ private function ensureQuoteMaskExist(int $quoteId): string
109108
}
110109

111110
}
111+
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
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\Test\Unit\Model\Resolver;
9+
10+
use Magento\Framework\Exception\LocalizedException;
11+
use Magento\Framework\GraphQl\Config\Element\Field;
12+
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
13+
use Magento\GraphQl\Model\Query\Context;
14+
use Magento\Quote\Model\QuoteIdMaskFactory;
15+
use Magento\Quote\Model\QuoteIdToMaskedQuoteIdInterface;
16+
use Magento\Quote\Model\ResourceModel\Quote\QuoteIdMask as QuoteIdMaskResourceModel;
17+
use Magento\QuoteGraphQl\Model\Resolver\Cart;
18+
use Magento\QuoteGraphQl\Model\Resolver\MaskedCartId;
19+
use PHPUnit\Framework\MockObject\MockObject;
20+
use PHPUnit\Framework\TestCase;
21+
22+
class MaskedCartIdTest extends TestCase
23+
{
24+
/**
25+
* @var MaskedCartId
26+
*/
27+
private MaskedCartId $maskedCartId;
28+
29+
/**
30+
* @var QuoteIdToMaskedQuoteIdInterface|MockObject
31+
*/
32+
private QuoteIdToMaskedQuoteIdInterface $quoteIdToMaskedQuoteIdMock;
33+
34+
/**
35+
* @var QuoteIdMaskFactory|MockObject
36+
*/
37+
private QuoteIdMaskFactory $quoteIdMaskFactoryMock;
38+
39+
/**
40+
* @var QuoteIdMaskResourceModel|MockObject
41+
*/
42+
private QuoteIdMaskResourceModel $quoteIdMaskResourceModelMock;
43+
44+
/**
45+
* @var Field|MockObject
46+
*/
47+
private Field $fieldMock;
48+
49+
/**
50+
* @var ResolveInfo|MockObject
51+
*/
52+
private ResolveInfo $resolveInfoMock;
53+
54+
/**
55+
* @var Context|MockObject
56+
*/
57+
private Context $contextMock;
58+
59+
/**
60+
* @var cart|MockObject
61+
*/
62+
private Cart $cartMock;
63+
64+
/**
65+
* @var array
66+
*/
67+
private array $valueMock = [];
68+
69+
protected function setUp(): void
70+
{
71+
$this->quoteIdToMaskedQuoteIdMock = $this->createMock(QuoteIdToMaskedQuoteIdInterface::class);
72+
$this->quoteIdMaskFactoryMock = $this->createMock(QuoteIdMaskFactory::class);
73+
$this->quoteIdMaskResourceModelMock = $this->createMock(QuoteIdMaskResourceModel::class);
74+
$this->fieldMock = $this->createMock(Field::class);
75+
$this->resolveInfoMock = $this->createMock(ResolveInfo::class);
76+
$this->contextMock = $this->createMock(Context::class);
77+
$this->cartMock = $this->getMockBuilder(Cart::class)
78+
->disableOriginalConstructor()
79+
->addMethods(['getId'])
80+
->getMock();
81+
$this->quoteIdMaskResourceModelMock = $this->getMockBuilder(QuoteIdMaskResourceModel::class)
82+
->disableOriginalConstructor()
83+
->addMethods(
84+
[
85+
'getQuoteMaskId',
86+
'ensureQuoteMaskExist'
87+
]
88+
)
89+
->getMock();
90+
$this->maskedCartId = new MaskedCartId(
91+
$this->quoteIdToMaskedQuoteIdMock,
92+
$this->quoteIdMaskFactoryMock,
93+
$this->quoteIdMaskResourceModelMock
94+
);
95+
}
96+
public function testResolveWithoutModelInValueParameter(): void
97+
{
98+
$this->expectException(LocalizedException::class);
99+
$this->expectExceptionMessage('"model" value should be specified');
100+
$this->maskedCartId->resolve($this->fieldMock, $this->contextMock, $this->resolveInfoMock, $this->valueMock);
101+
}
102+
103+
public function testResolve(): void
104+
{
105+
$this->valueMock = ['model' => $this->valueMock];
106+
$this->cartMock
107+
->expects($this->any())
108+
->method('getId');
109+
$this->quoteIdMaskResourceModelMock
110+
->expects($this->any())
111+
->method('getQuoteMaskId')
112+
->willReturn('maskedId');
113+
$this->quoteIdMaskResourceModelMock
114+
->expects($this->any())
115+
->method('ensureQuoteMaskExist')
116+
->willReturn('maskedId');
117+
118+
}
119+
}
120+
121+

0 commit comments

Comments
 (0)