Skip to content

Commit 31412e0

Browse files
committed
Cover changes with unit tests
1 parent 36fb3b7 commit 31412e0

File tree

1 file changed

+56
-1
lines changed

1 file changed

+56
-1
lines changed

app/code/Magento/Checkout/Test/Unit/Model/SessionTest.php

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
*/
1010
namespace Magento\Checkout\Test\Unit\Model;
1111

12-
use \Magento\Checkout\Model\Session;
12+
use Magento\Checkout\Model\Session;
13+
use Magento\Framework\Exception\NoSuchEntityException;
1314

1415
/**
1516
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
@@ -374,6 +375,60 @@ public function testGetStepData()
374375
$this->assertEquals($stepData['complex']['key'], $session->getStepData('complex', 'key'));
375376
}
376377

378+
/**
379+
* Ensure that if quote not exist for customer quote will be null
380+
*
381+
* @return void
382+
*/
383+
public function testGetQuote(): void
384+
{
385+
$quoteRepository = $this->createMock(\Magento\Quote\Api\CartRepositoryInterface::class);
386+
$storeManager = $this->getMockForAbstractClass(\Magento\Store\Model\StoreManagerInterface::class);
387+
$customerSession = $this->createMock(\Magento\Customer\Model\Session::class);
388+
$quoteFactory = $this->createMock(\Magento\Quote\Model\QuoteFactory::class);
389+
$quote = $this->createMock(\Magento\Quote\Model\Quote::class);
390+
391+
$quoteFactory->expects($this->once())
392+
->method('create')
393+
->willReturn($quote);
394+
$customerSession->expects($this->exactly(3))
395+
->method('isLoggedIn')
396+
->willReturn(true);
397+
$store = $this->getMockBuilder(\Magento\Store\Model\Store::class)
398+
->disableOriginalConstructor()
399+
->setMethods(['getWebsiteId', '__wakeup'])
400+
->getMock();
401+
$storeManager->expects($this->any())
402+
->method('getStore')
403+
->will($this->returnValue($store));
404+
$storage = $this->getMockBuilder(\Magento\Framework\Session\Storage::class)
405+
->disableOriginalConstructor()
406+
->setMethods(['setData', 'getData'])
407+
->getMock();
408+
$storage->expects($this->at(0))
409+
->method('getData')
410+
->willReturn(1);
411+
$quoteRepository->expects($this->once())
412+
->method('getActiveForCustomer')
413+
->willThrowException(new NoSuchEntityException());
414+
$quote->expects($this->once())
415+
->method('setCustomer')
416+
->with(null);
417+
418+
$constructArguments = $this->_helper->getConstructArguments(
419+
\Magento\Checkout\Model\Session::class,
420+
[
421+
'storeManager' => $storeManager,
422+
'quoteRepository' => $quoteRepository,
423+
'customerSession' => $customerSession,
424+
'storage' => $storage,
425+
'quoteFactory' => $quoteFactory
426+
]
427+
);
428+
$this->_session = $this->_helper->getObject(\Magento\Checkout\Model\Session::class, $constructArguments);
429+
$this->_session->getQuote();
430+
}
431+
377432
public function testSetStepData()
378433
{
379434
$stepData = [

0 commit comments

Comments
 (0)