5
5
*/
6
6
namespace Magento \Webapi \Model ;
7
7
8
+ use Magento \TestFramework \Helper \Bootstrap ;
9
+ use Magento \Webapi \Model \ServiceMetadata ;
10
+ use Magento \Customer \Api \AccountManagementInterface ;
11
+
8
12
class ServiceMetadataTest extends \PHPUnit_Framework_TestCase
9
13
{
10
14
/**
11
- * @var \Magento\Webapi\Model\ ServiceMetadata
15
+ * @var ServiceMetadata
12
16
*/
13
17
private $ serviceMetadata ;
14
18
15
- /**
16
- * Set up helper.
17
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
18
- */
19
19
protected function setUp ()
20
20
{
21
- $ interfaceParameters = [
22
- 'activateById ' => [
23
- 'interface ' => [
24
- 'in ' => [
25
- 'parameters ' => [
26
- 'customerId ' => [
27
- 'force ' => true ,
28
- 'value ' => '%customer_id% ' ,
29
- ],
30
- 'requiredInputParameter ' => [
31
- 'required ' => true ,
32
- ],
33
- ],
34
- ],
35
- 'out ' => [
36
- 'parameters ' => [
37
- 'outputParameter ' => [
38
- 'type ' => 'string ' ,
39
- ],
40
- ],
41
- ],
42
- ],
43
- ],
44
- ];
45
- $ classReflection = $ this ->getMock (
46
- \Magento \Webapi \Model \Config \ClassReflector::class,
47
- ['reflectClassMethods ' , 'extractClassDescription ' ],
48
- [],
49
- '' ,
50
- false
51
- );
52
- $ classReflection ->expects ($ this ->any ())
53
- ->method ('reflectClassMethods ' )
54
- ->will ($ this ->returnValue ($ interfaceParameters ));
55
- $ classReflection ->expects ($ this ->any ())
56
- ->method ('extractClassDescription ' )
57
- ->will ($ this ->returnValue ('classDescription ' ));
58
-
59
- $ servicesConfig = [
60
- 'services ' => [\Magento \Customer \Api \AccountManagementInterface::class => [
61
- 'V1 ' => [
62
- 'methods ' => [
63
- 'activateById ' => [
64
- 'resources ' => [
65
- [
66
- 'Magento_Customer::manage ' ,
67
- ],
68
- ],
69
- 'secure ' => false ,
70
- ],
71
- ],
72
- ],
73
- ], \Magento \Customer \Api \CustomerRepositoryInterface::class => [
74
- 'V1 ' => [
75
- 'methods ' => [
76
- 'getById ' => [
77
- 'resources ' => [
78
- [
79
- 'Magento_Customer::customer ' ,
80
- ],
81
- ],
82
- 'secure ' => false ,
83
- ],
84
- ],
85
- ],
86
- ],
87
- ],
88
- 'routes ' => [
89
- '/V1/customers/me/activate ' => [
90
- 'PUT ' => [
91
- 'secure ' => false ,
92
- 'service ' => [
93
- 'class ' => \Magento \Customer \Api \AccountManagementInterface::class,
94
- 'method ' => 'activateById ' ,
95
- ],
96
- 'resources ' => [
97
- 'self ' => true ,
98
- ],
99
- 'parameters ' => [
100
- 'customerId ' => [
101
- 'force ' => true ,
102
- 'value ' => '%customer_id% ' ,
103
- ],
104
- ],
105
- ],
106
- ],
107
- '/V1/customers/:customerId ' => [
108
- 'GET ' => [
109
- 'secure ' => false ,
110
- 'service ' => [
111
- 'class ' => \Magento \Customer \Api \CustomerRepositoryInterface::class,
112
- 'method ' => 'getById ' ,
113
- ],
114
- 'resources ' => [
115
- 'Magento_Customer::customer ' => true ,
116
- ],
117
- 'parameters ' => [
118
- ],
119
- ],
120
- ],
121
- ]
122
- ];
123
-
124
- /**
125
- * @var $cacheMock \Magento\Webapi\Model\Cache\Type\Webapi
126
- */
127
- $ cacheMock = $ this ->getMockBuilder (\Magento \Webapi \Model \Cache \Type \Webapi::class)
128
- ->disableOriginalConstructor ()
129
- ->getMock ();
130
-
131
- /** @var $readerMock \Magento\Webapi\Model\Config\Reader */
132
- $ readerMock = $ this ->getMockBuilder (\Magento \Webapi \Model \Config \Reader::class)
133
- ->disableOriginalConstructor ()
134
- ->getMock ();
135
- $ readerMock ->expects ($ this ->any ())->method ('read ' )->will ($ this ->returnValue ($ servicesConfig ));
136
-
137
- $ objectManager = \Magento \TestFramework \Helper \Bootstrap::getObjectManager ();
138
-
139
- /** @var $config \Magento\Webapi\Model\Config */
140
- $ config = $ objectManager ->create (
141
- \Magento \Webapi \Model \Config::class,
142
- [
143
- 'cache ' => $ cacheMock ,
144
- 'configReader ' => $ readerMock ,
145
- ]
146
- );
147
-
148
- $ typeProcessor = $ objectManager ->create (\Magento \Framework \Reflection \TypeProcessor::class);
149
-
150
- /** @var $config \Magento\Webapi\Model\ServiceMetadata */
151
- $ this ->serviceMetadata = $ objectManager ->create (
152
- \Magento \Webapi \Model \ServiceMetadata::class,
153
- [
154
- 'config ' => $ config ,
155
- 'cache ' => $ cacheMock ,
156
- 'classReflector ' => $ classReflection ,
157
- 'typeProcessor ' => $ typeProcessor ,
158
- ]
159
- );
21
+ $ objectManager = Bootstrap::getObjectManager ();
22
+ $ this ->serviceMetadata = $ objectManager ->create (ServiceMetadata::class);
160
23
}
161
24
162
25
public function testGetServiceMetadata ()
163
26
{
164
- $ expectedResult = [
27
+ $ expected = [
165
28
'methods ' => [
166
- 'activateById ' => [
167
- 'method ' => 'activateById ' ,
168
- 'inputRequired ' => '' ,
169
- 'isSecure ' => '' ,
170
- 'resources ' => [['Magento_Customer::manage ' ]],
29
+ 'activate ' => [
30
+ 'method ' => 'activate ' ,
31
+ 'inputRequired ' => false ,
32
+ 'isSecure ' => false ,
33
+ 'resources ' => [
34
+ 'Magento_Customer::manage '
35
+ ],
36
+ 'documentation ' => 'Activate a customer account using a key that was sent in a confirmation email. ' ,
171
37
'interface ' => [
172
38
'in ' => [
173
39
'parameters ' => [
174
- 'customerId ' => [
175
- 'force ' => true ,
176
- 'value ' => '%customer_id% ' ,
177
- ],
178
- 'requiredInputParameter ' => [
40
+ 'email ' => [
41
+ 'type ' => 'string ' ,
179
42
'required ' => true ,
43
+ 'documentation ' => null
180
44
],
181
- ],
45
+ 'confirmationKey ' => [
46
+ 'type ' => 'string ' ,
47
+ 'required ' => true ,
48
+ 'documentation ' => null
49
+ ]
50
+ ]
182
51
],
183
52
'out ' => [
184
53
'parameters ' => [
185
- 'outputParameter ' => [
186
- 'type ' => 'string ' ,
187
- ],
54
+ 'result ' => [
55
+ 'type ' => 'CustomerDataCustomerInterface ' ,
56
+ 'required ' => true ,
57
+ 'documentation ' => ''
58
+ ]
188
59
],
189
- ],
190
- ],
191
- ],
60
+ 'throws ' => [
61
+ '\Magento\Framework\Exception\LocalizedException '
62
+ ]
63
+ ]
64
+ ]
65
+ ]
192
66
],
193
- 'class ' => \ Magento \ Customer \ Api \ AccountManagementInterface::class,
194
- 'description ' => 'classDescription ' ,
67
+ 'class ' => AccountManagementInterface::class,
68
+ 'description ' => 'Interface for managing customers accounts. ' ,
195
69
];
196
- $ result = $ this ->serviceMetadata ->getServiceMetadata ('customerAccountManagementV1 ' );
197
- $ this ->assertEquals ($ expectedResult , $ result );
70
+ $ actual = $ this ->serviceMetadata ->getServiceMetadata ('customerAccountManagementV1 ' );
71
+ $ this ->assertEquals (array_replace_recursive ( $ expected , $ actual ), $ actual );
198
72
}
199
73
200
74
public function testGetRouteMetadata ()
201
75
{
202
- $ expectedResult = [
76
+ $ expected = [
203
77
'methods ' => [
204
- 'activateById ' => [
205
- 'method ' => 'activateById ' ,
206
- 'inputRequired ' => '' ,
207
- 'isSecure ' => '' ,
208
- 'resources ' => [['Magento_Customer::manage ' ]],
78
+ 'activate ' => [
79
+ 'method ' => 'activate ' ,
80
+ 'inputRequired ' => false ,
81
+ 'isSecure ' => false ,
82
+ 'resources ' => [
83
+ 'Magento_Customer::manage '
84
+ ],
85
+ 'documentation ' => 'Activate a customer account using a key that was sent in a confirmation email. ' ,
209
86
'interface ' => [
210
87
'in ' => [
211
88
'parameters ' => [
212
- 'customerId ' => [
213
- 'force ' => true ,
214
- 'value ' => '%customer_id% ' ,
215
- ],
216
- 'requiredInputParameter ' => [
89
+ 'email ' => [
90
+ 'type ' => 'string ' ,
217
91
'required ' => true ,
92
+ 'documentation ' => null
218
93
],
219
- ],
94
+ 'confirmationKey ' => [
95
+ 'type ' => 'string ' ,
96
+ 'required ' => true ,
97
+ 'documentation ' => null
98
+ ]
99
+ ]
220
100
],
221
101
'out ' => [
222
102
'parameters ' => [
223
- 'outputParameter ' => [
224
- 'type ' => 'string ' ,
225
- ],
103
+ 'result ' => [
104
+ 'type ' => 'CustomerDataCustomerInterface ' ,
105
+ 'required ' => true ,
106
+ 'documentation ' => ''
107
+ ]
226
108
],
227
- ],
228
- ],
229
- ],
109
+ 'throws ' => [
110
+ '\Magento\Framework\Exception\LocalizedException '
111
+ ]
112
+ ]
113
+ ]
114
+ ]
230
115
],
231
- 'class ' => \ Magento \ Customer \ Api \ AccountManagementInterface::class,
232
- 'description ' => 'classDescription ' ,
116
+ 'class ' => AccountManagementInterface::class,
117
+ 'description ' => 'Interface for managing customers accounts. ' ,
233
118
'routes ' => [
234
119
'/V1/customers/me/activate ' => [
235
120
'PUT ' => [
@@ -244,7 +129,7 @@ public function testGetRouteMetadata()
244
129
]
245
130
]
246
131
];
247
- $ result = $ this ->serviceMetadata ->getRouteMetadata ('customerAccountManagementV1 ' );
248
- $ this ->assertEquals ($ expectedResult , $ result );
132
+ $ actual = $ this ->serviceMetadata ->getRouteMetadata ('customerAccountManagementV1 ' );
133
+ $ this ->assertEquals (array_replace_recursive ( $ expected , $ actual ), $ actual );
249
134
}
250
135
}
0 commit comments