Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
VoidDataBuilderTest.php
Go to the documentation of this file.
1 <?php
7 
12 use PHPUnit_Framework_MockObject_MockObject as MockObject;
13 
17 class VoidDataBuilderTest extends \PHPUnit\Framework\TestCase
18 {
22  private $builder;
23 
27  private $paymentDOMock;
28 
32  private $paymentMock;
33 
37  private $subjectReaderMock;
38 
42  protected function setUp()
43  {
44  $this->paymentDOMock = $this->createMock(PaymentDataObjectInterface::class);
45  $this->paymentMock = $this->getMockBuilder(Payment::class)
46  ->disableOriginalConstructor()
47  ->getMock();
48  $this->paymentDOMock->expects(static::once())
49  ->method('getPayment')
50  ->willReturn($this->paymentMock);
51 
52  $this->subjectReaderMock = $this->getMockBuilder(SubjectReader::class)
53  ->disableOriginalConstructor()
54  ->getMock();
55 
56  $this->builder = new VoidDataBuilder($this->subjectReaderMock);
57  }
58 
67  public function testBuild($parentTransactionId, $callLastTransId, $lastTransId, $expected)
68  {
69  $amount = 30.00;
70 
71  $buildSubject = [
72  'payment' => $this->paymentDOMock,
73  'amount' => $amount,
74  ];
75 
76  $this->subjectReaderMock->expects(self::once())
77  ->method('readPayment')
78  ->with($buildSubject)
79  ->willReturn($this->paymentDOMock);
80 
81  $this->paymentMock->expects(self::once())
82  ->method('getParentTransactionId')
83  ->willReturn($parentTransactionId);
84  $this->paymentMock->expects(self::$callLastTransId())
85  ->method('getLastTransId')
86  ->willReturn($lastTransId);
87 
88  $result = $this->builder->build($buildSubject);
89  self::assertEquals(
90  ['transaction_id' => $expected],
91  $result
92  );
93  }
94 
98  public function buildDataProvider()
99  {
100  return [
101  [
102  'parentTransactionId' => 'b3b99d',
103  'callLastTransId' => 'never',
104  'lastTransId' => 'd45d22',
105  'expected' => 'b3b99d',
106  ],
107  [
108  'parentTransactionId' => null,
109  'callLastTransId' => 'once',
110  'expected' => 'd45d22',
111  'lastTransId' => 'd45d22',
112  ],
113  ];
114  }
115 }
$amount
Definition: order.php:14
testBuild($parentTransactionId, $callLastTransId, $lastTransId, $expected)