Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
CustomerGroupRetrieverTest.php
Go to the documentation of this file.
1 <?php
7 
10 
14 class CustomerGroupRetrieverTest extends \PHPUnit\Framework\TestCase
15 {
19  private $retriever;
20 
24  private $quoteSession;
25 
29  private $groupManagement;
30 
34  protected function setUp()
35  {
36  $this->quoteSession = $this->getMockBuilder(Quote::class)
37  ->disableOriginalConstructor()
38  ->setMethods(['getQuoteId', 'getQuote'])
39  ->getMock();
40  $this->groupManagement = $this->getMockBuilder(GroupManagementInterface::class)
41  ->disableOriginalConstructor()
42  ->getMockForAbstractClass();
43 
44  $helper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
45  $this->retriever = $helper->getObject(
46  \Magento\Sales\Model\CustomerGroupRetriever::class,
47  [
48  'quoteSession' => $this->quoteSession,
49  'groupManagement' => $this->groupManagement
50  ]
51  );
52  }
53 
57  public function testGetCustomerGroupIdQuote()
58  {
59  $this->quoteSession->expects($this->atLeastOnce())->method('getQuoteId')->willReturn(1);
60  $quote = $this->getMockBuilder(\Magento\Quote\Model\Quote::class)
61  ->disableOriginalConstructor()
62  ->getMock();
63  $this->quoteSession->expects($this->atLeastOnce())->method('getQuote')->willReturn($quote);
64  $quote->expects($this->once())->method('getCustomerGroupId')->willReturn(2);
65 
66  $this->assertEquals(2, $this->retriever->getCustomerGroupId());
67  }
68 
73  {
74  $this->quoteSession->expects($this->atLeastOnce())->method('getQuoteId')->willReturn(0);
75  $this->quoteSession->expects($this->never())->method('getQuote');
76  $group = $this->getMockBuilder(\Magento\Customer\Api\Data\GroupInterface::class)
77  ->disableOriginalConstructor()
78  ->getMockForAbstractClass();
79  $this->groupManagement->expects($this->once())->method('getNotLoggedInGroup')->willReturn($group);
80  $group->expects($this->once())->method('getId')->willReturn(2);
81 
82  $this->assertEquals(2, $this->retriever->getCustomerGroupId());
83  }
84 }
$helper
Definition: iframe.phtml:13
$quote
$group
Definition: sections.phtml:16