CalculatorTest.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\Math\Test\Unit;
  7. class CalculatorTest extends \PHPUnit\Framework\TestCase
  8. {
  9. /**
  10. * @var \Magento\Framework\Math\Calculator
  11. */
  12. protected $_model;
  13. /**
  14. * @var \PHPUnit\Framework_MockObject
  15. */
  16. protected $priceCurrency;
  17. protected function setUp()
  18. {
  19. $this->priceCurrency = $this->getMockBuilder(
  20. \Magento\Framework\Pricing\PriceCurrencyInterface::class
  21. )->getMock();
  22. $this->priceCurrency->expects($this->any())
  23. ->method('round')
  24. ->will($this->returnCallback(function ($argument) {
  25. return round($argument, 2);
  26. }));
  27. $this->_model = new \Magento\Framework\Math\Calculator($this->priceCurrency);
  28. }
  29. /**
  30. * @param float $price
  31. * @param bool $negative
  32. * @param float $expected
  33. * @dataProvider deltaRoundDataProvider
  34. * @covers \Magento\Framework\Math\Calculator::deltaRound
  35. * @covers \Magento\Framework\Math\Calculator::__construct
  36. */
  37. public function testDeltaRound($price, $negative, $expected)
  38. {
  39. $this->assertEquals($expected, $this->_model->deltaRound($price, $negative));
  40. }
  41. /**
  42. * @return array
  43. */
  44. public function deltaRoundDataProvider()
  45. {
  46. return [
  47. [0, false, 0],
  48. [2.223, false, 2.22],
  49. [2.226, false, 2.23],
  50. [2.226, true, 2.23],
  51. ];
  52. }
  53. }