Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
KountPaymentDataBuilderTest.php
Go to the documentation of this file.
1 <?php
7 
15 use PHPUnit_Framework_MockObject_MockObject as MockObject;
16 
20 class KountPaymentDataBuilderTest extends \PHPUnit\Framework\TestCase
21 {
22  const DEVICE_DATA = '{"test": "test"}';
23 
27  private $builder;
28 
32  private $configMock;
33 
37  private $paymentMock;
38 
42  private $paymentDOMock;
43 
47  private $subjectReaderMock;
48 
49  protected function setUp()
50  {
51  $this->paymentDOMock = $this->createMock(PaymentDataObjectInterface::class);
52  $this->configMock = $this->getMockBuilder(Config::class)
53  ->disableOriginalConstructor()
54  ->getMock();
55  $this->paymentMock = $this->getMockBuilder(Payment::class)
56  ->disableOriginalConstructor()
57  ->getMock();
58  $this->subjectReaderMock = $this->getMockBuilder(SubjectReader::class)
59  ->disableOriginalConstructor()
60  ->getMock();
61 
62  $this->builder = new KountPaymentDataBuilder($this->configMock, $this->subjectReaderMock);
63  }
64 
69  {
70  $buildSubject = [];
71 
72  $this->configMock->expects(self::never())
73  ->method('hasFraudProtection')
74  ->willReturn(true);
75 
76  $this->subjectReaderMock->expects(self::once())
77  ->method('readPayment')
78  ->with($buildSubject)
79  ->willThrowException(new \InvalidArgumentException());
80 
81  $this->builder->build($buildSubject);
82  }
83 
84  public function testBuild()
85  {
86  $additionalData = [
88  ];
89 
90  $expectedResult = [
92  ];
93 
94  $order = $this->createMock(OrderAdapterInterface::class);
95  $this->paymentDOMock->expects(self::once())->method('getOrder')->willReturn($order);
96 
97  $buildSubject = ['payment' => $this->paymentDOMock];
98 
99  $this->paymentMock->expects(self::exactly(count($additionalData)))
100  ->method('getAdditionalInformation')
101  ->willReturn($additionalData);
102 
103  $this->configMock->expects(self::once())
104  ->method('hasFraudProtection')
105  ->willReturn(true);
106 
107  $this->paymentDOMock->expects(self::once())
108  ->method('getPayment')
109  ->willReturn($this->paymentMock);
110 
111  $this->subjectReaderMock->expects(self::once())
112  ->method('readPayment')
113  ->with($buildSubject)
114  ->willReturn($this->paymentDOMock);
115 
116  static::assertEquals(
117  $expectedResult,
118  $this->builder->build($buildSubject)
119  );
120  }
121 }
$order
Definition: order.php:55