13 use PHPUnit_Framework_MockObject_MockObject as MockObject;
14 use Psr\Log\LoggerInterface;
39 protected function setUp()
42 $criticalLoggerMock = $this->getMockForAbstractClass(LoggerInterface::class);
43 $this->loggerMock = $this->getMockBuilder(Logger::class)
44 ->disableOriginalConstructor()
46 $this->adapterMock = $this->getMockBuilder(BraintreeAdapter::class)
47 ->disableOriginalConstructor()
50 $adapterFactoryMock = $this->getMockBuilder(BraintreeAdapterFactory::class)
51 ->disableOriginalConstructor()
53 $adapterFactoryMock->expects(self::once())
55 ->willReturn($this->adapterMock);
57 $this->model =
new TransactionSale($criticalLoggerMock, $this->loggerMock, $adapterFactoryMock);
68 public function testPlaceRequestException()
70 $this->loggerMock->expects($this->once())
74 'request' => $this->getTransferData(),
75 'client' => TransactionSale::class,
80 $this->adapterMock->expects($this->once())
82 ->willThrowException(
new \Exception(
'Test messages'));
85 $transferObjectMock = $this->getTransferObjectMock();
87 $this->model->placeRequest($transferObjectMock);
98 $this->adapterMock->expects($this->once())
100 ->with($this->getTransferData())
103 $this->loggerMock->expects($this->once())
107 'request' => $this->getTransferData(),
108 'client' => TransactionSale::class,
109 'response' => [
'success' => 1]
113 $actualResult = $this->model->placeRequest($this->getTransferObjectMock());
115 $this->assertTrue(is_object($actualResult[
'object']));
116 $this->assertEquals([
'object' =>
$response], $actualResult);
124 private function getTransferObjectMock()
126 $transferObjectMock = $this->createMock(TransferInterface::class);
127 $transferObjectMock->expects($this->once())
129 ->willReturn($this->getTransferData());
131 return $transferObjectMock;
139 private function getResponseObject()
141 $obj = new \stdClass;
142 $obj->success =
true;
152 private function getTransferData()
155 'test-data-key' =>
'test-data-value'
testPlaceRequestSuccess()