Skip to content

Commit 0abcd0e

Browse files
committed
AC-6920::fixed failing unit test case in graphql resolver
1 parent 3413844 commit 0abcd0e

File tree

1 file changed

+47
-36
lines changed

1 file changed

+47
-36
lines changed

app/code/Magento/QuoteGraphQl/Test/Unit/Model/Resolver/MaskedCartIdTest.php

Lines changed: 47 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,13 @@
1515
use Magento\Quote\Model\QuoteIdToMaskedQuoteIdInterface;
1616
use Magento\Quote\Model\ResourceModel\Quote\QuoteIdMask as QuoteIdMaskResourceModel;
1717
use Magento\QuoteGraphQl\Model\Resolver\Cart;
18+
use Magento\Quote\Model\Quote;
1819
use Magento\QuoteGraphQl\Model\Resolver\MaskedCartId;
1920
use Magento\Sales\Model\ResourceModel\Order\Collection;
2021
use Magento\Sales\Model\ResourceModel\Order\CollectionFactory;
2122
use PHPUnit\Framework\MockObject\MockObject;
2223
use PHPUnit\Framework\TestCase;
24+
use Magento\Quote\Model\QuoteIdMask;
2325

2426
class MaskedCartIdTest extends TestCase
2527
{
@@ -63,49 +65,50 @@ class MaskedCartIdTest extends TestCase
6365
*/
6466
private Cart $cartMock;
6567

68+
private Quote $quoteMock;
69+
70+
private QuoteIdMask $quoteIdMask;
6671
/**
6772
* @var array
6873
*/
6974
private array $valueMock = [];
7075

7176
protected function setUp(): void
7277
{
78+
$this->fieldMock = $this->createMock(Field::class);
79+
$this->resolveInfoMock = $this->createMock(ResolveInfo::class);
80+
$this->contextMock = $this->createMock(Context::class);
7381
$this->quoteIdToMaskedQuoteId = $this->createPartialMock(
7482
QuoteIdToMaskedQuoteIdInterface::class,
7583
['execute']
7684
);
85+
7786
$this->quoteIdMaskFactory = $this->createPartialMock(
7887
QuoteIdMaskFactory ::class,
7988
['create']
8089
);
81-
$this->quoteIdMaskFactory = $this->getMockBuilder(QuoteIdMaskFactory::class)
82-
->disableOriginalConstructor()
83-
->addMethods(['setQuoteId']
84-
)
85-
->getMock();
86-
$this->quoteIdMaskResourceModelMock = $this->createMock(QuoteIdMaskResourceModel::class);
87-
$this->fieldMock = $this->createMock(Field::class);
88-
$this->resolveInfoMock = $this->createMock(ResolveInfo::class);
89-
$this->contextMock = $this->createMock(Context::class);
90-
$this->quoteIdMaskResourceModelMock = $this->getMockBuilder(QuoteIdMaskResourceModel::class)
91-
->disableOriginalConstructor()
92-
->addMethods(
93-
[
94-
'getQuoteMaskId',
95-
'ensureQuoteMaskExist'
96-
]
97-
)
98-
->getMock();
99-
$this->cartMock = $this->getMockBuilder(Cart::class)
100-
->disableOriginalConstructor()
101-
->addMethods(['setQuoteId','getId'])
102-
->getMock();
90+
/* $this->quoteIdMaskResourceModelMock = $this->createMock(QuoteIdMaskResourceModel::class,
91+
['setQuoteId']);*/
92+
$this->quoteIdMaskResourceModelMock = $this->getMockBuilder(QuoteIdMaskResourceModel::class)
93+
->disableOriginalConstructor()
94+
->addMethods(
95+
[
96+
'setQuoteId',
97+
])
98+
->onlyMethods(['save'])
99+
->getMock();
103100
$this->maskedCartId = new MaskedCartId(
104101
$this->quoteIdToMaskedQuoteId,
105102
$this->quoteIdMaskFactory,
106103
$this->quoteIdMaskResourceModelMock
107104
);
108-
}
105+
$this->quoteMock = $this->getMockBuilder(Quote::class)
106+
->disableOriginalConstructor()
107+
->getMock();
108+
$this->quoteIdMask = $this->getMockBuilder(QuoteIdMask::class)
109+
->disableOriginalConstructor()
110+
->getMock();
111+
}
109112

110113
public function testResolveWithoutModelInValueParameter(): void
111114
{
@@ -116,19 +119,27 @@ public function testResolveWithoutModelInValueParameter(): void
116119

117120
public function testResolve(): void
118121
{
119-
$this->valueMock = ['model' => $this->cartMock];
120-
$quoteIdMask = $this->createPartialMock(
121-
QuoteIdMaskResourceModel::class,
122-
['setQuoteId']
123-
);
124-
$this->quoteIdToMaskedQuoteId
125-
->expects($this->any())
126-
->method('execute');
127-
// echo get_class($this->quoteIdMaskFactory);die;
128-
// $this->quoteIdMaskFactory->setQuoteId('maskId');
129-
$this->quoteIdMaskFactory->expects($this->once())
130-
->method('create')
131-
->willReturn($quoteIdMask);
122+
$this->valueMock = ['model' => $this->quoteMock];
123+
$cartId = 1;
124+
$this->quoteMock
125+
->expects($this->once())
126+
->method('getId')
127+
->willReturn($cartId);
128+
129+
$this->quoteIdMaskFactory
130+
->expects($this->once())
131+
->method('create')
132+
->willReturn($this->quoteIdMask);
133+
134+
$this->quoteIdMask->setQuoteId($cartId);
135+
136+
$this->quoteIdMaskResourceModelMock
137+
->expects($this->once())
138+
->method('save')
139+
->with( $this->quoteIdMask);
140+
141+
142+
132143
$this->maskedCartId->resolve($this->fieldMock, $this->contextMock, $this->resolveInfoMock, $this->valueMock);
133144
}
134145
}

0 commit comments

Comments
 (0)