Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AbstractMethodTest.php
Go to the documentation of this file.
1 <?php
7 
13 
20 class AbstractMethodTest extends \PHPUnit\Framework\TestCase
21 {
25  protected $payment;
26 
30  protected $scopeConfigMock;
31 
35  protected $eventManagerMock;
36 
40  protected $quoteMock;
41 
45  protected $loggerMock;
46 
47  protected function setUp()
48  {
49  $this->scopeConfigMock = $this->getMockBuilder(\Magento\Framework\App\Config\ScopeConfigInterface::class)
50  ->setMethods(['getValue'])
51  ->getMockForAbstractClass();
52  $this->eventManagerMock = $this->getMockBuilder(\Magento\Framework\Event\ManagerInterface::class)
53  ->setMethods(['dispatch'])
54  ->getMockForAbstractClass();
55  $this->quoteMock = $this->getMockBuilder(\Magento\Quote\Api\Data\CartInterface::class)
56  ->setMethods(['getStoreId'])
57  ->getMockForAbstractClass();
58  $contextMock = $this->getMockBuilder(\Magento\Framework\Model\Context::class)
59  ->disableOriginalConstructor()
60  ->setMethods(['getEventDispatcher'])
61  ->getMock();
62  $contextMock->expects($this->once())
63  ->method('getEventDispatcher')
64  ->willReturn($this->eventManagerMock);
65  $this->loggerMock = $this->getMockBuilder(\Magento\Payment\Model\Method\Logger::class)
66  ->setConstructorArgs([$this->getMockForAbstractClass(\Psr\Log\LoggerInterface::class)])
67  ->setMethods(['debug'])
68  ->getMock();
69 
70  $helper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
71  $this->payment = $helper->getObject(
72  Stub::class,
73  [
74  'scopeConfig' => $this->scopeConfigMock,
75  'context' => $contextMock,
76  'logger' => $this->loggerMock
77  ]
78  );
79  }
80 
81  public function testDebugData()
82  {
83  $debugData = ['masked' => '123'];
84  $this->loggerMock->expects($this->once())
85  ->method('debug')
86  ->with($this->equalTo($debugData));
87 
88  $this->payment->debugData($debugData);
89  }
90 
96  public function testIsAvailable($result)
97  {
98  $storeId = 15;
99  $this->quoteMock->expects($this->once())
100  ->method('getStoreId')
101  ->willReturn($storeId);
102 
103  $this->scopeConfigMock->expects($this->once())
104  ->method('getValue')
105  ->with(
106  'payment/' . Stub::STUB_CODE . '/active',
108  $storeId
109  )->willReturn($result);
110 
111  $this->eventManagerMock->expects($result ? $this->once() : $this->never())
112  ->method('dispatch')
113  ->with(
114  $this->equalTo('payment_method_is_active'),
115  $this->countOf(3)
116  );
117 
118  $this->assertEquals($result, $this->payment->isAvailable($this->quoteMock));
119  }
120 
121  public function testAssignData()
122  {
123  $data = new DataObject();
124  $paymentInfo = $this->createMock(InfoInterface::class);
125 
126  $this->payment->setInfoInstance($paymentInfo);
127 
128  $eventData = [
132  ];
133 
134  $this->eventManagerMock->expects(static::exactly(2))
135  ->method('dispatch')
136  ->willReturnMap(
137  [
138  [
139  'payment_method_assign_data_' . Stub::STUB_CODE,
140  $eventData
141  ],
142  [
143  'payment_method_assign_data',
144  $eventData
145  ]
146  ]
147  );
148 
149  $this->payment->assignData($data);
150  }
151 
156  {
157  return [
158  [
159  'result' => true
160  ],
161  [
162  'result' => false
163  ],
164  ];
165  }
166 }
$helper
Definition: iframe.phtml:13
return false
Definition: gallery.phtml:36
$paymentInfo