1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Braintree\Test\Unit\Gateway\Request;
use Magento\Braintree\Gateway\Config\Config;
use Magento\Braintree\Gateway\Request\DescriptorDataBuilder;
use Magento\Braintree\Gateway\SubjectReader;
use Magento\Payment\Gateway\Data\OrderAdapterInterface;
use Magento\Payment\Gateway\Data\PaymentDataObjectInterface;
use PHPUnit_Framework_MockObject_MockObject as MockObject;
/**
* Class DescriptorDataBuilderTest
*/
class DescriptorDataBuilderTest extends \PHPUnit\Framework\TestCase
{
/**
* @var SubjectReader|MockObject
*/
private $subjectReaderMock;
/**
* @var Config|MockObject
*/
private $configMock;
/**
* @var DescriptorDataBuilder
*/
private $builder;
protected function setUp()
{
$this->configMock = $this->getMockBuilder(Config::class)
->disableOriginalConstructor()
->setMethods(['getDynamicDescriptors'])
->getMock();
$this->subjectReaderMock = $this->getMockBuilder(SubjectReader::class)
->disableOriginalConstructor()
->getMock();
$this->builder = new DescriptorDataBuilder($this->configMock, $this->subjectReaderMock);
}
/**
* @param array $descriptors
* @param array $expected
* @dataProvider buildDataProvider
*/
public function testBuild(array $descriptors, array $expected)
{
$paymentDOMock = $this->createMock(PaymentDataObjectInterface::class);
$buildSubject = [
'payment' => $paymentDOMock,
];
$this->subjectReaderMock->expects(self::once())
->method('readPayment')
->with($buildSubject)
->willReturn($paymentDOMock);
$order = $this->createMock(OrderAdapterInterface::class);
$order->expects(self::once())->method('getStoreId')->willReturn('1');
$paymentDOMock->expects(self::once())->method('getOrder')->willReturn($order);
$this->configMock->method('getDynamicDescriptors')->willReturn($descriptors);
$actual = $this->builder->build(['payment' => $paymentDOMock]);
static::assertEquals($expected, $actual);
}
/**
* Get variations for build method testing
* @return array
*/
public function buildDataProvider()
{
$name = 'company * product';
$phone = '333-22-22-333';
$url = 'https://test.url.mage.com';
return [
[
'descriptors' => [
'name' => $name,
'phone' => $phone,
'url' => $url,
],
'expected' => [
'descriptor' => [
'name' => $name,
'phone' => $phone,
'url' => $url,
],
],
],
[
'descriptors' => [
'name' => $name,
'phone' => $phone,
],
'expected' => [
'descriptor' => [
'name' => $name,
'phone' => $phone,
],
],
],
[
'descriptors' => [
'name' => $name,
],
'expected' => [
'descriptor' => [
'name' => $name,
],
],
],
[
'descriptors' => [],
'expected' => [],
],
];
}
}