Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
DeltaPriceRoundTest.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
12 
16 class DeltaPriceRoundTest extends \PHPUnit\Framework\TestCase
17 {
21  private $priceCurrency;
22 
26  private $model;
27 
31  protected function setUp()
32  {
33  $this->priceCurrency = $this->getMockForAbstractClass(PriceCurrencyInterface::class);
34  $this->priceCurrency->method('round')
35  ->willReturnCallback(
36  function ($amount) {
37  return round($amount, 2);
38  }
39  );
40 
41  $this->model = new DeltaPriceRound($this->priceCurrency);
42  }
43 
52  public function testRound(array $prices, array $roundedPrices): void
53  {
54  foreach ($prices as $key => $price) {
55  $roundedPrice = $this->model->round($price, 'test');
56  $this->assertEquals($roundedPrices[$key], $roundedPrice);
57  }
58 
59  $this->model->reset('test');
60  }
61 
65  public function roundDataProvider(): array
66  {
67  return [
68  [
69  'prices' => [1.004, 1.004],
70  'rounded prices' => [1.00, 1.01],
71  ],
72  [
73  'prices' => [1.005, 1.005],
74  'rounded prices' => [1.01, 1.0],
75  ],
76  ];
77  }
78 
82  public function testReset(): void
83  {
84  $this->assertEquals(1.44, $this->model->round(1.444, 'test'));
85  $this->model->reset('test');
86  $this->assertEquals(1.44, $this->model->round(1.444, 'test'));
87  }
88 
92  public function testResetAll(): void
93  {
94  $this->assertEquals(1.44, $this->model->round(1.444, 'test1'));
95  $this->assertEquals(1.44, $this->model->round(1.444, 'test2'));
96 
97  $this->model->resetAll();
98 
99  $this->assertEquals(1.44, $this->model->round(1.444, 'test1'));
100  $this->assertEquals(1.44, $this->model->round(1.444, 'test2'));
101  }
102 }
$price
$amount
Definition: order.php:14