Skip to content

Commit 8f39ac3

Browse files
committed
Merge remote-tracking branch 'community_Melnychuk_Alexandr/non-numeric-value-encountered' into gl_pr_arrows_may26_2022
2 parents b53582a + b692ea6 commit 8f39ac3

File tree

2 files changed

+47
-3
lines changed

2 files changed

+47
-3
lines changed

app/code/Magento/Checkout/Controller/Sidebar/UpdateItemQty.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@
1414
use Magento\Framework\Exception\LocalizedException;
1515
use Magento\Framework\Json\Helper\Data;
1616
use Psr\Log\LoggerInterface;
17+
use Magento\Framework\App\Action\HttpPostActionInterface;
1718

18-
class UpdateItemQty extends Action
19+
class UpdateItemQty extends Action implements HttpPostActionInterface
1920
{
2021
/**
2122
* @var Sidebar
@@ -61,12 +62,12 @@ public function __construct(
6162
}
6263

6364
/**
64-
* @return $this
65+
* @inheritdoc
6566
*/
6667
public function execute()
6768
{
6869
$itemId = (int)$this->getRequest()->getParam('item_id');
69-
$itemQty = $this->getRequest()->getParam('item_qty') * 1;
70+
$itemQty = (float)$this->getRequest()->getParam('item_qty') * 1;
7071
$itemQty = $this->quantityProcessor->prepareQuantity($itemQty);
7172

7273
try {

app/code/Magento/Checkout/Test/Unit/Controller/Sidebar/UpdateItemQtyTest.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,4 +244,47 @@ public function testExecuteWithException(): void
244244

245245
$this->assertEquals('json represented', $this->updateItemQty->execute());
246246
}
247+
248+
/**
249+
* @return void
250+
*/
251+
public function testExecuteWithWrongRequestParams(): void
252+
{
253+
$this->requestMock
254+
->method('getParam')
255+
->withConsecutive(['item_id'], ['item_qty'])
256+
->willReturnOnConsecutiveCalls(0, 'error');
257+
258+
$this->sidebarMock->expects($this->once())
259+
->method('checkQuoteItem')
260+
->with(0)
261+
->willThrowException(new LocalizedException(__('Error!')));
262+
263+
$this->sidebarMock->expects($this->once())
264+
->method('getResponseData')
265+
->with('Error!')
266+
->willReturn(
267+
[
268+
'success' => false,
269+
'error_message' => 'Error!'
270+
]
271+
);
272+
273+
$this->jsonHelperMock->expects($this->once())
274+
->method('jsonEncode')
275+
->with(
276+
[
277+
'success' => false,
278+
'error_message' => 'Error!'
279+
]
280+
)
281+
->willReturn('json encoded');
282+
283+
$this->responseMock->expects($this->once())
284+
->method('representJson')
285+
->with('json encoded')
286+
->willReturn('json represented');
287+
288+
$this->assertEquals('json represented', $this->updateItemQty->execute());
289+
}
247290
}

0 commit comments

Comments
 (0)