1
1
<?php
2
- declare (strict_types=1 );
3
2
/**
4
3
* Copyright © Magento, Inc. All rights reserved.
5
4
* See COPYING.txt for license details.
6
5
*/
6
+ declare (strict_types=1 );
7
7
8
8
namespace Magento \Customer \Test \Unit \Controller \Address ;
9
9
10
+ use Magento \Customer \Api \AddressRepositoryInterface ;
11
+ use Magento \Customer \Api \CustomerRepositoryInterface ;
10
12
use Magento \Customer \Api \Data \AddressInterface ;
13
+ use Magento \Customer \Api \Data \AddressInterfaceFactory ;
14
+ use Magento \Customer \Api \Data \CustomerInterface ;
15
+ use Magento \Customer \Controller \Adminhtml \Address \Save ;
16
+ use Magento \Customer \Model \Metadata \Form ;
17
+ use Magento \Customer \Model \Metadata \FormFactory ;
18
+ use Magento \Framework \Api \DataObjectHelper ;
19
+ use Magento \Framework \App \RequestInterface ;
11
20
use Magento \Framework \Controller \Result \Json ;
12
21
use Magento \Framework \Controller \Result \JsonFactory ;
13
22
use Magento \Framework \TestFramework \Unit \Helper \ObjectManager as ObjectManagerHelper ;
23
+ use PHPUnit \Framework \MockObject \MockObject ;
24
+ use PHPUnit \Framework \TestCase ;
25
+ use Psr \Log \LoggerInterface ;
14
26
15
27
/**
16
28
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
17
29
*/
18
- class SaveTest extends \ PHPUnit \ Framework \ TestCase
30
+ class SaveTest extends TestCase
19
31
{
20
32
/**
21
- * @var \Magento\Customer\Controller\Adminhtml\Address\ Save
33
+ * @var Save
22
34
*/
23
35
private $ model ;
24
36
25
37
/**
26
- * @var \Magento\Customer\Api\ AddressRepositoryInterface|\PHPUnit_Framework_MockObject_MockObject
38
+ * @var AddressRepositoryInterface|MockObject
27
39
*/
28
40
private $ addressRepositoryMock ;
29
41
30
42
/**
31
- * @var \Magento\Customer\Model\Metadata\ FormFactory|\PHPUnit_Framework_MockObject_MockObject
43
+ * @var FormFactory|MockObject
32
44
*/
33
45
private $ formFactoryMock ;
34
46
35
47
/**
36
- * @var \Magento\Customer\Api\ CustomerRepositoryInterface|\PHPUnit_Framework_MockObject_MockObject
48
+ * @var CustomerRepositoryInterface|MockObject
37
49
*/
38
50
private $ customerRepositoryMock ;
39
51
40
52
/**
41
- * @var \Magento\Framework\Api\ DataObjectHelper|\PHPUnit_Framework_MockObject_MockObject
53
+ * @var DataObjectHelper|MockObject
42
54
*/
43
55
private $ dataObjectHelperMock ;
44
56
45
57
/**
46
- * @var \Magento\Customer\Api\Data\ AddressInterfaceFactory|\PHPUnit_Framework_MockObject_MockObject
58
+ * @var AddressInterfaceFactory|MockObject
47
59
*/
48
60
private $ addressDataFactoryMock ;
49
61
50
62
/**
51
- * @var \Psr\Log\ LoggerInterface|\PHPUnit_Framework_MockObject_MockObject
63
+ * @var LoggerInterface|MockObject
52
64
*/
53
65
private $ loggerMock ;
54
66
55
67
/**
56
- * @var \Magento\Framework\App\ RequestInterface|\PHPUnit_Framework_MockObject_MockObject
68
+ * @var RequestInterface|MockObject
57
69
*/
58
70
private $ requestMock ;
59
71
60
72
/**
61
- * @var AddressInterface|\PHPUnit_Framework_MockObject_MockObject
73
+ * @var AddressInterface|MockObject
62
74
*/
63
75
private $ address ;
64
76
65
77
/**
66
- * @var JsonFactory|\PHPUnit_Framework_MockObject_MockObject
78
+ * @var JsonFactory|MockObject
67
79
*/
68
80
private $ resultJsonFactory ;
69
81
70
82
/**
71
- * @var Json|\PHPUnit_Framework_MockObject_MockObject
83
+ * @var Json|MockObject
72
84
*/
73
85
private $ json ;
74
86
@@ -77,13 +89,13 @@ class SaveTest extends \PHPUnit\Framework\TestCase
77
89
*/
78
90
protected function setUp ()
79
91
{
80
- $ this ->addressRepositoryMock = $ this ->createMock (\ Magento \ Customer \ Api \ AddressRepositoryInterface::class);
81
- $ this ->formFactoryMock = $ this ->createMock (\ Magento \ Customer \ Model \ Metadata \ FormFactory::class);
82
- $ this ->customerRepositoryMock = $ this ->createMock (\ Magento \ Customer \ Api \ CustomerRepositoryInterface::class);
83
- $ this ->dataObjectHelperMock = $ this ->createMock (\ Magento \ Framework \ Api \ DataObjectHelper ::class);
84
- $ this ->addressDataFactoryMock = $ this ->createMock (\ Magento \ Customer \ Api \ Data \ AddressInterfaceFactory::class);
85
- $ this ->loggerMock = $ this ->createMock (\ Psr \ Log \ LoggerInterface::class);
86
- $ this ->requestMock = $ this ->createMock (\ Magento \ Framework \ App \ RequestInterface::class);
92
+ $ this ->addressRepositoryMock = $ this ->createMock (AddressRepositoryInterface::class);
93
+ $ this ->formFactoryMock = $ this ->createMock (FormFactory::class);
94
+ $ this ->customerRepositoryMock = $ this ->createMock (CustomerRepositoryInterface::class);
95
+ $ this ->dataObjectHelperMock = $ this ->createMock (DataObjectHelper ::class);
96
+ $ this ->addressDataFactoryMock = $ this ->createMock (AddressInterfaceFactory::class);
97
+ $ this ->loggerMock = $ this ->createMock (LoggerInterface::class);
98
+ $ this ->requestMock = $ this ->createMock (RequestInterface::class);
87
99
$ this ->address = $ this ->getMockBuilder (AddressInterface::class)
88
100
->disableOriginalConstructor ()
89
101
->getMockForAbstractClass ();
@@ -98,7 +110,7 @@ protected function setUp()
98
110
$ objectManager = new ObjectManagerHelper ($ this );
99
111
100
112
$ this ->model = $ objectManager ->getObject (
101
- \ Magento \ Customer \ Controller \ Adminhtml \ Address \ Save::class,
113
+ Save::class,
102
114
[
103
115
'addressRepository ' => $ this ->addressRepositoryMock ,
104
116
'formFactory ' => $ this ->formFactoryMock ,
@@ -153,15 +165,15 @@ public function testExecute(): void
153
165
->willReturnOnConsecutiveCalls (22 , 1 );
154
166
155
167
$ customerMock = $ this ->getMockBuilder (
156
- \ Magento \ Customer \ Api \ Data \ CustomerInterface::class
168
+ CustomerInterface::class
157
169
)->disableOriginalConstructor ()->getMock ();
158
170
159
171
$ this ->customerRepositoryMock ->expects ($ this ->atLeastOnce ())
160
172
->method ('getById ' )
161
173
->with ($ customerId )
162
174
->willReturn ($ customerMock );
163
175
164
- $ customerAddressFormMock = $ this ->createMock (\ Magento \ Customer \ Model \ Metadata \ Form::class);
176
+ $ customerAddressFormMock = $ this ->createMock (Form::class);
165
177
$ customerAddressFormMock ->expects ($ this ->atLeastOnce ())
166
178
->method ('extractData ' )
167
179
->with ($ this ->requestMock )
@@ -200,7 +212,7 @@ public function testExecute(): void
200
212
->method ('setData ' )
201
213
->with (
202
214
[
203
- 'message ' => __ ('Customer address has been updated. ' ),
215
+ 'messages ' => __ ('Customer address has been updated. ' ),
204
216
'error ' => false ,
205
217
'data ' => [
206
218
'entity_id ' => $ addressId
0 commit comments