Skip to content

Commit d73da4a

Browse files
committed
magento-engcom/bulk-api#4 Support for Async operations in WebAPI
- Fixed static tests
1 parent 0885828 commit d73da4a

File tree

11 files changed

+63
-39
lines changed

11 files changed

+63
-39
lines changed

app/code/Magento/AsynchronousOperations/Api/Data/AsyncResponseInterface.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ interface AsyncResponseInterface
1616
{
1717
const BULK_UUID = 'bulk_uuid';
1818
const REQUEST_ITEMS = 'request_items';
19-
const IS_ERRORS = 'is_errors';
19+
const ERRORS = 'errors';
2020

2121
/**
2222
* Gets the bulk uuid.
@@ -52,14 +52,14 @@ public function setRequestItems($requestItems);
5252
* @param bool $isErrors
5353
* @return $this
5454
*/
55-
public function setIsErrors($isErrors = false);
55+
public function setErrors($isErrors = false);
5656

5757
/**
5858
* Is there errors during processing bulk
5959
*
6060
* @return boolean
6161
*/
62-
public function getIsErrors();
62+
public function isErrors();
6363

6464
/**
6565
* Retrieve existing extension attributes object.

app/code/Magento/AsynchronousOperations/Model/AsyncResponse.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,17 @@ public function setRequestItems($requestItems)
4747
/**
4848
* @inheritdoc
4949
*/
50-
public function setIsErrors($isErrors = false)
50+
public function setErrors($isErrors = false)
5151
{
52-
return $this->setData(self::IS_ERRORS, $isErrors);
52+
return $this->setData(self::ERRORS, $isErrors);
5353
}
5454

5555
/**
5656
* @inheritdoc
5757
*/
58-
public function getIsErrors()
58+
public function isErrors()
5959
{
60-
return $this->getData(self::IS_ERRORS);
60+
return $this->getData(self::ERRORS);
6161
}
6262

6363
/**

app/code/Magento/AsynchronousOperations/Model/MassSchedule.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424

2525
/**
2626
* Class MassSchedule used for adding multiple entities as Operations to Bulk Management with the status tracking
27+
*
28+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
2729
*/
2830
class MassSchedule
2931
{
@@ -90,6 +92,7 @@ class MassSchedule
9092
* @param MessageValidator $messageValidator
9193
* @param BulkManagementInterface $bulkManagement
9294
* @param LoggerInterface $logger
95+
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
9396
*/
9497
public function __construct(
9598
OperationInterfaceFactory $operationFactory,

app/code/Magento/SwaggerWebapiAsync/Test/Unit/Model/SchemaType/AsyncTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function testGetCode()
4040
*
4141
* @dataProvider getSchemaUrlPathProvider
4242
*/
43-
public function testGetSchemaUrlPath($store = null, $expected)
43+
public function testGetSchemaUrlPath($expected, $store = null)
4444
{
4545
$this->assertEquals($expected, $this->async->getSchemaUrlPath($store));
4646
}
@@ -52,12 +52,12 @@ public function getSchemaUrlPathProvider()
5252
{
5353
return [
5454
[
55-
null,
56-
'/rest/all/async/schema?services=all'
55+
'/rest/all/async/schema?services=all',
56+
null
5757
],
5858
[
59-
'test',
60-
'/rest/test/async/schema?services=all'
59+
'/rest/test/async/schema?services=all',
60+
'test'
6161
]
6262
];
6363
}

app/code/Magento/WebapiAsync/Controller/Rest/AsynchronousRequestProcessor.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ public function process(\Magento\Framework\Webapi\Rest\Request $request)
8989

9090
$entitiesParamsArray = $this->inputParamsResolver->resolve();
9191
$topicName = $this->getTopicName($request);
92-
$requestItemsList = null;
9392

9493
try {
9594
$asyncResponse = $this->asyncBulkPublisher->publishMass(

app/code/Magento/WebapiAsync/Plugin/ServiceMetadata.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ public function __construct(
6969
* @param \Magento\Webapi\Model\ServiceMetadata $subject
7070
* @param array $result
7171
* @return array
72+
* @SuppressWarnings(PHPMD.UnusedLocalVariable)
7273
*/
7374
public function afterGetServicesConfig(\Magento\Webapi\Model\ServiceMetadata $subject, array $result)
7475
{
@@ -154,6 +155,7 @@ private function getSynchronousOnlyServiceMethods(\Magento\Webapi\Model\ServiceM
154155
*
155156
* @param \Magento\Webapi\Model\ServiceMetadata $serviceMetadata
156157
* @return array
158+
* @SuppressWarnings(PHPMD.UnusedLocalVariable)
157159
*/
158160
private function getSynchronousOnlyRoutesAsServiceMethods(
159161
\Magento\Webapi\Model\ServiceMetadata $serviceMetadata

app/code/Magento/WebapiAsync/Test/Unit/Model/ServiceConfig/ReaderTest.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,10 @@ public function testReader()
4343
{
4444
$this->fileResolver->expects($this->once())
4545
->method('get')
46-
->with('webapi_async.xml', 'global')->willReturn(
47-
[
46+
->with('webapi_async.xml', 'global')->willReturn([
4847
file_get_contents(__DIR__ . '/_files/Reader/webapi_async_1.xml'),
4948
file_get_contents(__DIR__ . '/_files/Reader/webapi_async_2.xml'),
50-
]
51-
);
49+
]);
5250

5351
$mergedConfiguration = include __DIR__ . '/_files/Reader/webapi_async.php';
5452
$readConfiguration = $this->reader->read();

dev/tests/api-functional/testsuite/Magento/WebapiAsync/Model/BulkScheduleTest.php

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
* check if product was created by async requests
2525
*
2626
* @magentoAppIsolation enabled
27+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
2728
*/
2829
class BulkScheduleTest extends WebapiAbstract
2930
{
@@ -98,7 +99,6 @@ protected function setUp()
9899
}
99100

100101
parent::setUp();
101-
102102
}
103103

104104
/**
@@ -114,21 +114,22 @@ public function testAsyncScheduleBulk($product)
114114
$this->skus[] = $product['product'][ProductInterface::SKU];
115115
$this->assertCount(1, $response['request_items']);
116116
$this->assertEquals('accepted', $response['request_items'][0]['status']);
117-
$this->assertFalse($response['is_errors']);
117+
$this->assertFalse($response['errors']);
118118
} else {
119119
$this->assertCount(count($product), $response['request_items']);
120-
foreach($product as $productItem) {
120+
foreach ($product as $productItem) {
121121
$this->skus[] = $productItem['product'][ProductInterface::SKU];
122122
}
123123
foreach ($response['request_items'] as $status) {
124124
$this->assertEquals('accepted', $status['status']);
125125
}
126-
$this->assertFalse($response['is_errors']);
126+
$this->assertFalse($response['errors']);
127127
}
128128
//assert one products is created
129129
try {
130130
$this->publisherConsumerController->waitForAsynchronousResult(
131-
[$this, 'assertProductCreation'], [$product]
131+
[$this, 'assertProductCreation'],
132+
[$product]
132133
);
133134
} catch (PreconditionFailedException $e) {
134135
$this->fail("Not all products were created");
@@ -210,11 +211,27 @@ public function productCreationProvider()
210211
};
211212

212213
return [
213-
[['product' => $productBuilder([ProductInterface::TYPE_ID => 'simple', ProductInterface::SKU => 'psku-test-1'])]],
214-
[['product' => $productBuilder([ProductInterface::TYPE_ID => 'virtual', ProductInterface::SKU => 'psku-test-2'])]],
214+
[
215+
['product' =>
216+
$productBuilder([
217+
ProductInterface::TYPE_ID => 'simple',
218+
ProductInterface::SKU => 'psku-test-1'
219+
])
220+
]
221+
],
222+
[['product' => $productBuilder([
223+
ProductInterface::TYPE_ID => 'virtual',
224+
ProductInterface::SKU => 'psku-test-2'])
225+
]],
215226
[[
216-
['product' => $productBuilder([ProductInterface::TYPE_ID => 'simple', ProductInterface::SKU => 'psku-test-1'])],
217-
['product' => $productBuilder([ProductInterface::TYPE_ID => 'virtual', ProductInterface::SKU => 'psku-test-2'])]
227+
['product' => $productBuilder([
228+
ProductInterface::TYPE_ID => 'simple',
229+
ProductInterface::SKU => 'psku-test-1'
230+
])],
231+
['product' => $productBuilder([
232+
ProductInterface::TYPE_ID => 'virtual',
233+
ProductInterface::SKU => 'psku-test-2'
234+
])]
218235
]]
219236
];
220237
}
@@ -272,7 +289,7 @@ private function saveProductAsync($requestData, $storeCode = null)
272289
return $this->_webApiCall($serviceInfo, $requestData, null, $storeCode);
273290
}
274291

275-
public function assertProductCreation($product)
292+
public function assertProductCreation()
276293
{
277294
$collection = $this->objectManager->create(Collection::class)
278295
->addAttributeToFilter('sku', ['in' => $this->skus])

dev/tests/integration/testsuite/Magento/AsynchronousOperations/Model/MassScheduleTest.php

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
use Magento\Catalog\Api\ProductRepositoryInterface;
2525
use Magento\Framework\ObjectManagerInterface;
2626

27+
/**
28+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
29+
*/
2730
class MassScheduleTest extends \PHPUnit\Framework\TestCase
2831
{
2932
/**
@@ -86,13 +89,10 @@ protected function setUp()
8689
} catch (EnvironmentPreconditionException $e) {
8790
$this->markTestSkipped($e->getMessage());
8891
} catch (PreconditionFailedException $e) {
89-
$this->fail(
90-
$e->getMessage()
91-
);
92+
$this->fail($e->getMessage());
9293
}
9394

9495
parent::setUp();
95-
9696
}
9797

9898
/**
@@ -102,7 +102,8 @@ protected function setUp()
102102
* @dataProvider productDataProvider
103103
* @param ProductInterface[] $products
104104
*/
105-
public function testScheduleMass($products) {
105+
public function testScheduleMass($products)
106+
{
106107
try {
107108
$this->sendBulk($products);
108109
} catch (BulkException $bulkException) {
@@ -112,7 +113,8 @@ public function testScheduleMass($products) {
112113
//assert all products are created
113114
try {
114115
$this->publisherConsumerController->waitForAsynchronousResult(
115-
[$this, 'assertProductExists'], [$this->skus, count($this->skus)]
116+
[$this, 'assertProductExists'],
117+
[$this->skus, count($this->skus)]
116118
);
117119
} catch (PreconditionFailedException $e) {
118120
$this->fail("Not all products were created");
@@ -130,7 +132,7 @@ public function sendBulk($products)
130132
$result = $this->massSchedule->publishMass('async.V1.products.POST', $products);
131133

132134
//assert bulk accepted with no errors
133-
$this->assertFalse($result->getIsErrors());
135+
$this->assertFalse($result->isErrors());
134136

135137
//assert number of products sent to queue
136138
$this->assertCount(count($this->skus), $result->getRequestItems());
@@ -199,15 +201,15 @@ public function testScheduleMassOneEntityFailure($products)
199201
} catch (BulkException $e) {
200202
$this->assertCount(1, $e->getErrors());
201203

202-
203204
$errors = $e->getErrors();
204205
$this->assertInstanceOf(\Magento\Framework\Exception\LocalizedException::class, $errors[0]);
205206

206207
$this->assertEquals("Error processing 1 element of input data", $errors[0]->getMessage());
207208

208209
$reasonException = $errors[0]->getPrevious();
209210

210-
$expectedErrorMessage = "Data item corresponding to \"product\" must be specified in the message with topic " .
211+
$expectedErrorMessage = "Data item corresponding to \"product\" " .
212+
"must be specified in the message with topic " .
211213
"\"async.V1.products.POST\".";
212214
$this->assertEquals(
213215
$expectedErrorMessage,
@@ -216,7 +218,7 @@ public function testScheduleMassOneEntityFailure($products)
216218

217219
/** @var \Magento\WebapiAsync\Model\AsyncResponse $bulkStatus */
218220
$bulkStatus = $e->getData();
219-
$this->assertTrue($bulkStatus->getIsErrors());
221+
$this->assertTrue($bulkStatus->isErrors());
220222

221223
/** @var ItemStatus[] $items */
222224
$items = $bulkStatus->getRequestItems();
@@ -233,7 +235,8 @@ public function testScheduleMassOneEntityFailure($products)
233235
//assert one products is created
234236
try {
235237
$this->publisherConsumerController->waitForAsynchronousResult(
236-
[$this, 'assertProductExists'], [$this->skus, count($this->skus)]
238+
[$this, 'assertProductExists'],
239+
[$this->skus, count($this->skus)]
237240
);
238241
} catch (PreconditionFailedException $e) {
239242
$this->fail("Not all products were created");

dev/tests/integration/testsuite/Magento/Framework/MessageQueue/UseCase/QueueTestCaseAbstract.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@ protected function waitForAsynchronousResult($expectedLinesCount, $logFilePath)
9393
}
9494
}
9595

96-
public function checkLogsExists($expectedLinesCount) {
96+
public function checkLogsExists($expectedLinesCount)
97+
{
9798
$actualCount = file_exists($this->logFilePath) ? count(file($this->logFilePath)) : 0;
9899
return $expectedLinesCount === $actualCount;
99100
}

0 commit comments

Comments
 (0)