45 private $massSchedule;
55 private $productRepository;
60 private $publisherConsumerController;
72 protected function setUp()
75 $this->registry = $this->objectManager->get(Registry::class);
76 $this->massSchedule = $this->objectManager->create(MassSchedule::class);
77 $this->logFilePath = TESTS_TEMP_DIR .
"/MessageQueueTestLog.txt";
78 $this->collection = $this->objectManager->create(Collection::class);
79 $this->productRepository = $this->objectManager->create(ProductRepositoryInterface::class);
81 $this->publisherConsumerController = $this->objectManager->create(PublisherConsumerController::class, [
82 'consumers' => $this->consumers,
83 'logFilePath' => $this->logFilePath,
88 $this->publisherConsumerController->initialize();
90 $this->markTestSkipped($e->getMessage());
92 $this->fail($e->getMessage());
107 $this->fail(
'Bulk was not accepted in full');
112 $this->publisherConsumerController->waitForAsynchronousResult(
113 [$this,
'assertProductExists'],
114 [$this->skus, count($this->skus)]
117 $this->fail(
"Not all products were created");
125 if (isset(
$data[
'product'])) {
126 $this->skus[] =
$data[
'product']->getSku();
129 $this->clearProducts();
131 $result = $this->massSchedule->publishMass(
'async.V1.products.POST',
$products);
134 $this->assertFalse(
$result->isErrors());
137 $this->assertCount(count($this->skus),
$result->getRequestItems());
142 $this->publisherConsumerController->stopConsumers();
143 $this->clearProducts();
148 private function clearProducts()
150 $size = $this->objectManager->create(Collection::class)
151 ->addAttributeToFilter(
'sku', [
'in' => $this->skus])
159 $this->registry->unregister(
'isSecureArea');
160 $this->registry->register(
'isSecureArea',
true);
162 foreach ($this->skus as $sku) {
163 $this->productRepository->deleteById($sku);
165 }
catch (\Exception $e) {
168 $this->registry->unregister(
'isSecureArea');
170 $size = $this->objectManager->create(Collection::class)
171 ->addAttributeToFilter(
'sku', [
'in' => $this->skus])
176 throw new Exception(
new Phrase(
"Collection size after clearing the products: %size", [
'size' => $size]));
182 $collection = $this->objectManager->create(Collection::class)
183 ->addAttributeToFilter(
'sku', [
'in' => $productsSkus])
185 $size = $collection->getSize();
193 public function testScheduleMassOneEntityFailure(
$products)
197 }
catch (BulkException $e) {
198 $this->assertCount(1, $e->getErrors());
201 $this->assertInstanceOf(\
Magento\Framework\Exception\LocalizedException::class,
$errors[0]);
203 $this->assertEquals(
"Error processing 1 element of input data",
$errors[0]->getMessage());
205 $reasonException =
$errors[0]->getPrevious();
207 $expectedErrorMessage =
"Data item corresponding to \"product\" " .
208 "must be specified in the message with topic " .
209 "\"async.V1.products.POST\".";
211 $expectedErrorMessage,
212 $reasonException->getMessage()
216 $bulkStatus = $e->getData();
217 $this->assertTrue($bulkStatus->isErrors());
220 $items = $bulkStatus->getRequestItems();
221 $this->assertCount(2,
$items);
224 $this->assertEquals(0,
$items[0]->getId());
227 $this->assertEquals(1,
$items[1]->getId());
228 $this->assertEquals($expectedErrorMessage,
$items[1]->getErrorMessage());
233 $this->publisherConsumerController->waitForAsynchronousResult(
234 [$this,
'assertProductExists'],
235 [$this->skus, count($this->skus)]
237 }
catch (PreconditionFailedException $e) {
238 $this->fail(
"Not all products were created");
242 private function getProduct()
246 ->create(ProductInterface::class);
248 ->setTypeId(
'simple')
249 ->setAttributeSetId(4)
251 ->setName(
'Simple Product 1')
252 ->setSku(
'unique-simple-product1')
254 ->setMetaTitle(
'meta title')
255 ->setMetaKeyword(
'meta keyword')
256 ->setMetaDescription(
'meta description')
257 ->setVisibility(\
Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH)
258 ->setStatus(\
Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED)
259 ->setStockData([
'use_config_manage_stock' => 0]);
266 'single_product' => [
267 [[
'product' => $this->getProduct()]],
269 'multiple_products' => [
271 [
'product' => $this->getProduct()
272 ->setName(
'Simple Product 3')
273 ->setSku(
'unique-simple-product3')
274 ->setMetaTitle(
'meta title 3')
276 [
'product' => $this->getProduct()
277 ->setName(
'Simple Product 2')
278 ->setSku(
'unique-simple-product2')
279 ->setMetaTitle(
'meta title 2')
289 'single_product' => [
290 [[
'product' => $this->getProduct()]],
292 'multiple_products' => [
294 [
'product' => $this->getProduct()],
295 [
'customer' => $this->getProduct()]
productExceptionDataProvider()
assertProductExists($productsSkus, $count)
testScheduleMass($products)
static getObjectManager()