13 use PHPUnit_Framework_MockObject_MockObject as MockObject;
14 use Psr\Log\LoggerInterface;
40 private $transactionId =
'px4kpev5';
45 private $paymentAmount =
'100.00';
50 protected function setUp()
53 $criticalLoggerMock = $this->getMockForAbstractClass(LoggerInterface::class);
54 $this->loggerMock = $this->getMockBuilder(Logger::class)
55 ->disableOriginalConstructor()
57 $this->adapterMock = $this->getMockBuilder(BraintreeAdapter::class)
58 ->disableOriginalConstructor()
61 $adapterFactoryMock = $this->getMockBuilder(BraintreeAdapterFactory::class)
62 ->disableOriginalConstructor()
64 $adapterFactoryMock->expects(self::once())
66 ->willReturn($this->adapterMock);
68 $this->client =
new TransactionRefund($criticalLoggerMock, $this->loggerMock, $adapterFactoryMock);
77 public function testPlaceRequestException()
79 $this->loggerMock->expects($this->once())
83 'request' => $this->getTransferData(),
84 'client' => TransactionRefund::class,
89 $this->adapterMock->expects($this->once())
91 ->with($this->transactionId, $this->paymentAmount)
92 ->willThrowException(
new \Exception(
'Test messages'));
95 $transferObjectMock = $this->getTransferObjectMock();
97 $this->client->placeRequest($transferObjectMock);
107 $this->adapterMock->expects($this->once())
109 ->with($this->transactionId, $this->paymentAmount)
112 $this->loggerMock->expects($this->once())
116 'request' => $this->getTransferData(),
117 'client' => TransactionRefund::class,
118 'response' => [
'success' => 1],
122 $actualResult = $this->client->placeRequest($this->getTransferObjectMock());
124 $this->assertTrue(is_object($actualResult[
'object']));
125 $this->assertEquals([
'object' =>
$response], $actualResult);
133 private function getTransferObjectMock()
135 $transferObjectMock = $this->createMock(TransferInterface::class);
136 $transferObjectMock->expects($this->once())
138 ->willReturn($this->getTransferData());
140 return $transferObjectMock;
148 private function getTransferData()
151 'transaction_id' => $this->transactionId,
testPlaceRequestSuccess()