Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
TransactionSubmitForSettlementTest.php
Go to the documentation of this file.
1 <?php
7 
8 use Braintree\Result\Successful;
14 use PHPUnit_Framework_MockObject_MockObject as MockObject;
15 use Psr\Log\LoggerInterface;
16 
20 class TransactionSubmitForSettlementTest extends \PHPUnit\Framework\TestCase
21 {
25  private $client;
26 
30  private $loggerMock;
31 
35  private $adapterMock;
36 
37  protected function setUp()
38  {
40  $criticalLoggerMock = $this->getMockForAbstractClass(LoggerInterface::class);
41  $this->loggerMock = $this->getMockBuilder(Logger::class)
42  ->disableOriginalConstructor()
43  ->setMethods(['debug'])
44  ->getMock();
45 
46  $this->adapterMock = $this->getMockBuilder(BraintreeAdapter::class)
47  ->disableOriginalConstructor()
48  ->setMethods(['submitForSettlement'])
49  ->getMock();
51  $adapterFactoryMock = $this->getMockBuilder(BraintreeAdapterFactory::class)
52  ->disableOriginalConstructor()
53  ->getMock();
54  $adapterFactoryMock->method('create')
55  ->willReturn($this->adapterMock);
56 
57  $this->client = new TransactionSubmitForSettlement(
58  $criticalLoggerMock,
59  $this->loggerMock,
60  $adapterFactoryMock
61  );
62  }
63 
69  public function testPlaceRequestWithException()
70  {
71  $exception = new \Exception('Transaction has been declined');
72  $this->adapterMock->expects(static::once())
73  ->method('submitForSettlement')
74  ->willThrowException($exception);
75 
77  $transferObject = $this->getTransferObjectMock();
78  $this->client->placeRequest($transferObject);
79  }
80 
84  public function testPlaceRequest()
85  {
86  $data = new Successful(['success'], [true]);
87  $this->adapterMock->expects(static::once())
88  ->method('submitForSettlement')
89  ->willReturn($data);
90 
92  $transferObject = $this->getTransferObjectMock();
93  $response = $this->client->placeRequest($transferObject);
94  static::assertTrue(is_object($response['object']));
95  static::assertEquals(['object' => $data], $response);
96  }
97 
103  private function getTransferObjectMock()
104  {
105  $mock = $this->createMock(TransferInterface::class);
106  $mock->expects($this->once())
107  ->method('getBody')
108  ->willReturn([
109  'transaction_id' => 'vb4c6b',
110  'amount' => 124.00,
111  ]);
112 
113  return $mock;
114  }
115 }
$response
Definition: 404.php:11