Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AbstractCreateTest.php
Go to the documentation of this file.
1 <?php
8 
11 
12 class AbstractCreateTest extends \PHPUnit\Framework\TestCase
13 {
17  protected $model;
18 
22  protected $productMock;
23 
27  protected $priceInfoMock;
28 
32  protected $linkPriceMock;
33 
34  protected function setUp()
35  {
36  $this->model = $this->getMockBuilder(\Magento\Sales\Block\Adminhtml\Order\Create\AbstractCreate::class)
37  ->setMethods(['convertPrice'])
38  ->disableOriginalConstructor()
39  ->getMockForAbstractClass();
40  $this->priceInfoMock = $this->getMockBuilder(\Magento\Framework\Pricing\PriceInfo\Base::class)
41  ->disableOriginalConstructor()
42  ->getMock();
43  $this->productMock = $this->getMockBuilder(\Magento\Catalog\Model\Product::class)
44  ->disableOriginalConstructor()
45  ->getMock();
46  $this->linkPriceMock = $this->getMockBuilder(\Magento\Downloadable\Pricing\Price\LinkPrice::class)
47  ->disableOriginalConstructor()
48  ->getMock();
49  $this->productMock->expects($this->any())
50  ->method('getPriceInfo')
51  ->willReturn($this->priceInfoMock);
52  }
53 
54  public function testGetItemPrice()
55  {
56  $price = 5.6;
57  $resultPrice = 9.3;
58 
59  $this->linkPriceMock->expects($this->once())
60  ->method('getValue')
61  ->willReturn($price);
62  $this->priceInfoMock->expects($this->once())
63  ->method('getPrice')
65  ->willReturn($this->linkPriceMock);
66  $this->model->expects($this->once())
67  ->method('convertPrice')
68  ->with($price)
69  ->willReturn($resultPrice);
70  $this->assertEquals($resultPrice, $this->model->getItemPrice($this->productMock));
71  }
72 
78  public function testGetProduct($item)
79  {
80  $product = $this->model->getProduct($item);
81 
82  self::assertInstanceOf(Product::class, $product);
83  }
84 
90  public function getProductDataProvider()
91  {
92  $productMock = $this->createMock(Product::class);
93 
94  $itemMock = $this->createMock(\Magento\Wishlist\Model\Item::class);
95  $itemMock->expects($this->once())->method('getProduct')->willReturn($productMock);
96 
97  return [
98  [$productMock],
99  [$itemMock],
100  ];
101  }
102 }
$price