Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
FreeTest.php
Go to the documentation of this file.
1 <?php
8 
12 class FreeTest extends \PHPUnit\Framework\TestCase
13 {
15  protected $methodFree;
16 
18  protected $scopeConfig;
19 
21  protected $currencyPrice;
22 
23  protected function setUp()
24  {
25  $paymentData = $this->createMock(\Magento\Payment\Helper\Data::class);
26  $this->scopeConfig = $this->createMock(\Magento\Framework\App\Config\ScopeConfigInterface::class);
27  $this->currencyPrice = $this->getMockBuilder(\Magento\Framework\Pricing\PriceCurrencyInterface::class)
28  ->getMock();
29 
30  $context = $this->createPartialMock(\Magento\Framework\Model\Context::class, ['getEventDispatcher']);
31  $eventManagerMock = $this->createMock(\Magento\Framework\Event\ManagerInterface::class);
32  $context->expects($this->any())->method('getEventDispatcher')->willReturn($eventManagerMock);
33 
34  $registry = $this->createMock(\Magento\Framework\Registry::class);
35  $extensionAttributesFactory = $this->createMock(\Magento\Framework\Api\ExtensionAttributesFactory::class);
36  $customAttributeFactory = $this->createMock(\Magento\Framework\Api\AttributeValueFactory::class);
37 
38  $loggerMock = $this->getMockBuilder(\Magento\Payment\Model\Method\Logger::class)
39  ->setConstructorArgs([$this->getMockForAbstractClass(\Psr\Log\LoggerInterface::class)])
40  ->getMock();
41 
42  $this->methodFree = new \Magento\Payment\Model\Method\Free(
43  $context,
44  $registry,
46  $customAttributeFactory,
47  $paymentData,
48  $this->scopeConfig,
49  $loggerMock,
50  $this->currencyPrice
51  );
52  }
53 
60  public function testGetConfigPaymentAction($orderStatus, $paymentAction, $result)
61  {
62  $this->scopeConfig->expects($this->at(0))
63  ->method('getValue')
64  ->will($this->returnValue($orderStatus));
65 
66  if ($orderStatus != 'pending') {
67  $this->scopeConfig->expects($this->at(1))
68  ->method('getValue')
69  ->will($this->returnValue($paymentAction));
70  }
71  $this->assertEquals($result, $this->methodFree->getConfigPaymentAction());
72  }
73 
81  public function testIsAvailable($grandTotal, $isActive, $notEmptyQuote, $result)
82  {
83  $quote = null;
84  if ($notEmptyQuote) {
85  $quote = $this->createMock(\Magento\Quote\Model\Quote::class);
86  $quote->expects($this->any())
87  ->method('__call')
88  ->with($this->equalTo('getGrandTotal'))
89  ->will($this->returnValue($grandTotal));
90  }
91 
92  $this->currencyPrice->expects($this->any())
93  ->method('round')
94  ->willReturnArgument(0);
95 
96  $this->scopeConfig->expects($this->any())
97  ->method('getValue')
98  ->will($this->returnValue($isActive));
99 
100  $this->assertEquals($result, $this->methodFree->isAvailable($quote));
101  }
102 
106  public function getIsAvailableProvider()
107  {
108  return [
109  [0, true, true, true],
110  [0.1, true, true, false],
111  [0, false, false, false],
112  [1, true, false, false],
113  [0, true, false, false]
114  ];
115  }
116 
121  {
122  return [
123  ['pending', 'action', null],
124  ['processing', 'payment_action', 'payment_action']
125  ];
126  }
127 }
$quote
$orderStatus
Definition: order_status.php:9
testIsAvailable($grandTotal, $isActive, $notEmptyQuote, $result)
Definition: FreeTest.php:81
testGetConfigPaymentAction($orderStatus, $paymentAction, $result)
Definition: FreeTest.php:60
$extensionAttributesFactory