7 declare(strict_types=1);
58 private $publisherConsumerController;
63 private $productRepository;
68 private $objectManager;
75 protected function setUp()
78 $this->logFilePath = TESTS_TEMP_DIR .
"/MessageQueueTestLog.txt";
79 $this->registry = $this->objectManager->get(Registry::class);
81 $params = array_merge_recursive(
83 [
'MAGE_DIRS' => [
'cache' => [
'path' => TESTS_TEMP_DIR .
'/cache']]]
87 $this->publisherConsumerController = $this->objectManager->create(PublisherConsumerController::class, [
88 'consumers' => $this->consumers,
89 'logFilePath' => $this->logFilePath,
92 $this->productRepository = $this->objectManager->create(ProductRepositoryInterface::class);
95 $this->publisherConsumerController->initialize();
97 $this->markTestSkipped($e->getMessage());
114 $this->clearProducts();
117 $this->assertArrayHasKey(self::BULK_UUID_KEY,
$response);
118 $this->assertNotNull(
$response[self::BULK_UUID_KEY]);
120 $this->assertCount(1,
$response[
'request_items']);
121 $this->assertEquals(
'accepted',
$response[
'request_items'][0][
'status']);
126 $this->publisherConsumerController->waitForAsynchronousResult(
127 [$this,
'assertProductCreation'],
131 $this->fail(
"Not all products were created");
137 $this->clearProducts();
138 $this->publisherConsumerController->stopConsumers();
142 private function clearProducts()
144 $size = $this->objectManager->create(Collection::class)
145 ->addAttributeToFilter(
'sku', [
'in' => $this->skus])
153 $this->registry->unregister(
'isSecureArea');
154 $this->registry->register(
'isSecureArea',
true);
156 foreach ($this->skus as $sku) {
157 $this->productRepository->deleteById($sku);
159 }
catch (\Exception $e) {
163 $this->registry->unregister(
'isSecureArea');
165 $size = $this->objectManager->create(Collection::class)
166 ->addAttributeToFilter(
'sku', [
'in' => $this->skus])
171 throw new Exception(
new Phrase(
"Collection size after clearing the products: %size", [
'size' => $size]));
187 'resourcePath' => self::ASYNC_RESOURCE_PATH .
'/' . $sku,
196 $this->assertEquals(400, $e->getCode());
206 $productBuilder =
function (
$data) {
207 return array_replace_recursive(
208 $this->getSimpleProductData(),
225 'product' => $productBuilder([
240 [
'psku-test-1',
null],
250 private function getSimpleProductData(
$productData = [])
263 'custom_attributes' => [
264 [
'attribute_code' =>
'cost',
'value' =>
''],
265 [
'attribute_code' =>
'description',
'value' =>
'Description'],
289 $collection = $this->objectManager->create(Collection::class)
290 ->addAttributeToFilter(
'sku', [
'in' => $this->skus])
294 return $size == count($this->skus);
_markTestAsRestOnly($message=null)
_webApiCall( $serviceInfo, $arguments=[], $webApiAdapterCode=null, $storeCode=null, $integration=null)
testAsyncScheduleBulk($product)
const ASYNC_CONSUMER_NAME
productCreationProvider()
testGETRequestToAsync($sku, $storeCode=null)
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
const ASYNC_RESOURCE_PATH
static getObjectManager()