protected function executeDiscoverer(DiscovererInterface $discoverer) { $uris = $discoverer->discover($this->spiderResource); $uri = $uris[0]; $this->assertInstanceOf('VDB\\Spider\\Uri\\DiscoveredUri', $uri); $this->assertEquals($this->uri->toString(), $uri->toString()); }
/** * Sets up the fixture, for example, opens a network connection. * This method is called before a test is executed. * * Setting up the following structure: * * 0: A * /|\ * 1: B C E * /| | | * 2: D F G | * | _ | * * Note: E links to F. */ protected function setUp() { $this->spider = new Spider('http://php-spider.org/A'); $this->requestHandler = $this->getMock('VDB\\Spider\\RequestHandler\\RequestHandlerInterface'); $this->hrefA = 'http://php-spider.org/A'; $this->hrefB = 'http://php-spider.org/B'; $this->hrefC = 'http://php-spider.org/C'; $this->hrefD = 'http://php-spider.org/D'; $this->hrefE = 'http://php-spider.org/E'; $this->hrefF = 'http://php-spider.org/F'; $this->hrefG = 'http://php-spider.org/G'; $this->linkA = new DiscoveredUri(new Uri($this->hrefA)); $this->linkB = new DiscoveredUri(new Uri($this->hrefB)); $this->linkC = new DiscoveredUri(new Uri($this->hrefC)); $this->linkD = new DiscoveredUri(new Uri($this->hrefD)); $this->linkE = new DiscoveredUri(new Uri($this->hrefE)); $this->linkF = new DiscoveredUri(new Uri($this->hrefF)); $this->linkG = new DiscoveredUri(new Uri($this->hrefG)); $this->linkA->setDepthFound(0); $this->linkB->setDepthFound(1); $this->linkC->setDepthFound(1); $this->linkD->setDepthFound(2); $this->linkE->setDepthFound(1); $this->linkF->setDepthFound(2); $this->linkG->setDepthFound(2); $htmlA = file_get_contents(__DIR__ . '/Fixtures/SpiderTestHTMLResourceA.html'); $this->responseA = new Response(200, [], $htmlA); $htmlB = file_get_contents(__DIR__ . '/Fixtures/SpiderTestHTMLResourceB.html'); $this->responseB = new Response(200, [], $htmlB); $htmlC = file_get_contents(__DIR__ . '/Fixtures/SpiderTestHTMLResourceC.html'); $this->responseC = new Response(200, [], $htmlC); $htmlD = file_get_contents(__DIR__ . '/Fixtures/SpiderTestHTMLResourceD.html'); $this->responseD = new Response(200, [], $htmlD); $htmlE = file_get_contents(__DIR__ . '/Fixtures/SpiderTestHTMLResourceE.html'); $this->responseE = new Response(200, [], $htmlE); $htmlF = file_get_contents(__DIR__ . '/Fixtures/SpiderTestHTMLResourceF.html'); $this->responseF = new Response(200, [], $htmlF); $htmlG = file_get_contents(__DIR__ . '/Fixtures/SpiderTestHTMLResourceG.html'); $this->responseG = new Response(200, [], $htmlG); $this->linkToResponseMap[$this->linkA->toString()] = $this->responseA; $this->linkToResponseMap[$this->linkB->toString()] = $this->responseB; $this->linkToResponseMap[$this->linkC->toString()] = $this->responseC; $this->linkToResponseMap[$this->linkD->toString()] = $this->responseD; $this->linkToResponseMap[$this->linkE->toString()] = $this->responseE; $this->linkToResponseMap[$this->linkF->toString()] = $this->responseF; $this->linkToResponseMap[$this->linkG->toString()] = $this->responseG; $this->requestHandler->expects($this->any())->method('request')->will($this->returnCallback(array($this, 'doTestRequest'))); $this->spider->getDownloader()->setRequestHandler($this->requestHandler); $this->spider->getDiscovererSet()->set(new XPathExpressionDiscoverer('//a')); $this->statsHandler = new StatsHandler(); $this->spider->getDispatcher()->addSubscriber($this->statsHandler); $this->spider->getQueueManager()->getDispatcher()->addSubscriber($this->statsHandler); $this->spider->getDownloader()->getDispatcher()->addSubscriber($this->statsHandler); $this->logHandler = new LogHandler(); $this->spider->getDispatcher()->addSubscriber($this->logHandler); $this->spider->getQueueManager()->getDispatcher()->addSubscriber($this->logHandler); $this->spider->getDownloader()->getDispatcher()->addSubscriber($this->logHandler); }
/** * @param DiscoveredUri $uri * @return Resource */ public function request(DiscoveredUri $uri) { $response = $this->getClient()->get($uri->toString()); return new Resource($uri, $response); }