function it_massively_insert_new_products_and_update_existing_products($documentManager, $collection, $normalizer, $mongoFactory, $pendingPersister, $eventDispatcher, ProductInterface $product1, ProductInterface $product2, ProductInterface $product3, ProductInterface $product4)
 {
     $mongoFactory->createMongoId()->willReturn('my_mongo_id');
     $product1->getId()->willReturn("my_product_1");
     $product2->getId()->willReturn(null);
     $product3->getId()->willReturn("my_product_3");
     $product4->getId()->willReturn(null);
     $product1->setId(Argument::any())->shouldNotBeCalled();
     $product2->setId('my_mongo_id')->shouldBeCalled();
     $product3->setId(Argument::any())->shouldNotBeCalled();
     $product4->setId('my_mongo_id')->shouldBeCalled();
     $normalizer->normalize($product1, 'mongodb_document', ['collection_name' => 'pim_product_collection'])->willReturn(['_id' => 'my_product_1', 'normalized_product_1']);
     $normalizer->normalize($product2, 'mongodb_document', ['collection_name' => 'pim_product_collection'])->willReturn(['_id' => 'my_mongo_id', 'normalized_product_2']);
     $normalizer->normalize($product3, 'mongodb_document', ['collection_name' => 'pim_product_collection'])->willReturn(['_id' => 'my_product_3', 'normalized_product_3']);
     $normalizer->normalize($product4, 'mongodb_document', ['collection_name' => 'pim_product_collection'])->willReturn(['_id' => 'my_mongo_id', 'normalized_product_4']);
     $collection->batchInsert([['_id' => 'my_mongo_id', 'normalized_product_2'], ['_id' => 'my_mongo_id', 'normalized_product_4']])->shouldBeCalled();
     $collection->update(['_id' => 'my_product_1'], ['_id' => 'my_product_1', 'normalized_product_1'])->shouldBeCalled();
     $collection->update(['_id' => 'my_product_3'], ['_id' => 'my_product_3', 'normalized_product_3'])->shouldBeCalled();
     $pendingPersister->persistPendingVersions([$product1, $product2, $product3, $product4])->shouldBeCalled();
     $eventDispatcher->dispatch('pim_base_connector.direct_to_db_writer.pre_insert', Argument::any())->shouldBeCalled();
     $eventDispatcher->dispatch('pim_base_connector.direct_to_db_writer.pre_update', Argument::any())->shouldBeCalled();
     $eventDispatcher->dispatch('pim_base_connector.direct_to_db_writer.post_insert', Argument::any())->shouldBeCalled();
     $eventDispatcher->dispatch('pim_base_connector.direct_to_db_writer.post_update', Argument::any())->shouldBeCalled();
     $documentManager->clear()->shouldBeCalled();
     $this->write([$product1, $product2, $product3, $product4]);
 }
Ejemplo n.º 2
0
 function it_inserts_or_updates_several_products($versionSaver, $normalizer, $collection, ProductInterface $productA, ProductInterface $productB, ProductInterface $productC, ProductInterface $productD)
 {
     $products = [$productA, $productB, $productC, $productD];
     $productA->getId()->willReturn('id_a');
     $productB->getId()->willReturn('id_b');
     $productC->getId()->willReturn(null);
     $productD->getId()->willReturn(null);
     $productA->setId(Argument::any())->shouldNotBeCalled();
     $productB->setId(Argument::any())->shouldNotBeCalled();
     $productC->setId(Argument::any())->shouldBeCalled();
     $productD->setId(Argument::any())->shouldBeCalled();
     $normalizer->normalize($productA, Argument::cetera())->willReturn(['_id' => 'id_a', 'key_a' => 'data_a']);
     $normalizer->normalize($productB, Argument::cetera())->willReturn(['_id' => 'id_b', 'key_b' => 'data_b']);
     $normalizer->normalize($productC, Argument::cetera())->willReturn(['_id' => 'id_c', 'key_c' => 'data_c']);
     $normalizer->normalize($productD, Argument::cetera())->willReturn(['_id' => 'id_d', 'key_d' => 'data_d']);
     $collection->batchInsert([['_id' => 'id_c', 'key_c' => 'data_c'], ['_id' => 'id_d', 'key_d' => 'data_d']])->shouldBeCalled();
     $collection->update(['_id' => 'id_a'], ['_id' => 'id_a', 'key_a' => 'data_a'])->shouldBeCalled();
     $collection->update(['_id' => 'id_b'], ['_id' => 'id_b', 'key_b' => 'data_b'])->shouldBeCalled();
     $versionSaver->saveAll(Argument::any())->shouldBeCalled();
     $this->saveAll($products);
 }