public function testScrapeItemModificationFailure() { $this->crawler->expects($this->once())->method('getNextUrls')->will($this->returnValue([])); $this->parser->expects($this->once())->method('parse')->will($this->throwException(new ModificationException())); $this->dispatcher->expects($this->once())->method('dispatch')->with(ScraperEvents::ITEM_FAILED, $this->isInstanceOf(FailedItemEvent::class)); $this->scraper->scrape(new ScraperEntity(), 'http://example.org'); }
/** * @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())); } }