Skip to content

Commit 0e2beb8

Browse files
Igor Melnikovbuskamuza
authored andcommitted
MAGETWO-58692: Refactor Module_Webapi, Module_Elasticsearch
Refactoring integration tests
1 parent 4002afa commit 0e2beb8

File tree

2 files changed

+150
-314
lines changed

2 files changed

+150
-314
lines changed

dev/tests/integration/testsuite/Magento/Webapi/Model/ServiceMetadataTest.php

Lines changed: 73 additions & 188 deletions
Original file line numberDiff line numberDiff line change
@@ -5,231 +5,116 @@
55
*/
66
namespace Magento\Webapi\Model;
77

8+
use Magento\TestFramework\Helper\Bootstrap;
9+
use Magento\Webapi\Model\ServiceMetadata;
10+
use Magento\Customer\Api\AccountManagementInterface;
11+
812
class ServiceMetadataTest extends \PHPUnit_Framework_TestCase
913
{
1014
/**
11-
* @var \Magento\Webapi\Model\ServiceMetadata
15+
* @var ServiceMetadata
1216
*/
1317
private $serviceMetadata;
1418

15-
/**
16-
* Set up helper.
17-
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
18-
*/
1919
protected function setUp()
2020
{
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);
16023
}
16124

16225
public function testGetServiceMetadata()
16326
{
164-
$expectedResult = [
27+
$expected = [
16528
'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.',
17137
'interface' => [
17238
'in' => [
17339
'parameters' => [
174-
'customerId' => [
175-
'force' => true,
176-
'value' => '%customer_id%',
177-
],
178-
'requiredInputParameter' => [
40+
'email' => [
41+
'type' => 'string',
17942
'required' => true,
43+
'documentation' => null
18044
],
181-
],
45+
'confirmationKey' => [
46+
'type' => 'string',
47+
'required' => true,
48+
'documentation' => null
49+
]
50+
]
18251
],
18352
'out' => [
18453
'parameters' => [
185-
'outputParameter' => [
186-
'type' => 'string',
187-
],
54+
'result' => [
55+
'type' => 'CustomerDataCustomerInterface',
56+
'required' => true,
57+
'documentation' => ''
58+
]
18859
],
189-
],
190-
],
191-
],
60+
'throws' => [
61+
'\Magento\Framework\Exception\LocalizedException'
62+
]
63+
]
64+
]
65+
]
19266
],
193-
'class' => \Magento\Customer\Api\AccountManagementInterface::class,
194-
'description' => 'classDescription',
67+
'class' => AccountManagementInterface::class,
68+
'description' => 'Interface for managing customers accounts.',
19569
];
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);
19872
}
19973

20074
public function testGetRouteMetadata()
20175
{
202-
$expectedResult = [
76+
$expected = [
20377
'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.',
20986
'interface' => [
21087
'in' => [
21188
'parameters' => [
212-
'customerId' => [
213-
'force' => true,
214-
'value' => '%customer_id%',
215-
],
216-
'requiredInputParameter' => [
89+
'email' => [
90+
'type' => 'string',
21791
'required' => true,
92+
'documentation' => null
21893
],
219-
],
94+
'confirmationKey' => [
95+
'type' => 'string',
96+
'required' => true,
97+
'documentation' => null
98+
]
99+
]
220100
],
221101
'out' => [
222102
'parameters' => [
223-
'outputParameter' => [
224-
'type' => 'string',
225-
],
103+
'result' => [
104+
'type' => 'CustomerDataCustomerInterface',
105+
'required' => true,
106+
'documentation' => ''
107+
]
226108
],
227-
],
228-
],
229-
],
109+
'throws' => [
110+
'\Magento\Framework\Exception\LocalizedException'
111+
]
112+
]
113+
]
114+
]
230115
],
231-
'class' => \Magento\Customer\Api\AccountManagementInterface::class,
232-
'description' => 'classDescription',
116+
'class' => AccountManagementInterface::class,
117+
'description' => 'Interface for managing customers accounts.',
233118
'routes' => [
234119
'/V1/customers/me/activate' => [
235120
'PUT' => [
@@ -244,7 +129,7 @@ public function testGetRouteMetadata()
244129
]
245130
]
246131
];
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);
249134
}
250135
}

0 commit comments

Comments
 (0)