Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
VoidTest.php
Go to the documentation of this file.
1 <?php
6 namespace Magento\Paypal\Model;
7 
11 class VoidTest extends \PHPUnit\Framework\TestCase
12 {
19  public function testPayflowProVoid()
20  {
22 
24  $order = $objectManager->create(\Magento\Sales\Model\Order::class);
25  $order->loadByIncrementId('100000001');
26  $payment = $order->getPayment();
27 
28  $gatewayMock = $this->createMock(\Magento\Paypal\Model\Payflow\Service\Gateway::class);
29 
30  $configMock = $this->createMock(\Magento\Paypal\Model\PayflowConfig::class);
31  $configFactoryMock = $this->createPartialMock(
32  \Magento\Payment\Model\Method\ConfigInterfaceFactory::class,
33  ['create']
34  );
35 
36  $configFactoryMock->expects($this->once())
37  ->method('create')
38  ->willReturn($configMock);
39 
40  $configMock->expects($this->any())
41  ->method('getValue')
42  ->willReturnMap(
43  [
44  ['use_proxy', false],
45  ['sandbox_flag', '1'],
46  ['transaction_url_test_mode', 'https://test_transaction_url']
47  ]
48  );
49 
51  $instance = $this->getMockBuilder(\Magento\Paypal\Model\Payflowpro::class)
52  ->setMethods(['setStore'])
53  ->setConstructorArgs(
54  [
55  $objectManager->get(\Magento\Framework\Model\Context::class),
56  $objectManager->get(\Magento\Framework\Registry::class),
57  $objectManager->get(\Magento\Framework\Api\ExtensionAttributesFactory::class),
58  $objectManager->get(\Magento\Framework\Api\AttributeValueFactory::class),
59  $objectManager->get(\Magento\Payment\Helper\Data::class),
60  $objectManager->get(\Magento\Framework\App\Config\ScopeConfigInterface::class),
61  $objectManager->get(\Magento\Payment\Model\Method\Logger::class),
62  $objectManager->get(\Magento\Framework\Module\ModuleListInterface::class),
63  $objectManager->get(\Magento\Framework\Stdlib\DateTime\TimezoneInterface::class),
64  $objectManager->get(\Magento\Store\Model\StoreManagerInterface::class),
65  $configFactoryMock,
66  $gatewayMock,
67  $objectManager->get(\Magento\Paypal\Model\Payflow\Service\Response\Handler\HandlerInterface::class),
68  null,
69  null,
70  []
71  ]
72  )
73  ->getMock();
74 
75  $response = new \Magento\Framework\DataObject(
76  [
77  'result' => '0',
78  'pnref' => 'V19A3D27B61E',
79  'respmsg' => 'Approved',
80  'authcode' => '510PNI',
81  'hostcode' => 'A',
82  'request_id' => 'f930d3dc6824c1f7230c5529dc37ae5e',
83  'result_code' => '0',
84  ]
85  );
86 
87  $gatewayMock->expects($this->once())
88  ->method('postRequest')
89  ->willReturn($response);
90  $instance->expects($this->once())
91  ->method('setStore')
92  ->willReturnSelf();
93 
94  $payment->setMethodInstance($instance);
95  $payment->void(new \Magento\Framework\DataObject());
96  $order->save();
97 
98  $order = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(\Magento\Sales\Model\Order::class);
99  $order->loadByIncrementId('100000001');
100  $this->assertFalse($order->canVoidPayment());
101  }
102 }
$response
Definition: 404.php:11
$objectManager
Definition: bootstrap.php:17
$order
Definition: order.php:55
$payment
Definition: order.php:17