public function test_scraper()
 {
     // we want to intercept the product description link request
     // and return the cached version of the page
     // it's not very efficient to hit HTTP request every time we run the tests
     $this->linkScraper->shouldReceive('fetchPageContentFor')->andReturn($this->fetchProductDescriptionPage());
     $html = $this->fetchProductsPage();
     $this->scraper->setHtml($html);
     $this->scraper->process();
     // Check the first item
     $firstItem = $this->scraper->getFirstItem();
     $this->assertEquals('Sainsbury\'s Apple, Strawberry, Grape & Blueberry 240g', $firstItem['title']);
     // We already know the size of cached page
     $this->assertEquals('43.77kb', $firstItem['size']);
     $this->assertEquals(1.75, $firstItem['unit_price']);
     $this->assertStringStartsWith('Apple, Strawberry, Grape & Blueberry', $firstItem['description']);
     // Check the last item
     $lastItem = $this->scraper->getLastItem();
     $this->assertEquals('Sainsbury\'s Watermelon, Mango & Grape 240g', $lastItem['title']);
     $this->assertEquals('43.77kb', $lastItem['size']);
     $this->assertEquals(1.75, $lastItem['unit_price']);
     $this->assertStringStartsWith('Apple, Strawberry, Grape & Blueberry', $lastItem['description']);
     // Check json output
     $this->assertRegExp('/Apple, Strawberry, Grape & Blueberry/', $this->scraper->toPrettyJson());
 }
 /**
  * Fetch page content for the provided link
  *
  * @param $link
  * @return string
  */
 public function fetch($link)
 {
     return $this->linkScraper->fetchPageContentFor($link);
 }