Skip to content

Commit 6b01af9

Browse files
committed
Refactor Unit Tests too
1 parent 4b0fdfc commit 6b01af9

File tree

1 file changed

+8
-44
lines changed

1 file changed

+8
-44
lines changed

app/code/Magento/Quote/Test/Unit/Model/ChangeQuoteControlTest.php

Lines changed: 8 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -16,57 +16,36 @@
1616

1717
/**
1818
* Unit test for \Magento\Quote\Model\ChangeQuoteControl
19-
*
20-
* Class \Magento\Quote\Test\Unit\Model\ChangeQuoteControlTest
2119
*/
2220
class ChangeQuoteControlTest extends TestCase
2321
{
24-
/**
25-
* @var ObjectManager
26-
*/
27-
protected $objectManager;
28-
2922
/**
3023
* @var ChangeQuoteControl
3124
*/
3225
protected $model;
3326

3427
/**
35-
* @var MockObject
28+
* @var MockObject|UserContextInterface
3629
*/
3730
protected $userContextMock;
3831

3932
/**
40-
* @var MockObject
33+
* @var MockObject|CartInterface
4134
*/
4235
protected $quoteMock;
4336

4437
protected function setUp(): void
4538
{
46-
$this->objectManager = new ObjectManager($this);
4739
$this->userContextMock = $this->getMockForAbstractClass(UserContextInterface::class);
4840

49-
$this->model = $this->objectManager->getObject(
50-
ChangeQuoteControl::class,
51-
[
52-
'userContext' => $this->userContextMock
53-
]
54-
);
55-
56-
$this->quoteMock = $this->getMockForAbstractClass(
57-
CartInterface::class,
58-
[],
59-
'',
60-
false,
61-
true,
62-
true,
63-
['getCustomerId']
64-
);
41+
$this->model = new ChangeQuoteControl($this->userContextMock);
42+
43+
$this->quoteMock = $this->getMockBuilder(CartInterface::class)
44+
->disableOriginalConstructor()
45+
->addMethods(['getCustomerId'])
46+
->getMockForAbstractClass();
6547
}
6648

67-
/**
68-
* Test if the quote is belonged to customer
69-
*/
7049
public function testIsAllowedIfTheQuoteIsBelongedToCustomer()
7150
{
7251
$quoteCustomerId = 1;
@@ -80,9 +59,6 @@ public function testIsAllowedIfTheQuoteIsBelongedToCustomer()
8059
$this->assertTrue($this->model->isAllowed($this->quoteMock));
8160
}
8261

83-
/**
84-
* Test if the quote is not belonged to customer
85-
*/
8662
public function testIsAllowedIfTheQuoteIsNotBelongedToCustomer()
8763
{
8864
$currentCustomerId = 1;
@@ -98,9 +74,6 @@ public function testIsAllowedIfTheQuoteIsNotBelongedToCustomer()
9874
$this->assertFalse($this->model->isAllowed($this->quoteMock));
9975
}
10076

101-
/**
102-
* Test if the quote is belonged to guest and the context is guest
103-
*/
10477
public function testIsAllowedIfQuoteIsBelongedToGuestAndContextIsGuest()
10578
{
10679
$quoteCustomerId = null;
@@ -111,9 +84,6 @@ public function testIsAllowedIfQuoteIsBelongedToGuestAndContextIsGuest()
11184
$this->assertTrue($this->model->isAllowed($this->quoteMock));
11285
}
11386

114-
/**
115-
* Test if the quote is belonged to customer and the context is guest
116-
*/
11787
public function testIsAllowedIfQuoteIsBelongedToCustomerAndContextIsGuest()
11888
{
11989
$quoteCustomerId = 1;
@@ -124,19 +94,13 @@ public function testIsAllowedIfQuoteIsBelongedToCustomerAndContextIsGuest()
12494
$this->assertFalse($this->model->isAllowed($this->quoteMock));
12595
}
12696

127-
/**
128-
* Test if the context is admin
129-
*/
13097
public function testIsAllowedIfContextIsAdmin()
13198
{
13299
$this->userContextMock->expects($this->any())->method('getUserType')
133100
->willReturn(UserContextInterface::USER_TYPE_ADMIN);
134101
$this->assertTrue($this->model->isAllowed($this->quoteMock));
135102
}
136103

137-
/**
138-
* Test if the context is integration
139-
*/
140104
public function testIsAllowedIfContextIsIntegration()
141105
{
142106
$this->userContextMock->expects($this->any())->method('getUserType')

0 commit comments

Comments
 (0)