Skip to content

Commit 23077d5

Browse files
author
larsroettig
committed
- Fix API Test - Add Type Hint
1 parent cdf1165 commit 23077d5

File tree

2 files changed

+146
-134
lines changed

2 files changed

+146
-134
lines changed

app/code/Magento/Inventory/Model/Source/Validator/CarrierLinksValidator.php

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class CarrierLinksValidator implements SourceValidatorInterface
3030

3131
/**
3232
* @param ValidationResultFactory $validationResultFactory
33+
* @param Config $shippingConfig
3334
*/
3435
public function __construct(ValidationResultFactory $validationResultFactory, Config $shippingConfig)
3536
{

app/code/Magento/InventoryApi/Test/Api/SourceRepository/CarrierLinkManagementTest.php

+145-134
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
67
namespace Magento\InventoryApi\Test\Api\SourceRepository;
78

8-
use Magento\Framework\Webapi\Exception;
99
use Magento\Framework\Webapi\Rest\Request;
1010
use Magento\InventoryApi\Api\Data\SourceCarrierLinkInterface;
1111
use Magento\InventoryApi\Api\Data\SourceInterface;
@@ -49,106 +49,6 @@ public function testCarrierLinksManagement(array $carrierLinks)
4949
self::assertEquals($expectedData[SourceInterface::CARRIER_LINKS], $sourceData[SourceInterface::CARRIER_LINKS]);
5050
}
5151

