Пример #1
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     if (is_string($this->argument('url'))) {
         $url = $this->argument('url');
         $crawlCommand = new CrawlerUrl($this->client, $this->crawler);
         $crawlCommand->setBaseUrl($url);
         $crawlCommand->start();
     }
 }
Пример #2
0
 /**
  * Test continue if expected url
  *
  * @return void
  */
 public function testCrawler()
 {
     $html = '<a href="http:example.com"></a>';
     $client = $this->getMockClient();
     $domCrawler = $this->getMockDomCrawler()->makePartial();
     $response = Mockery::mock('GuzzleHttp\\Psr7\\Response')->makePartial();
     $client->shouldReceive('get')->andReturn($response);
     $response->shouldReceive('getHeaderLine')->andReturn('http://example.com', 'http://example.com/test', 'http://example.com/baz');
     $response->shouldReceive('getStatusCode')->andReturn(200);
     $domCrawler->shouldReceive('addHtmlContent')->andReturn($html);
     $crawling = new CrawlerUrl($client, $domCrawler);
     $crawling->setBaseUrl('http://example.com');
     $crawling->start();
     $this->assertEquals([], $crawling->getSiteUrl());
     $this->assertEquals([], $crawling->getUnvisitedUrl());
 }