Пример #1
0
 /**
  * {@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->getConfiguredChannel();
         if (null !== $channel) {
             $this->metricConverter->convert($product, $channel);
         }
     }
     return $product;
 }
 /**
  * {@inheritdoc}
  */
 public function read()
 {
     $configuration = $this->getJobConfiguration();
     if (null === $configuration) {
         return null;
     }
     if (!$this->isExecuted) {
         $this->isExecuted = true;
         $this->products = $this->getProductsCursor($configuration['filters']);
     }
     $result = $this->products->current();
     if (!empty($result)) {
         $this->stepExecution->incrementSummaryInfo('read');
         $this->products->next();
     } else {
         $result = null;
     }
     return $result;
 }
 function it_iterate_by_page_over_cursor(CursorInterface $cursor)
 {
     $page1 = [new Entity(1), new Entity(2), new Entity(3), new Entity(4), new Entity(5), new Entity(6), new Entity(7), new Entity(8), new Entity(9), new Entity(10)];
     $page2 = [new Entity(11), new Entity(12), new Entity(13)];
     $data = array_merge($page1, $page2);
     $cursor->count()->shouldBeCalled()->willReturn(13);
     $cursor->next()->shouldBeCalled()->will(function () use($cursor, &$data) {
         $item = array_shift($data);
         if ($item === null) {
             $item = false;
         }
         $cursor->current()->willReturn($item);
     });
     $cursor->rewind()->shouldBeCalled()->will(function () use($cursor, &$data, $page1, $page2) {
         $data = array_merge($page1, $page2);
         $item = array_shift($data);
         if ($item === null) {
             $item = false;
         }
         $cursor->current()->willReturn($item);
     });
     // for each call sequence
     $this->rewind()->shouldReturn(null);
     $this->valid()->shouldReturn(true);
     $this->current()->shouldReturn($page1);
     $this->key()->shouldReturn(0);
     $this->next()->shouldReturn(null);
     $this->valid()->shouldReturn(true);
     $this->current()->shouldReturn($page2);
     $this->key()->shouldReturn(1);
     $this->next()->shouldReturn(null);
     $this->valid()->shouldReturn(false);
     // check behaviour after the end of data
     $this->current()->shouldReturn(false);
     $this->key()->shouldReturn(null);
     // methods that not iterate can be called twice
     $this->rewind()->shouldReturn(null);
     $this->valid()->shouldReturn(true);
     $this->valid()->shouldReturn(true);
     $this->current()->shouldReturn($page1);
     $this->current()->shouldReturn($page1);
     $this->key()->shouldReturn(0);
     $this->key()->shouldReturn(0);
 }