Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
QuoteItemProductOptionTest.php
Go to the documentation of this file.
1 <?php
7 
8 use Magento\Catalog\Model\Plugin\QuoteItemProductOption as QuoteItemProductOptionPlugin;
10 use Magento\Quote\Model\Quote\Item\ToOrderItem as QuoteToOrderItem;
11 use Magento\Quote\Model\Quote\Item\AbstractItem as AbstractQuoteItem;
12 use Magento\Quote\Model\Quote\Item\Option as QuoteItemOption;
16 
20 class QuoteItemProductOptionTest extends \PHPUnit\Framework\TestCase
21 {
25  private $plugin;
26 
30  private $objectManagerHelper;
31 
35  private $subjectMock;
36 
40  private $quoteItemMock;
41 
45  private $quoteItemOptionMock;
46 
50  private $productMock;
51 
52  protected function setUp()
53  {
54  $this->subjectMock = $this->getMockBuilder(QuoteToOrderItem::class)
55  ->disableOriginalConstructor()
56  ->getMock();
57  $this->quoteItemMock = $this->getMockBuilder(AbstractQuoteItem::class)
58  ->disableOriginalConstructor()
59  ->setMethods(['getOptions', 'getProduct'])
60  ->getMockForAbstractClass();
61  $this->quoteItemOptionMock = $this->getMockBuilder(QuoteItemOption::class)
62  ->disableOriginalConstructor()
63  ->setMethods(['getCode'])
64  ->getMock();
65  $this->productMock = $this->getMockBuilder(Product::class)
66  ->disableOriginalConstructor()
67  ->getMock();
68 
69  $this->objectManagerHelper = new ObjectManagerHelper($this);
70  $this->plugin = $this->objectManagerHelper->getObject(QuoteItemProductOptionPlugin::class);
71  }
72 
74  {
75  $this->quoteItemMock->expects(static::once())
76  ->method('getOptions')
77  ->willReturn(null);
78 
79  $this->plugin->beforeConvert($this->subjectMock, $this->quoteItemMock);
80  }
81 
83  {
84  $this->quoteItemMock->expects(static::exactly(2))
85  ->method('getOptions')
86  ->willReturn([$this->quoteItemOptionMock, $this->quoteItemOptionMock]);
87  $this->quoteItemOptionMock->expects(static::exactly(2))
88  ->method('getCode')
89  ->willReturnOnConsecutiveCalls('someText_8', 'not_int_text');
90  $this->productMock->expects(static::once())
91  ->method('getOptionById')
92  ->willReturn(new DataObject(['type' => ProductOption::OPTION_TYPE_FILE]));
93  $this->quoteItemMock->expects(static::once())
94  ->method('getProduct')
95  ->willReturn($this->productMock);
96 
97  $this->plugin->beforeConvert($this->subjectMock, $this->quoteItemMock);
98  }
99 }