Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
CaptureDataBuilderTest.php
Go to the documentation of this file.
1 <?php
7 
12 use PHPUnit_Framework_MockObject_MockObject as MockObject;
13 
17 class CaptureDataBuilderTest extends \PHPUnit\Framework\TestCase
18 {
22  private $builder;
23 
27  private $paymentMock;
28 
32  private $paymentDOMock;
33 
37  private $subjectReaderMock;
38 
39  protected function setUp()
40  {
41  $this->paymentDOMock = $this->createMock(PaymentDataObjectInterface::class);
42  $this->paymentMock = $this->getMockBuilder(Payment::class)
43  ->disableOriginalConstructor()
44  ->getMock();
45  $this->subjectReaderMock = $this->getMockBuilder(SubjectReader::class)
46  ->disableOriginalConstructor()
47  ->getMock();
48 
49  $this->builder = new CaptureDataBuilder($this->subjectReaderMock);
50  }
51 
57  public function testBuildWithException()
58  {
59  $amount = 10.00;
60  $buildSubject = [
61  'payment' => $this->paymentDOMock,
62  'amount' => $amount,
63  ];
64 
65  $this->paymentMock->expects(self::once())
66  ->method('getCcTransId')
67  ->willReturn('');
68 
69  $this->paymentDOMock->expects(self::once())
70  ->method('getPayment')
71  ->willReturn($this->paymentMock);
72 
73  $this->subjectReaderMock->expects(self::once())
74  ->method('readPayment')
75  ->with($buildSubject)
76  ->willReturn($this->paymentDOMock);
77 
78  $this->builder->build($buildSubject);
79  }
80 
84  public function testBuild()
85  {
86  $transactionId = 'b3b99d';
87  $amount = 10.00;
88 
89  $expected = [
90  'transaction_id' => $transactionId,
91  'amount' => $amount,
92  ];
93 
94  $buildSubject = [
95  'payment' => $this->paymentDOMock,
96  'amount' => $amount,
97  ];
98 
99  $this->paymentMock->expects(self::once())
100  ->method('getCcTransId')
101  ->willReturn($transactionId);
102 
103  $this->paymentDOMock->expects(self::once())
104  ->method('getPayment')
105  ->willReturn($this->paymentMock);
106 
107  $this->subjectReaderMock->expects(self::once())
108  ->method('readPayment')
109  ->with($buildSubject)
110  ->willReturn($this->paymentDOMock);
111  $this->subjectReaderMock->expects(self::once())
112  ->method('readAmount')
113  ->with($buildSubject)
114  ->willReturn($amount);
115 
116  static::assertEquals($expected, $this->builder->build($buildSubject));
117  }
118 }
$amount
Definition: order.php:14