21 private $serviceMetadata;
36 private $classReflectorMock;
41 private $typeProcessorMock;
46 private $serializerMock;
50 $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
52 $this->configMock = $this->createMock(Config::class);
53 $this->cacheMock = $this->createMock(Webapi::class);
54 $this->classReflectorMock = $this->createMock(ClassReflector::class);
55 $this->typeProcessorMock = $this->createMock(TypeProcessor::class);
56 $this->serializerMock = $this->createMock(SerializerInterface::class);
59 ServiceMetadata::class,
61 'config' => $this->configMock,
62 'cache' => $this->cacheMock,
63 'classReflector' => $this->classReflectorMock,
64 'typeProcessor' => $this->typeProcessorMock,
65 'serializer' => $this->serializerMock
72 $servicesConfig = [
'foo' =>
'bar'];
73 $typeData = [
'bar' =>
'foo'];
74 $serializedServicesConfig =
'serialized services config';
75 $serializedTypeData =
'serialized type data';
76 $this->cacheMock->expects($this->at(0))
79 ->willReturn($serializedServicesConfig);
80 $this->cacheMock->expects($this->at(1))
83 ->willReturn($serializedTypeData);
84 $this->serializerMock->expects($this->at(0))
85 ->method(
'unserialize')
86 ->with($serializedServicesConfig)
87 ->willReturn($servicesConfig);
88 $this->serializerMock->expects($this->at(1))
89 ->method(
'unserialize')
90 ->with($serializedTypeData)
91 ->willReturn($typeData);
92 $this->typeProcessorMock->expects($this->once())
93 ->method(
'setTypesData')
95 $this->serviceMetadata->getServicesConfig();
96 $this->assertEquals($servicesConfig, $this->serviceMetadata->getServicesConfig());
106 CustomerRepositoryInterface::class => [
112 'Magento_Customer::customer',
122 $methodsReflectionData = [
124 'documentation' =>
'Get customer by customer ID.',
131 'documentation' => null
138 'type' =>
'CustomerDataCustomerInterface',
140 'documentation' => null
147 $servicesMetadata = [
148 'customerCustomerRepositoryV1' => [
149 'methods' => array_merge_recursive(
154 'Magento_Customer::customer',
157 'method' =>
'getById',
158 'inputRequired' =>
false,
162 $methodsReflectionData
164 'class' => CustomerRepositoryInterface::class,
165 'description' =>
'Customer CRUD interface.' 169 'CustomerDataCustomerInterface' => [
170 'documentation' =>
'Customer interface.',
175 'documentation' =>
'Customer id' 180 $serializedServicesConfig =
'serialized services config';
181 $serializedTypeData =
'serialized type data';
182 $this->cacheMock->expects($this->at(0))
186 $this->cacheMock->expects($this->at(1))
190 $this->serializerMock->expects($this->never())
191 ->method(
'unserialize');
192 $this->configMock->expects($this->once())
193 ->method(
'getServices')
194 ->willReturn($servicesConfig);
195 $this->classReflectorMock->expects($this->once())
196 ->method(
'reflectClassMethods')
197 ->willReturn($methodsReflectionData);
198 $this->classReflectorMock->expects($this->once())
199 ->method(
'extractClassDescription')
200 ->with(CustomerRepositoryInterface::class)
201 ->willReturn(
'Customer CRUD interface.');
202 $this->typeProcessorMock->expects($this->once())
203 ->method(
'getTypesData')
204 ->willReturn($typeData);
205 $this->serializerMock->expects($this->at(0))
206 ->method(
'serialize')
207 ->with($servicesMetadata)
208 ->willReturn($serializedServicesConfig);
209 $this->serializerMock->expects($this->at(1))
210 ->method(
'serialize')
212 ->willReturn($serializedTypeData);
213 $this->cacheMock->expects($this->at(2))
216 $serializedServicesConfig,
219 $this->cacheMock->expects($this->at(3))
225 $this->serviceMetadata->getServicesConfig();
226 $this->assertEquals($servicesMetadata, $this->serviceMetadata->getServicesConfig());
231 $routesConfig = [
'foo' =>
'bar'];
232 $typeData = [
'bar' =>
'foo'];
233 $serializedRoutesConfig =
'serialized routes config';
234 $serializedTypeData =
'serialized type data';
235 $this->cacheMock->expects($this->at(0))
238 ->willReturn($serializedRoutesConfig);
239 $this->cacheMock->expects($this->at(1))
242 ->willReturn($serializedTypeData);
243 $this->serializerMock->expects($this->at(0))
244 ->method(
'unserialize')
245 ->with($serializedRoutesConfig)
246 ->willReturn($routesConfig);
247 $this->serializerMock->expects($this->at(1))
248 ->method(
'unserialize')
249 ->with($serializedTypeData)
250 ->willReturn($typeData);
251 $this->typeProcessorMock->expects($this->once())
252 ->method(
'setTypesData')
254 $this->serviceMetadata->getRoutesConfig();
255 $this->assertEquals($routesConfig, $this->serviceMetadata->getRoutesConfig());
265 CustomerRepositoryInterface::class => [
271 'Magento_Customer::customer',
281 '/V1/customers/:customerId' => [
285 'class' => CustomerRepositoryInterface::class,
286 'method' =>
'getById' 289 'Magento_Customer::customer' => true
295 'class' => CustomerRepositoryInterface::class,
296 'description' =>
'Customer CRUD interface.',
298 $methodsReflectionData = [
300 'documentation' =>
'Get customer by customer ID.',
307 'documentation' => null
314 'type' =>
'CustomerDataCustomerInterface',
316 'documentation' => null
324 'customerCustomerRepositoryV1' => [
325 'methods' => array_merge_recursive(
330 'Magento_Customer::customer',
333 'method' =>
'getById',
334 'inputRequired' =>
false,
338 $methodsReflectionData
341 '/V1/customers/:customerId' => [
343 'method' =>
'getById',
348 'class' => CustomerRepositoryInterface::class,
349 'description' =>
'Customer CRUD interface.' 353 'CustomerDataCustomerInterface' => [
354 'documentation' =>
'Customer interface.',
359 'documentation' =>
'Customer id' 364 $serializedRoutesConfig =
'serialized routes config';
365 $serializedTypeData =
'serialized type data';
366 $this->cacheMock->expects($this->at(0))
370 $this->cacheMock->expects($this->at(1))
374 $this->serializerMock->expects($this->never())
375 ->method(
'unserialize');
376 $this->configMock->expects($this->exactly(2))
377 ->method(
'getServices')
378 ->willReturn($servicesConfig);
379 $this->classReflectorMock->expects($this->once())
380 ->method(
'reflectClassMethods')
381 ->willReturn($methodsReflectionData);
382 $this->classReflectorMock->expects($this->once())
383 ->method(
'extractClassDescription')
384 ->with(CustomerRepositoryInterface::class)
385 ->willReturn(
'Customer CRUD interface.');
386 $this->typeProcessorMock->expects($this->exactly(2))
387 ->method(
'getTypesData')
388 ->willReturn($typeData);
389 $this->serializerMock->expects($this->at(2))
390 ->method(
'serialize')
391 ->with($routesMetadata)
392 ->willReturn($serializedRoutesConfig);
393 $this->serializerMock->expects($this->at(3))
394 ->method(
'serialize')
396 ->willReturn($serializedTypeData);
397 $this->cacheMock->expects($this->at(6))
400 $serializedRoutesConfig,
403 $this->cacheMock->expects($this->at(7))
409 $this->serviceMetadata->getRoutesConfig();
410 $this->assertEquals($routesMetadata, $this->serviceMetadata->getRoutesConfig());
431 \Magento\Customer\Api\AccountManagementInterface::class,
434 'customerAccountManagement' 437 \Magento\Customer\Api\AddressRepositoryInterface::class,
440 'customerAddressRepositoryV1' 451 $this->serviceMetadata->getServiceName($interfaceClassName,
$version);
460 [
'BarV1Interface',
'V1'],
461 [
'Service\\V1Interface',
'V1'],
462 [
'Magento\\Foo\\Service\\BarVxInterface',
'V1'],
463 [
'Magento\\Foo\\Service\\BarInterface',
'V1'],
464 [
'Magento\\Foo\\Service\\BarV1',
'V1'],
465 [
'Foo\\Service\\BarV1Interface',
'V1'],
466 [
'Foo\\BarV1Interface',
'V1']