Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
DescriptorDataBuilderTest.php
Go to the documentation of this file.
1 <?php
7 
13 use PHPUnit_Framework_MockObject_MockObject as MockObject;
14 
18 class DescriptorDataBuilderTest extends \PHPUnit\Framework\TestCase
19 {
23  private $subjectReaderMock;
24 
28  private $configMock;
29 
33  private $builder;
34 
35  protected function setUp()
36  {
37  $this->configMock = $this->getMockBuilder(Config::class)
38  ->disableOriginalConstructor()
39  ->setMethods(['getDynamicDescriptors'])
40  ->getMock();
41  $this->subjectReaderMock = $this->getMockBuilder(SubjectReader::class)
42  ->disableOriginalConstructor()
43  ->getMock();
44 
45  $this->builder = new DescriptorDataBuilder($this->configMock, $this->subjectReaderMock);
46  }
47 
53  public function testBuild(array $descriptors, array $expected)
54  {
55  $paymentDOMock = $this->createMock(PaymentDataObjectInterface::class);
56  $buildSubject = [
57  'payment' => $paymentDOMock,
58  ];
59  $this->subjectReaderMock->expects(self::once())
60  ->method('readPayment')
61  ->with($buildSubject)
62  ->willReturn($paymentDOMock);
63 
64  $order = $this->createMock(OrderAdapterInterface::class);
65  $order->expects(self::once())->method('getStoreId')->willReturn('1');
66 
67  $paymentDOMock->expects(self::once())->method('getOrder')->willReturn($order);
68 
69  $this->configMock->method('getDynamicDescriptors')->willReturn($descriptors);
70 
71  $actual = $this->builder->build(['payment' => $paymentDOMock]);
72  static::assertEquals($expected, $actual);
73  }
74 
79  public function buildDataProvider()
80  {
81  $name = 'company * product';
82  $phone = '333-22-22-333';
83  $url = 'https://test.url.mage.com';
84  return [
85  [
86  'descriptors' => [
87  'name' => $name,
88  'phone' => $phone,
89  'url' => $url,
90  ],
91  'expected' => [
92  'descriptor' => [
93  'name' => $name,
94  'phone' => $phone,
95  'url' => $url,
96  ],
97  ],
98  ],
99  [
100  'descriptors' => [
101  'name' => $name,
102  'phone' => $phone,
103  ],
104  'expected' => [
105  'descriptor' => [
106  'name' => $name,
107  'phone' => $phone,
108  ],
109  ],
110  ],
111  [
112  'descriptors' => [
113  'name' => $name,
114  ],
115  'expected' => [
116  'descriptor' => [
117  'name' => $name,
118  ],
119  ],
120  ],
121  [
122  'descriptors' => [],
123  'expected' => [],
124  ],
125  ];
126  }
127 }
$order
Definition: order.php:55
if(!isset($_GET['name'])) $name
Definition: log.php:14