ZeroTotalTest.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Payment\Test\Unit\Model\Checks;
  7. use \Magento\Payment\Model\Checks\ZeroTotal;
  8. class ZeroTotalTest extends \PHPUnit\Framework\TestCase
  9. {
  10. /**
  11. * @dataProvider paymentMethodDataProvider
  12. * @param string $code
  13. * @param int $total
  14. * @param bool $expectation
  15. */
  16. public function testIsApplicable($code, $total, $expectation)
  17. {
  18. $paymentMethod = $this->getMockBuilder(\Magento\Payment\Model\MethodInterface::class)
  19. ->disableOriginalConstructor()
  20. ->setMethods([])
  21. ->getMock();
  22. if (!$total) {
  23. $paymentMethod->expects($this->once())
  24. ->method('getCode')
  25. ->will($this->returnValue($code));
  26. }
  27. $quote = $this->getMockBuilder(\Magento\Quote\Model\Quote::class)
  28. ->disableOriginalConstructor()
  29. ->setMethods(['getBaseGrandTotal', '__wakeup'])
  30. ->getMock();
  31. $quote->expects($this->once())
  32. ->method('getBaseGrandTotal')
  33. ->will($this->returnValue($total));
  34. $model = new ZeroTotal();
  35. $this->assertEquals($expectation, $model->isApplicable($paymentMethod, $quote));
  36. }
  37. /**
  38. * @return array
  39. */
  40. public function paymentMethodDataProvider()
  41. {
  42. return [['not_free', 0, false], ['free', 1, true]];
  43. }
  44. }