52-
/**
53-
* @return array
54-
*/
55-
public function dataProviderCarrierLinks(): array
56-
{
57-
return [
58-
'add_carrier_new_links' => [
59-
[
60-
[
61-
SourceCarrierLinkInterface::CARRIER_CODE => 'ups',
62-
SourceCarrierLinkInterface::POSITION => 100,
63-
],
64-
[
65-
SourceCarrierLinkInterface::CARRIER_CODE => 'usps',
66-
SourceCarrierLinkInterface::POSITION => 200,
67-
],
68-
[
69-
SourceCarrierLinkInterface::CARRIER_CODE => 'dhl',
70-
SourceCarrierLinkInterface::POSITION => 300,
71-
],
72-
[
73-
SourceCarrierLinkInterface::CARRIER_CODE => 'fedex',
74-
SourceCarrierLinkInterface::POSITION => 400,
75-
],
76-
],
77-
],
78-
'replace_carrier_links' => [
79-
[
80-
[
81-
SourceCarrierLinkInterface::CARRIER_CODE => 'dhl',
82-
SourceCarrierLinkInterface::POSITION => 100,
83-
],
84-
[
85-
SourceCarrierLinkInterface::CARRIER_CODE => 'fedex',
86-
SourceCarrierLinkInterface::POSITION => 200,
87-
],
88-
],
89-
],
90-
'delete_carrier_links' => [
91-
[],
92-
],
93-
];
94-
}
95-
96-
/**
97-
* @magentoApiDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/source.php
98-
*/
99-
public function testAssignCarrierLinksIfUseGlobalConfigurationChosen()
100-
{
101-
$sourceId = 10;
102-
$expectedData = [
103-
SourceInterface::NAME => 'source-name-1',
104-
SourceInterface::POSTCODE => 'source-postcode',
105-
SourceInterface::COUNTRY_ID => 'US',
106-
SourceInterface::USE_DEFAULT_CARRIER_CONFIG => 1,
107-
SourceInterface::CARRIER_LINKS => [
108-
[
109-
SourceCarrierLinkInterface::CARRIER_CODE => 'ups',
110-
SourceCarrierLinkInterface::POSITION => 100,
111-
],
112-
[
113-
SourceCarrierLinkInterface::CARRIER_CODE => 'usps',
114-
SourceCarrierLinkInterface::POSITION => 200,
115-
],
116-
],
117-
];
118-
119-
$expectedErrorData = [
120-
'message' => 'Validation Failed',
121-
'errors' => [
122-
[
123-
'message' => 'You can\'t configure "%field" because you have chosen Global Shipping configuration.',
124-
'parameters' => [
125-
'field' => SourceInterface::CARRIER_LINKS,
126-
],
127-
],
128-
],
129-
];
130-
131-
try {
132-
$this->saveSource($sourceId, $expectedData);
133-
$this->fail('Expected throwing exception');
134-
} catch (\Exception $e) {
135-
if (TESTS_WEB_API_ADAPTER == self::ADAPTER_REST) {
136-
self::assertEquals($expectedErrorData, $this->processRestExceptionResult($e));
137-
self::assertEquals(Exception::HTTP_BAD_REQUEST, $e->getCode());
138-
} elseif (TESTS_WEB_API_ADAPTER == self::ADAPTER_SOAP) {
139-
$this->assertInstanceOf('SoapFault', $e);
140-
// @see \Magento\TestFramework\TestCase\WebapiAbstract::getActualWrappedErrors()
141-
$expectedWrappedErrors = $expectedErrorData['errors'];
142-
$expectedWrappedErrors[0]['params'] = $expectedWrappedErrors[0]['parameters'];
143-
unset($expectedWrappedErrors[0]['parameters']);
144-
145-
$this->checkSoapFault($e, $expectedErrorData['message'], 'env:Sender', [], $expectedWrappedErrors);
146-
} else {
147-
throw $e;
148-
}
149-
}
150-
}
151-
15252
/**
15353
* @param int $sourceId
15454
* @param array $data
@@ -198,24 +98,13 @@ private function getSourceDataById(int $sourceId): array
19898
return $response;
19999
}
200100

201-
public function testFailedValidationOnCreate()
101+
/**
102+
* @param array $carrierLinks
103+
* @magentoApiDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/source.php
104+
* @dataProvider dataProviderForValidationFailed
105+
*/
106+
public function testCarrierLinksValidation(array $carrierData, array $expectedErrorData)
202107
{
203-
$expectedData = [
204-
SourceInterface::NAME => 'source-name-1',
205-
SourceInterface::POSTCODE => 'source-postcode',
206-
SourceInterface::COUNTRY_ID => 'US',
207-
SourceInterface::USE_DEFAULT_CARRIER_CONFIG => 0,
208-
SourceInterface::CARRIER_LINKS => [
209-
[
210-
SourceCarrierLinkInterface::CARRIER_CODE => 'no_exists_1',
211-
SourceCarrierLinkInterface::POSITION => 100,
212-
],
213-
[
214-
SourceCarrierLinkInterface::CARRIER_CODE => 'no_exists_2',
215-
SourceCarrierLinkInterface::POSITION => 200,
216-
],
217-
],
218-
];
219108
$serviceInfo = [
220109
'rest' => [
221110
'resourcePath' => self::RESOURCE_PATH,
@@ -227,29 +116,151 @@ public function testFailedValidationOnCreate()
227116
],
228117
];
229118

230-
$expectedErrorData = [
231-
'message' => 'Validation Failed',
232-
'errors' => [
119+
try {
120+
$this->_webApiCall($serviceInfo, ['source' => $carrierData]);
121+
$this->fail('Expected throwing exception');
122+
} catch (\Exception $e) {
123+
self::assertEquals($expectedErrorData, $this->processRestExceptionResult($e));
124+
self::assertEquals(\Magento\Framework\Webapi\Exception::HTTP_BAD_REQUEST, $e->getCode());
125+
}
126+
}
127+
128+
/**
129+
* @return array
130+
*/
131+
public function dataProviderCarrierLinks(): array
132+
{
133+
return [
134+
'add_carrier_new_links' => [
233135
[
234-
'message' => 'You can\'t configure because carrier with code: "%carrier" don\'t exists.',
235-
'parameters' => [
236-
'carrier' => 'no_exists_1'
136+
[
137+
SourceCarrierLinkInterface::CARRIER_CODE => 'ups',
138+
SourceCarrierLinkInterface::POSITION => 100,
139+
],
140+
[
141+
SourceCarrierLinkInterface::CARRIER_CODE => 'usps',
142+
SourceCarrierLinkInterface::POSITION => 200,
143+
],
144+
[
145+
SourceCarrierLinkInterface::CARRIER_CODE => 'dhl',
146+
SourceCarrierLinkInterface::POSITION => 300,
147+
],
148+
[
149+
SourceCarrierLinkInterface::CARRIER_CODE => 'fedex',
150+
SourceCarrierLinkInterface::POSITION => 400,
237151
],
238152
],
153+
],
154+
'replace_carrier_links' => [
239155
[
240-
'message' => 'You can\'t configure because carrier with code: "%carrier" don\'t exists.',
241-
'parameters' => [
242-
'carrier' => 'no_exists_2'
156+
[
157+
SourceCarrierLinkInterface::CARRIER_CODE => 'dhl',
158+
SourceCarrierLinkInterface::POSITION => 100,
159+
],
160+
[
161+
SourceCarrierLinkInterface::CARRIER_CODE => 'fedex',
162+
SourceCarrierLinkInterface::POSITION => 200,
243163
],
244-
]
164+
],
165+
],
166+
'delete_carrier_links' => [
167+
[],
245168
],
246169
];
170+
}
247171

248-
try {
249-
$this->_webApiCall($serviceInfo, ['source' => $expectedData]);
250-
} catch (\Exception $e) {
251-
self::assertEquals($expectedErrorData, $this->processRestExceptionResult($e));
252-
self::assertEquals(\Magento\Framework\Webapi\Exception::HTTP_BAD_REQUEST, $e->getCode());
253-
}
172+
/**
173+
* @return array
174+
*/
175+
public function dataProviderForValidationFailed(): array
176+
{
177+
return [
178+
'not_list_of_SourceCarrierLinkInterface' => [
179+
[
180+
SourceInterface::NAME => 'source-name-1',
181+
SourceInterface::POSTCODE => 'source-postcode',
182+
SourceInterface::COUNTRY_ID => 'US',
183+
SourceInterface::USE_DEFAULT_CARRIER_CONFIG => 0,
184+
SourceInterface::CARRIER_LINKS => 1222
185+
],
186+
[
187+
'message' => 'Validation Failed',
188+
'errors' => [
189+
[
190+
'message' => '"%field" must be list of SourceCarrierLinkInterface.',
191+
'parameters' => [
192+
'field' => SourceInterface::CARRIER_LINKS,
193+
],
194+
],
195+
],
196+
],
197+
],
198+
'use_global_configuration_chosen' => [
199+
[
200+
SourceInterface::NAME => 'source-name-1',
201+
SourceInterface::POSTCODE => 'source-postcode',
202+
SourceInterface::COUNTRY_ID => 'US',
203+
SourceInterface::USE_DEFAULT_CARRIER_CONFIG => 1,
204+
SourceInterface::CARRIER_LINKS => [
205+
[
206+
SourceCarrierLinkInterface::CARRIER_CODE => 'ups',
207+
SourceCarrierLinkInterface::POSITION => 100,
208+
],
209+
[
210+
SourceCarrierLinkInterface::CARRIER_CODE => 'usps',
211+
SourceCarrierLinkInterface::POSITION => 200,
212+
],
213+
],
214+
],
215+
[
216+
'message' => 'Validation Failed',
217+
'errors' => [
218+
[
219+
'message' =>
220+
'You can\'t configure "%field" because you have chosen Global Shipping configuration.',
221+
'parameters' => [
222+
'field' => SourceInterface::CARRIER_LINKS,
223+
],
224+
],
225+
],
226+
],
227+
],
228+
'carrier_codes_not_exits' => [
229+
[
230+
SourceInterface::NAME => 'source-name-1',
231+
SourceInterface::POSTCODE => 'source-postcode',
232+
SourceInterface::COUNTRY_ID => 'US',
233+
SourceInterface::USE_DEFAULT_CARRIER_CONFIG => 0,
234+
SourceInterface::CARRIER_LINKS => [
235+
[
236+
SourceCarrierLinkInterface::CARRIER_CODE => 'no_exists_1',
237+
SourceCarrierLinkInterface::POSITION => 100,
238+
],
239+
[
240+
SourceCarrierLinkInterface::CARRIER_CODE => 'no_exists_2',
241+
SourceCarrierLinkInterface::POSITION => 200,
242+
],
243+
],
244+
],
245+
[
246+
'message' => 'Validation Failed',
247+
'errors' => [
248+
[
249+
'message' => 'You can\'t configure because carrier with code: "%carrier" don\'t exists.',
250+
'parameters' => [
251+
'carrier' => 'no_exists_1'
252+
],
253+
],
254+
[
255+
'message' => 'You can\'t configure because carrier with code: "%carrier" don\'t exists.',
256+
'parameters' => [
257+
'carrier' => 'no_exists_2'
258+
],
259+
]
260+
],
261+
],
262+
]
263+
264+
];
254265
}
255266
}

0 commit comments

Comments
 (0)