13 use PHPUnit_Framework_MockObject_MockObject as MockObject;
14 use Psr\Log\LoggerInterface;
39 private $transactionId =
'px4kpev5';
44 protected function setUp()
47 $criticalLoggerMock = $this->getMockForAbstractClass(LoggerInterface::class);
48 $this->loggerMock = $this->getMockBuilder(Logger::class)
49 ->disableOriginalConstructor()
51 $this->adapterMock = $this->getMockBuilder(BraintreeAdapter::class)
52 ->disableOriginalConstructor()
55 $adapterFactoryMock = $this->getMockBuilder(BraintreeAdapterFactory::class)
56 ->disableOriginalConstructor()
58 $adapterFactoryMock->expects(self::once())
60 ->willReturn($this->adapterMock);
62 $this->client =
new TransactionVoid($criticalLoggerMock, $this->loggerMock, $adapterFactoryMock);
71 public function testPlaceRequestException()
73 $this->loggerMock->expects($this->once())
77 'request' => $this->getTransferData(),
78 'client' => TransactionVoid::class,
83 $this->adapterMock->expects($this->once())
85 ->with($this->transactionId)
86 ->willThrowException(
new \Exception(
'Test messages'));
89 $transferObjectMock = $this->getTransferObjectMock();
91 $this->client->placeRequest($transferObjectMock);
101 $this->adapterMock->expects($this->once())
103 ->with($this->transactionId)
106 $this->loggerMock->expects($this->once())
110 'request' => $this->getTransferData(),
111 'client' => TransactionVoid::class,
112 'response' => [
'success' => 1],
116 $actualResult = $this->client->placeRequest($this->getTransferObjectMock());
118 $this->assertTrue(is_object($actualResult[
'object']));
119 $this->assertEquals([
'object' =>
$response], $actualResult);
127 private function getTransferObjectMock()
129 $transferObjectMock = $this->createMock(TransferInterface::class);
130 $transferObjectMock->expects($this->once())
132 ->willReturn($this->getTransferData());
134 return $transferObjectMock;
142 private function getTransferData()
145 'transaction_id' => $this->transactionId,
testPlaceRequestSuccess()