/**
  * {@inheritdoc}
  */
 public function read()
 {
     $this->documentManager->clear();
     if (!$this->executed) {
         $this->executed = true;
         if (!is_object($this->channel)) {
             $this->channel = $this->channelManager->getChannelByCode($this->channel);
         }
         if ($this->missingCompleteness) {
             $this->completenessManager->generateMissingForChannel($this->channel);
         }
         $this->query = $this->repository->buildByChannelAndCompleteness($this->channel)->getQuery();
         $this->products = $this->getQuery()->execute();
         // MongoDB Cursor are not positioned on first element (whereas ArrayIterator is)
         // as long as getNext() hasn't be called
         $this->products->getNext();
     }
     $result = $this->products->current();
     if ($result) {
         $this->metricConverter->convert($result, $this->channel);
         $this->stepExecution->incrementSummaryInfo('read');
         $this->products->next();
     }
     return $result;
 }
 /**
  * @{inheritdoc}
  */
 public function read()
 {
     $product = null;
     if ($this->products->valid()) {
         $product = $this->products->current();
         $this->stepExecution->incrementSummaryInfo('read');
         $this->products->next();
     }
     if (null !== $product) {
         $channel = $this->channelManager->getChannelByCode($this->channel);
         $this->metricConverter->convert($product, $channel);
     }
     return $product;
 }
 function it_throws_an_exception_if_something_went_wrong_during_normalization($webservice, $attributeMappingMerger, $categoryMappingMerger, $productNormalizer, $mappingCollection, Product $product, Channel $channel, Family $family, MetricConverter $metricConverter, AbstractAttribute $skuAttribute, ProductValue $sku)
 {
     $categoryMappingMerger->getMapping()->willReturn($mappingCollection);
     $attributeMappingMerger->getMapping()->willReturn($mappingCollection);
     $product->getFamily()->shouldBeCalled()->willReturn($family);
     $family->getCode()->shouldBeCalled()->willReturn('family_code');
     $webservice->getAttributeSetId('family_code')->shouldBeCalled()->willReturn('4');
     $product->getIdentifier()->shouldBeCalled()->willReturn($sku);
     $sku->getData()->willReturn('sku-000');
     $sku->getAttribute()->willReturn($skuAttribute);
     $skuAttribute->getCode()->willReturn('SKU');
     $product->getId()->willReturn(12);
     $product->getLabel()->willReturn('my product');
     $metricConverter->convert($product, $channel)->shouldBeCalled();
     $productNormalizer->normalize(Argument::type('\\Pim\\Bundle\\CatalogBundle\\Model\\Product'), 'MagentoArray', Argument::type('array'))->shouldBeCalled()->willThrow('\\Pim\\Bundle\\MagentoConnectorBundle\\Normalizer\\Exception\\NormalizeException');
     $this->shouldThrow('\\Akeneo\\Bundle\\BatchBundle\\Item\\InvalidItemException')->duringProcess($product);
 }