Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AmountFactoryTest.php
Go to the documentation of this file.
1 <?php
8 
12 class AmountFactoryTest extends \PHPUnit\Framework\TestCase
13 {
17  protected $factory;
18 
22  protected $objectManagerMock;
23 
27  protected $amountMock;
28 
32  protected function setUp()
33  {
34  $this->objectManagerMock = $this->createMock(\Magento\Framework\App\ObjectManager::class);
35  $this->amountMock = $this->createMock(\Magento\Framework\Pricing\Amount\Base::class);
36  $this->factory = new \Magento\Framework\Pricing\Amount\AmountFactory($this->objectManagerMock);
37  }
38 
42  public function testCreate()
43  {
44  $this->objectManagerMock->expects($this->once())
45  ->method('create')
46  ->with(
47  $this->equalTo(\Magento\Framework\Pricing\Amount\AmountInterface::class),
48  $this->equalTo(
49  [
50  'amount' => 'this-is-float-amount',
51  'adjustmentAmounts' => ['this-is-array-of-adjustments'],
52  ]
53  )
54  )
55  ->will($this->returnValue($this->amountMock));
56  $this->assertEquals(
57  $this->amountMock,
58  $this->factory->create('this-is-float-amount', ['this-is-array-of-adjustments'])
59  );
60  }
61 
67  public function testCreateException()
68  {
69  $this->objectManagerMock->expects($this->once())
70  ->method('create')
71  ->with(
72  $this->equalTo(\Magento\Framework\Pricing\Amount\AmountInterface::class),
73  $this->equalTo(
74  [
75  'amount' => 'this-is-float-amount',
76  'adjustmentAmounts' => ['this-is-array-of-adjustments'],
77  ]
78  )
79  )
80  ->will($this->returnValue(new \stdClass()));
81  $this->assertEquals(
82  $this->amountMock,
83  $this->factory->create('this-is-float-amount', ['this-is-array-of-adjustments'])
84  );
85  }
86 }