Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
CustomerDataBuilderTest.php
Go to the documentation of this file.
1 <?php
7 
13 use PHPUnit_Framework_MockObject_MockObject as MockObject;
14 
18 class CustomerDataBuilderTest extends \PHPUnit\Framework\TestCase
19 {
23  private $paymentDOMock;
24 
28  private $orderMock;
29 
33  private $builder;
34 
38  private $subjectReaderMock;
39 
40  protected function setUp()
41  {
42  $this->paymentDOMock = $this->createMock(PaymentDataObjectInterface::class);
43  $this->orderMock = $this->createMock(OrderAdapterInterface::class);
44  $this->subjectReaderMock = $this->getMockBuilder(SubjectReader::class)
45  ->disableOriginalConstructor()
46  ->getMock();
47 
48  $this->builder = new CustomerDataBuilder($this->subjectReaderMock);
49  }
50 
55  {
56  $buildSubject = [
57  'payment' => null,
58  ];
59 
60  $this->subjectReaderMock->expects(self::once())
61  ->method('readPayment')
62  ->with($buildSubject)
63  ->willThrowException(new \InvalidArgumentException());
64 
65  $this->builder->build($buildSubject);
66  }
67 
74  public function testBuild($billingData, $expectedResult)
75  {
76  $billingMock = $this->getBillingMock($billingData);
77 
78  $this->paymentDOMock->expects(static::once())
79  ->method('getOrder')
80  ->willReturn($this->orderMock);
81  $this->orderMock->expects(static::once())
82  ->method('getBillingAddress')
83  ->willReturn($billingMock);
84 
85  $buildSubject = [
86  'payment' => $this->paymentDOMock,
87  ];
88 
89  $this->subjectReaderMock->expects(self::once())
90  ->method('readPayment')
91  ->with($buildSubject)
92  ->willReturn($this->paymentDOMock);
93 
94  self::assertEquals($expectedResult, $this->builder->build($buildSubject));
95  }
96 
100  public function dataProviderBuild()
101  {
102  return [
103  [
104  [
105  'first_name' => 'John',
106  'last_name' => 'Smith',
107  'company' => 'Magento',
108  'phone' => '555-555-555',
109  'email' => '[email protected]',
110  ],
111  [
115  CustomerDataBuilder::COMPANY => 'Magento',
116  CustomerDataBuilder::PHONE => '555-555-555',
118  ],
119  ],
120  ],
121  ];
122  }
123 
128  private function getBillingMock($billingData)
129  {
130  $addressMock = $this->createMock(AddressAdapterInterface::class);
131 
132  $addressMock->expects(static::once())
133  ->method('getFirstname')
134  ->willReturn($billingData['first_name']);
135  $addressMock->expects(static::once())
136  ->method('getLastname')
137  ->willReturn($billingData['last_name']);
138  $addressMock->expects(static::once())
139  ->method('getCompany')
140  ->willReturn($billingData['company']);
141  $addressMock->expects(static::once())
142  ->method('getTelephone')
143  ->willReturn($billingData['phone']);
144  $addressMock->expects(static::once())
145  ->method('getEmail')
146  ->willReturn($billingData['email']);
147 
148  return $addressMock;
149  }
150 }
$billingData