Skip to content

Commit 8a0cec3

Browse files
rachanarachana
authored andcommitted
BUG#AC-6920:updated testacses with fixes
1 parent 3413844 commit 8a0cec3

File tree

1 file changed

+47
-39
lines changed

1 file changed

+47
-39
lines changed

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

Lines changed: 47 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@
1111
use Magento\Framework\GraphQl\Config\Element\Field;
1212
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
1313
use Magento\GraphQl\Model\Query\Context;
14+
use Magento\Quote\Model\Quote;
15+
use Magento\Quote\Model\QuoteIdMask;
1416
use Magento\Quote\Model\QuoteIdMaskFactory;
1517
use Magento\Quote\Model\QuoteIdToMaskedQuoteIdInterface;
1618
use Magento\Quote\Model\ResourceModel\Quote\QuoteIdMask as QuoteIdMaskResourceModel;
1719
use Magento\QuoteGraphQl\Model\Resolver\Cart;
1820
use Magento\QuoteGraphQl\Model\Resolver\MaskedCartId;
19-
use Magento\Sales\Model\ResourceModel\Order\Collection;
20-
use Magento\Sales\Model\ResourceModel\Order\CollectionFactory;
2121
use PHPUnit\Framework\MockObject\MockObject;
2222
use PHPUnit\Framework\TestCase;
2323

@@ -34,7 +34,7 @@ class MaskedCartIdTest extends TestCase
3434
private QuoteIdToMaskedQuoteIdInterface $quoteIdToMaskedQuoteId;
3535

3636
/**
37-
* @var QuoteIdMaskFactory|MockObject
37+
* @var \Magento\QuoteGraphQl\Test\Unit\Model\Resolver\QuoteIdMaskFactory|MockObject
3838
*/
3939
private QuoteIdMaskFactory $quoteIdMaskFactory;
4040

@@ -59,52 +59,58 @@ class MaskedCartIdTest extends TestCase
5959
private Context $contextMock;
6060

6161
/**
62-
* @var cart|MockObject
62+
* @var Cart|MockObject
6363
*/
6464
private Cart $cartMock;
6565

66+
/**
67+
* @var Quote|MockObject
68+
*/
69+
private Quote $quoteMock;
70+
71+
/**
72+
* @var QuoteIdMask|MockObject
73+
*/
74+
private QuoteIdMask $quoteIdMask;
75+
6676
/**
6777
* @var array
6878
*/
6979
private array $valueMock = [];
7080

7181
protected function setUp(): void
7282
{
83+
$this->fieldMock = $this->createMock(Field::class);
84+
$this->resolveInfoMock = $this->createMock(ResolveInfo::class);
85+
$this->contextMock = $this->createMock(Context::class);
7386
$this->quoteIdToMaskedQuoteId = $this->createPartialMock(
7487
QuoteIdToMaskedQuoteIdInterface::class,
7588
['execute']
7689
);
7790
$this->quoteIdMaskFactory = $this->createPartialMock(
78-
QuoteIdMaskFactory ::class,
91+
QuoteIdMaskFactory::class,
7992
['create']
8093
);
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);
9094
$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();
95+
->disableOriginalConstructor()
96+
->addMethods(
97+
[
98+
'setQuoteId',
99+
]
100+
)
101+
->onlyMethods(['save'])
102+
->getMock();
103103
$this->maskedCartId = new MaskedCartId(
104104
$this->quoteIdToMaskedQuoteId,
105105
$this->quoteIdMaskFactory,
106106
$this->quoteIdMaskResourceModelMock
107107
);
108+
$this->quoteMock = $this->getMockBuilder(Quote::class)
109+
->disableOriginalConstructor()
110+
->getMock();
111+
$this->quoteIdMask = $this->getMockBuilder(QuoteIdMask::class)
112+
->disableOriginalConstructor()
113+
->getMock();
108114
}
109115

110116
public function testResolveWithoutModelInValueParameter(): void
@@ -116,19 +122,21 @@ public function testResolveWithoutModelInValueParameter(): void
116122

117123
public function testResolve(): void
118124
{
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);
125+
$this->valueMock = ['model' => $this->quoteMock];
126+
$cartId = 1;
127+
$this->quoteMock
128+
->expects($this->once())
129+
->method('getId')
130+
->willReturn($cartId);
131+
$this->quoteIdMaskFactory
132+
->expects($this->once())
133+
->method('create')
134+
->willReturn($this->quoteIdMask);
135+
$this->quoteIdMask->setQuoteId($cartId);
136+
$this->quoteIdMaskResourceModelMock
137+
->expects($this->once())
138+
->method('save')
139+
->with($this->quoteIdMask);
132140
$this->maskedCartId->resolve($this->fieldMock, $this->contextMock, $this->resolveInfoMock, $this->valueMock);
133141
}
134142
}

0 commit comments

Comments
 (0)