23 use Magento\Sales\Model\ResourceModel\Order\Payment\Transaction\CollectionFactory;
24 use PHPUnit_Framework_MockObject_MockObject as MockObject;
36 private $strategyCommand;
41 private $commandPoolMock;
46 private $transactionRepositoryMock;
51 private $filterBuilderMock;
56 private $searchCriteriaBuilderMock;
71 private $subjectReaderMock;
76 private $braintreeAdapterMock;
81 private $braintreeSearchAdapter;
83 protected function setUp()
85 $this->commandPoolMock = $this->getMockBuilder(CommandPoolInterface::class)
86 ->disableOriginalConstructor()
87 ->setMethods([
'get',
'__wakeup'])
90 $this->subjectReaderMock = $this->getMockBuilder(SubjectReader::class)
91 ->disableOriginalConstructor()
94 $this->initCommandMock();
95 $this->initTransactionRepositoryMock();
96 $this->initFilterBuilderMock();
97 $this->initSearchCriteriaBuilderMock();
99 $this->braintreeAdapterMock = $this->getMockBuilder(BraintreeAdapter::class)
100 ->disableOriginalConstructor()
103 $adapterFactoryMock = $this->getMockBuilder(BraintreeAdapterFactory::class)
104 ->disableOriginalConstructor()
106 $adapterFactoryMock->expects(self::any())
108 ->willReturn($this->braintreeAdapterMock);
113 $this->commandPoolMock,
114 $this->transactionRepositoryMock,
115 $this->filterBuilderMock,
116 $this->searchCriteriaBuilderMock,
117 $this->subjectReaderMock,
119 $this->braintreeSearchAdapter
128 $paymentData = $this->getPaymentDataObjectMock();
129 $subject[
'payment'] = $paymentData;
131 $this->subjectReaderMock->expects(self::once())
132 ->method(
'readPayment')
134 ->willReturn($paymentData);
136 $this->paymentMock->expects(static::once())
137 ->method(
'getAuthorizationTransaction')
140 $this->paymentMock->expects(static::once())
144 $this->buildSearchCriteria();
146 $this->transactionRepositoryMock->expects(static::once())
147 ->method(
'getTotalCount')
150 $this->commandPoolMock->expects(static::once())
153 ->willReturn($this->commandMock);
155 $this->strategyCommand->execute($subject);
163 $paymentData = $this->getPaymentDataObjectMock();
164 $subject[
'payment'] = $paymentData;
165 $lastTransId =
'txnds';
167 $this->subjectReaderMock->expects(self::once())
168 ->method(
'readPayment')
170 ->willReturn($paymentData);
172 $this->paymentMock->expects(static::once())
173 ->method(
'getAuthorizationTransaction')
175 $this->paymentMock->expects(static::once())
176 ->method(
'getLastTransId')
177 ->willReturn($lastTransId);
179 $this->paymentMock->expects(static::once())
183 $this->buildSearchCriteria();
185 $this->transactionRepositoryMock->expects(static::once())
186 ->method(
'getTotalCount')
190 $collection = $this->getNotExpiredExpectedCollection($lastTransId);
192 ->method(
'maximumCount')
195 $this->commandPoolMock->expects(static::once())
198 ->willReturn($this->commandMock);
200 $this->strategyCommand->execute($subject);
207 private function getNotExpiredExpectedCollection($lastTransactionId)
210 'id' => [
'is' => $lastTransactionId],
211 'status' => [\Braintree\Transaction::AUTHORIZATION_EXPIRED]
214 $collection = $this->getMockBuilder(\Braintree\ResourceCollection::class)
215 ->disableOriginalConstructor()
218 $this->braintreeAdapterMock->expects(static::once())
222 function (array
$filters) use ($isExpectations) {
225 if (!isset($isExpectations[$filter->name])) {
229 if ($isExpectations[$filter->name] !== $filter->toParam()) {
248 $paymentData = $this->getPaymentDataObjectMock();
249 $subject[
'payment'] = $paymentData;
250 $lastTransId =
'txnds';
252 $this->subjectReaderMock->expects(self::once())
253 ->method(
'readPayment')
255 ->willReturn($paymentData);
257 $this->paymentMock->expects(static::once())
258 ->method(
'getAuthorizationTransaction')
260 $this->paymentMock->expects(static::once())
261 ->method(
'getLastTransId')
262 ->willReturn($lastTransId);
264 $this->paymentMock->expects(static::once())
268 $this->buildSearchCriteria();
270 $this->transactionRepositoryMock->expects(static::once())
271 ->method(
'getTotalCount')
275 $collection = $this->getNotExpiredExpectedCollection($lastTransId);
277 ->method(
'maximumCount')
280 $this->commandPoolMock->expects(static::once())
283 ->willReturn($this->commandMock);
285 $this->strategyCommand->execute($subject);
293 $paymentData = $this->getPaymentDataObjectMock();
294 $subject[
'payment'] = $paymentData;
296 $this->subjectReaderMock->expects(self::once())
297 ->method(
'readPayment')
299 ->willReturn($paymentData);
301 $this->paymentMock->expects(static::once())
302 ->method(
'getAuthorizationTransaction')
305 $this->paymentMock->expects(static::once())
309 $this->buildSearchCriteria();
311 $this->transactionRepositoryMock->expects(static::once())
312 ->method(
'getTotalCount')
315 $this->commandPoolMock->expects(static::once())
318 ->willReturn($this->commandMock);
320 $this->strategyCommand->execute($subject);
327 private function getPaymentDataObjectMock()
329 $this->paymentMock = $this->getMockBuilder(Payment::class)
330 ->disableOriginalConstructor()
333 $mock = $this->getMockBuilder(PaymentDataObject::class)
334 ->setMethods([
'getPayment',
'getOrder'])
335 ->disableOriginalConstructor()
338 $mock->expects(static::once())
339 ->method(
'getPayment')
340 ->willReturn($this->paymentMock);
342 $orderMock = $this->getMockBuilder(OrderAdapterInterface::class)
343 ->disableOriginalConstructor()
346 $mock->method(
'getOrder')
347 ->willReturn($orderMock);
355 private function initCommandMock()
357 $this->commandMock = $this->getMockBuilder(GatewayCommand::class)
358 ->disableOriginalConstructor()
359 ->setMethods([
'execute'])
362 $this->commandMock->expects(static::once())
370 private function initFilterBuilderMock()
372 $this->filterBuilderMock = $this->getMockBuilder(FilterBuilder::class)
373 ->disableOriginalConstructor()
374 ->setMethods([
'setField',
'setValue',
'create',
'__wakeup'])
381 private function buildSearchCriteria()
383 $this->filterBuilderMock->expects(static::exactly(2))
386 $this->filterBuilderMock->expects(static::exactly(2))
391 $this->searchCriteriaBuilderMock->expects(static::exactly(2))
392 ->method(
'addFilters')
394 $this->searchCriteriaBuilderMock->expects(static::once())
398 $this->transactionRepositoryMock->expects(static::once())
407 private function initSearchCriteriaBuilderMock()
409 $this->searchCriteriaBuilderMock = $this->getMockBuilder(SearchCriteriaBuilder::class)
410 ->disableOriginalConstructor()
411 ->setMethods([
'addFilters',
'create',
'__wakeup'])
418 private function initTransactionRepositoryMock()
420 $this->transactionRepositoryMock = $this->getMockBuilder(TransactionRepositoryInterface::class)
421 ->disableOriginalConstructor()
422 ->setMethods([
'getList',
'getTotalCount',
'delete',
'get',
'save',
'create',
'__wakeup'])
if(!defined( 'PHP_VERSION_ID')||!(PHP_VERSION_ID===70002||PHP_VERSION_ID===70004||PHP_VERSION_ID >=70006))
testVaultCaptureExecute()
testExpiredAuthorizationPerformVaultCaptureExecute()