Skip to content

Commit 4dfa556

Browse files
committed
addressed comments: backwards compatibility, inheritance based API and and long var names from codacy/pr
1 parent 2536b10 commit 4dfa556

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

app/code/Magento/Quote/Model/QuoteManagement.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ class QuoteManagement implements \Magento\Quote\Api\CartManagementInterface
140140
/**
141141
* @var \Magento\Quote\Model\Quote\Validator\MinimumOrderAmount\ValidationMessage
142142
*/
143-
private $minimumAmountErrorMessage;
143+
private $minimumAmountMessage;
144144

145145
/**
146146
* @param EventManager $eventManager
@@ -163,7 +163,7 @@ class QuoteManagement implements \Magento\Quote\Api\CartManagementInterface
163163
* @param \Magento\Customer\Model\Session $customerSession
164164
* @param \Magento\Customer\Api\AccountManagementInterface $accountManagement
165165
* @param QuoteFactory $quoteFactory
166-
* @param Quote\Validator\MinimumOrderAmount\ValidationMessage $minimumAmountErrorMessage
166+
* @param Quote\Validator\MinimumOrderAmount\ValidationMessage $minimumAmountMessage
167167
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
168168
*/
169169
public function __construct(
@@ -187,7 +187,7 @@ public function __construct(
187187
\Magento\Customer\Model\Session $customerSession,
188188
\Magento\Customer\Api\AccountManagementInterface $accountManagement,
189189
\Magento\Quote\Model\QuoteFactory $quoteFactory,
190-
\Magento\Quote\Model\Quote\Validator\MinimumOrderAmount\ValidationMessage $minimumAmountErrorMessage
190+
\Magento\Quote\Model\Quote\Validator\MinimumOrderAmount\ValidationMessage $minimumAmountMessage = null
191191
) {
192192
$this->eventManager = $eventManager;
193193
$this->quoteValidator = $quoteValidator;
@@ -209,7 +209,8 @@ public function __construct(
209209
$this->accountManagement = $accountManagement;
210210
$this->customerSession = $customerSession;
211211
$this->quoteFactory = $quoteFactory;
212-
$this->minimumAmountErrorMessage = $minimumAmountErrorMessage;
212+
$this->minimumAmountMessage = $minimumAmountMessage ?: \Magento\Framework\App\ObjectManager::getInstance()
213+
->get(\Magento\Quote\Model\Quote\Validator\MinimumOrderAmount\ValidationMessage::class);
213214
}
214215

215216
/**
@@ -330,7 +331,7 @@ public function placeOrder($cartId, PaymentInterface $paymentMethod = null)
330331
{
331332
$quote = $this->quoteRepository->getActive($cartId);
332333
if (!$quote->validateMinimumAmount($quote->getIsMultiShipping())) {
333-
throw new InputException($this->minimumAmountErrorMessage->getMessage());
334+
throw new InputException($this->minimumAmountMessage->getMessage());
334335
}
335336

336337
if ($paymentMethod) {

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ class QuoteManagementTest extends \PHPUnit_Framework_TestCase
124124
/**
125125
* @var \Magento\Quote\Model\Quote\Validator\MinimumOrderAmount\ValidationMessage
126126
*/
127-
protected $minimumAmountErrorMessage;
127+
private $minimumAmountMessage;
128128

129129
/**
130130
* @var \PHPUnit_Framework_MockObject_MockObject
@@ -256,7 +256,7 @@ protected function setUp()
256256
false
257257
);
258258

259-
$this->minimumAmountErrorMessage = $this->getMock(
259+
$this->minimumAmountMessage = $this->getMock(
260260
\Magento\Quote\Model\Quote\Validator\MinimumOrderAmount\ValidationMessage::class,
261261
['getMessage'],
262262
[],
@@ -288,7 +288,7 @@ protected function setUp()
288288
'customerSession' => $this->customerSessionMock,
289289
'accountManagement' => $this->accountManagementMock,
290290
'quoteFactory' => $this->quoteFactoryMock,
291-
'minimumAmountErrorMessage' => $this->minimumAmountErrorMessage
291+
'minimumAmountMessage' => $this->minimumAmountMessage
292292
]
293293
);
294294

@@ -724,7 +724,7 @@ public function testPlaceOrderIfCustomerIsGuest()
724724
$this->quoteMock->expects($this->once())->method('getIsMultiShipping')->willReturn(false);
725725
$this->quoteMock->expects($this->once())->method('validateMinimumAmount')->with(false)->willReturn(true);
726726

727-
$this->minimumAmountErrorMessage->expects($this->never())->method('getMessage');
727+
$this->minimumAmountMessage->expects($this->never())->method('getMessage');
728728

729729
$addressMock = $this->getMock(\Magento\Quote\Model\Quote\Address::class, ['getEmail'], [], '', false);
730730
$addressMock->expects($this->once())->method('getEmail')->willReturn($email);
@@ -760,7 +760,7 @@ public function testPlaceOrderIfCustomerIsGuest()
760760
'customerSession' => $this->customerSessionMock,
761761
'accountManagement' => $this->accountManagementMock,
762762
'quoteFactory' => $this->quoteFactoryMock,
763-
'minimumAmountErrorMessage' => $this->minimumAmountErrorMessage
763+
'minimumAmountMessage' => $this->minimumAmountMessage
764764
]
765765
);
766766
$orderMock = $this->getMock(
@@ -819,7 +819,7 @@ public function testPlaceOrder()
819819
'customerSession' => $this->customerSessionMock,
820820
'accountManagement' => $this->accountManagementMock,
821821
'quoteFactory' => $this->quoteFactoryMock,
822-
'minimumAmountErrorMessage' => $this->minimumAmountErrorMessage
822+
'minimumAmountMessage' => $this->minimumAmountMessage
823823
]
824824
);
825825
$orderMock = $this->getMock(
@@ -854,7 +854,7 @@ public function testPlaceOrder()
854854
$this->quoteMock->expects($this->once())->method('getIsMultiShipping')->willReturn(false);
855855
$this->quoteMock->expects($this->once())->method('validateMinimumAmount')->with(false)->willReturn(true);
856856

857-
$this->minimumAmountErrorMessage->expects($this->never())->method('getMessage');
857+
$this->minimumAmountMessage->expects($this->never())->method('getMessage');
858858

859859
$service->expects($this->once())->method('submit')->willReturn($orderMock);
860860

@@ -894,7 +894,7 @@ public function testPlaceOrderWithViolationOfMinimumAmount()
894894
$this->quoteMock->expects($this->once())->method('getIsMultiShipping')->willReturn(false);
895895
$this->quoteMock->expects($this->once())->method('validateMinimumAmount')->with(false)->willReturn(false);
896896

897-
$this->minimumAmountErrorMessage->expects($this->once())
897+
$this->minimumAmountMessage->expects($this->once())
898898
->method('getMessage')
899899
->willReturn(__('Incorrect amount'));
900900

@@ -928,7 +928,7 @@ public function testPlaceOrderWithViolationOfMinimumAmount()
928928
'customerSession' => $this->customerSessionMock,
929929
'accountManagement' => $this->accountManagementMock,
930930
'quoteFactory' => $this->quoteFactoryMock,
931-
'minimumAmountErrorMessage' => $this->minimumAmountErrorMessage
931+
'minimumAmountMessage' => $this->minimumAmountMessage
932932
]
933933
);
934934

0 commit comments

Comments
 (0)