Пример #1
0
 public function testScrapeItemSuccess()
 {
     $source = new SourceMock(1234);
     $this->crawler->expects($this->once())->method('getNextUrls')->will($this->returnValue([]));
     $this->handler->expects($this->once())->method('handle')->will($this->returnValue($source));
     $this->dispatcher->expects($this->once())->method('dispatch')->with(ScraperEvents::ITEM_SUCCESS, $this->callback(function (SuccessItemEvent $event) use($source) {
         return $event->getResult() === $source;
     }));
     $this->scraper->scrape(new ScraperEntity(), 'http://example.org');
 }
Пример #2
0
 /**
  * @param ScrapedItemBag $item
  */
 protected function scrapeItem(ScrapedItemBag $item)
 {
     try {
         $this->parser->parse($item);
         $source = $this->handler->handle($item);
         $this->eventDispatcher->dispatch(ScraperEvents::ITEM_SUCCESS, new SuccessItemEvent($this, $item, $source));
     } catch (FilterException $e) {
         $this->eventDispatcher->dispatch(ScraperEvents::ITEM_SKIPPED, new SkippedItemEvent($this, $item, $e->getMessage()));
     } catch (ValidationException $e) {
         $this->eventDispatcher->dispatch(ScraperEvents::ITEM_FAILED, new FailedItemEvent($this, $item, $e->getMessage()));
     } catch (FailedItemException $e) {
         $this->eventDispatcher->dispatch(ScraperEvents::ITEM_FAILED, new FailedItemEvent($this, $item, $e->getMessage()));
     } catch (ModificationException $e) {
         if ($e->getPrevious()) {
             $e = $e->getPrevious();
         }
         $this->eventDispatcher->dispatch(ScraperEvents::ITEM_FAILED, new FailedItemEvent($this, $item, $e->getMessage()));
     }
 }