Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
FormattedPriceInfoBuilderTest.php
Go to the documentation of this file.
1 <?php
8 
12 use Magento\Catalog\Api\Data\ProductRender\FormattedPriceInfoInterfaceFactory;
14 
15 class FormattedPriceInfoBuilderTest extends \PHPUnit\Framework\TestCase
16 {
20  private $priceCurrencyMock;
21 
25  private $formattedPriceInfoFactoryMock;
26 
30  private $formattedPriceInfoBuilderMock;
31 
32  public function setUp()
33  {
34  $this->priceCurrencyMock = $this->getMockBuilder(PriceCurrencyInterface::class)
35  ->getMockForAbstractClass();
36  $this->formattedPriceInfoFactoryMock = $this->getMockBuilder(FormattedPriceInfoInterfaceFactory::class)
37  ->disableOriginalConstructor()
38  ->getMock();
39 
40  $this->formattedPriceInfoBuilderMock = new FormattedPriceInfoBuilder(
41  $this->priceCurrencyMock,
42  $this->formattedPriceInfoFactoryMock
43  );
44  }
45 
46  public function testBuild()
47  {
48  $storeId = 1;
49  $storeCurrencyCode = 'USD';
50 
51  $formattedPriceInfoInterfaceMock = $this->getMockBuilder(FormattedPriceInfoInterface::class)
52  ->disableOriginalConstructor()
53  ->setMethods(['setData'])
54  ->getMockForAbstractClass();
55  $priceInfoMock = $this->getMockBuilder(PriceInfoInterface::class)
56  ->disableOriginalConstructor()
57  ->setMethods(['getData'])
58  ->getMockForAbstractClass();
59  $priceInfoMock->expects($this->any())
60  ->method('getData')
61  ->willReturn([
62  'key'=>'1233123'
63  ]);
64  $this->priceCurrencyMock->expects($this->atLeastOnce())
65  ->method('format')
66  ->with(
67  '1233123',
68  true,
70  $storeId,
71  $storeCurrencyCode
72  )
73  ->willReturn(12.1);
74  $formattedPriceInfoInterfaceMock->expects($this->atLeastOnce())
75  ->method('setData')
76  ->with('key', 12.1);
77  $this->formattedPriceInfoFactoryMock->expects($this->once())
78  ->method('create')
79  ->willReturn($formattedPriceInfoInterfaceMock);
80 
81  $this->formattedPriceInfoBuilderMock->build($priceInfoMock, $storeId, $storeCurrencyCode);
82  }
83 }