Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ItemPoolTest.php
Go to the documentation of this file.
1 <?php
7 
8 class ItemPoolTest extends \PHPUnit\Framework\TestCase
9 {
13  protected $objectManagerMock;
14 
18  protected $defaultItemId = 'default_item_id';
19 
23  protected $itemMap = [];
24 
28  protected $model;
29 
30  protected function setUp()
31  {
32  $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
33 
34  $this->objectManagerMock = $this->createMock(\Magento\Framework\ObjectManagerInterface::class);
35  $this->model = $objectManager->getObject(
36  \Magento\Checkout\CustomerData\ItemPool::class,
37  [
38  'objectManager' => $this->objectManagerMock,
39  'defaultItemId' => $this->defaultItemId,
40  'itemMap' => $this->itemMap,
41  ]
42  );
43  }
44 
46  {
47  $itemData = ['key' => 'value'];
48  $productType = 'product_type';
49  $quoteItemMock = $this->createMock(\Magento\Quote\Model\Quote\Item::class);
50  $quoteItemMock->expects($this->once())->method('getProductType')->willReturn($productType);
51 
52  $itemMock = $this->createMock(\Magento\Checkout\CustomerData\ItemInterface::class);
53  $itemMock->expects($this->once())->method('getItemData')->with($quoteItemMock)->willReturn($itemData);
54 
55  $this->objectManagerMock->expects($this->once())
56  ->method('get')
57  ->with($this->defaultItemId)
58  ->willReturn($itemMock);
59 
60  $this->assertEquals($itemData, $this->model->getItemData($quoteItemMock));
61  }
62 
64  {
65  $itemData = ['key' => 'value'];
66  $productType = 'product_type';
67  $this->itemMap[$productType] = 'product_id';
68 
69  $quoteItemMock = $this->createMock(\Magento\Quote\Model\Quote\Item::class);
70  $quoteItemMock->expects($this->once())->method('getProductType')->willReturn($productType);
71 
72  $itemMock = $this->createMock(\Magento\Checkout\CustomerData\ItemInterface::class);
73  $itemMock->expects($this->once())->method('getItemData')->with($quoteItemMock)->willReturn($itemData);
74 
75  $this->objectManagerMock->expects($this->once())
76  ->method('get')
77  ->with($this->itemMap[$productType])
78  ->willReturn($itemMock);
79 
80  $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
81  $this->model = $objectManager->getObject(
82  \Magento\Checkout\CustomerData\ItemPool::class,
83  [
84  'objectManager' => $this->objectManagerMock,
85  'defaultItemId' => $this->defaultItemId,
86  'itemMap' => $this->itemMap,
87  ]
88  );
89 
90  $this->assertEquals($itemData, $this->model->getItemData($quoteItemMock));
91  }
92 
98  {
99  $itemData = ['key' => 'value'];
100  $productType = 'product_type';
101  $quoteItemMock = $this->createMock(\Magento\Quote\Model\Quote\Item::class);
102  $quoteItemMock->expects($this->once())->method('getProductType')->willReturn($productType);
103  $this->objectManagerMock->expects($this->once())
104  ->method('get')
105  ->with($this->defaultItemId)
106  ->willReturn($this->createMock(\Magento\Quote\Model\Quote\Item::class));
107  $this->assertEquals($itemData, $this->model->getItemData($quoteItemMock));
108  }
109 }
$objectManager
Definition: bootstrap.php:17