Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
BeforeOrderPaymentSaveObserverTest.php
Go to the documentation of this file.
1 <?php
7 
15 use PHPUnit_Framework_MockObject_MockObject as MockObject;
17 
18 class BeforeOrderPaymentSaveObserverTest extends \PHPUnit\Framework\TestCase
19 {
23  protected $_model;
24 
28  private $payment;
29 
33  private $event;
34 
38  private $observer;
39 
43  protected function setUp()
44  {
45  $objectManagerHelper = new ObjectManager($this);
46  $this->payment = $this->getMockBuilder(Payment::class)
47  ->disableOriginalConstructor()
48  ->getMock();
49 
50  $this->event = $this->getMockBuilder(Event::class)
51  ->disableOriginalConstructor()
52  ->setMethods(['getPayment'])
53  ->getMock();
54 
55  $this->event->expects(self::once())
56  ->method('getPayment')
57  ->willReturn($this->payment);
58 
59  $this->observer = $this->getMockBuilder(Observer::class)
60  ->disableOriginalConstructor()
61  ->getMock();
62 
63  $this->observer->expects(self::once())
64  ->method('getEvent')
65  ->willReturn($this->event);
66 
67  $this->_model = $objectManagerHelper->getObject(BeforeOrderPaymentSaveObserver::class);
68  }
69 
75  {
76  $this->payment->expects(self::once())
77  ->method('getMethod')
78  ->willReturn($methodCode);
79  $this->payment->expects(self::once())
80  ->method('setAdditionalInformation')
81  ->with('instructions', 'payment configuration');
82  $method = $this->getMockBuilder(Banktransfer::class)
83  ->disableOriginalConstructor()
84  ->getMock();
85 
86  $method->expects(self::once())
87  ->method('getInstructions')
88  ->willReturn('payment configuration');
89  $this->payment->expects(self::once())
90  ->method('getMethodInstance')
91  ->willReturn($method);
92 
93  $this->_model->execute($this->observer);
94  }
95 
102  {
103  return [
106  ];
107  }
108 
110  {
111  $this->payment->expects(self::exactly(2))
112  ->method('getMethod')
114  $this->payment->expects(self::exactly(2))
115  ->method('setAdditionalInformation')
116  ->willReturnMap(
117  [
118  ['payable_to', 'payable to', $this->payment],
119  ['mailing_address', 'mailing address', $this->payment],
120  ]
121  );
122 
123  $method = $this->getMockBuilder(Checkmo::class)
124  ->disableOriginalConstructor()
125  ->getMock();
126  $method->expects(self::exactly(2))
127  ->method('getPayableTo')
128  ->willReturn('payable to');
129  $method->expects(self::exactly(2))
130  ->method('getMailingAddress')
131  ->willReturn('mailing address');
132  $this->payment->expects(self::once())
133  ->method('getMethodInstance')
134  ->willReturn($method);
135  $this->_model->execute($this->observer);
136  }
137 
143  {
144  $this->payment->expects(self::exactly(2))
145  ->method('getMethod')
147  $this->payment->expects(self::never())
148  ->method('setAdditionalInformation');
149 
150  $method = $this->getMockBuilder(Checkmo::class)
151  ->disableOriginalConstructor()
152  ->getMock();
153  $method->expects(self::once())
154  ->method('getPayableTo')
155  ->willReturn(null);
156  $method->expects(self::once())
157  ->method('getMailingAddress')
158  ->willReturn(null);
159  $this->payment->expects(self::once())
160  ->method('getMethodInstance')
161  ->willReturn($method);
162  $this->_model->execute($this->observer);
163  }
164 
166  {
167  $this->payment->expects(self::exactly(2))
168  ->method('getMethod')
169  ->willReturn('somepaymentmethod');
170  $this->payment->expects(self::never())
171  ->method('setAdditionalInformation');
172 
173  $this->_model->execute($this->observer);
174  }
175 }
$method
Definition: info.phtml:13