|
@@ 81-93 (lines=13) @@
|
| 78 |
|
* @covers VDB\Spider\Downloader\Downloader::getRequestHandler() |
| 79 |
|
* @covers VDB\Spider\Downloader\Downloader::setRequestHandler() |
| 80 |
|
*/ |
| 81 |
|
public function testDownloadFailed() |
| 82 |
|
{ |
| 83 |
|
$requestHandler = $this->getMock('VDB\Spider\RequestHandler\RequestHandlerInterface'); |
| 84 |
|
$requestHandler |
| 85 |
|
->expects($this->any()) |
| 86 |
|
->method('request') |
| 87 |
|
->will($this->throwException(new \Exception)); |
| 88 |
|
$this->downloader->setRequestHandler($requestHandler); |
| 89 |
|
|
| 90 |
|
$resource = $this->downloader->download(new DiscoveredUri(new Uri('http://foobar.org'))); |
| 91 |
|
|
| 92 |
|
$this->assertFalse($resource); |
| 93 |
|
} |
| 94 |
|
|
| 95 |
|
/** |
| 96 |
|
* @covers VDB\Spider\Downloader\Downloader::download() |
|
@@ 103-115 (lines=13) @@
|
| 100 |
|
* @covers VDB\Spider\Downloader\Downloader::fetchResource() |
| 101 |
|
* @covers VDB\Spider\Downloader\Downloader::addPostFetchFilter() |
| 102 |
|
*/ |
| 103 |
|
public function testFilterNotMatches() |
| 104 |
|
{ |
| 105 |
|
$filterNeverMatch = $this->getMock('VDB\Spider\Filter\PostFetchFilterInterface'); |
| 106 |
|
$filterNeverMatch |
| 107 |
|
->expects($this->any()) |
| 108 |
|
->method('match') |
| 109 |
|
->will($this->returnValue(false)); |
| 110 |
|
$this->downloader->addPostFetchFilter($filterNeverMatch); |
| 111 |
|
|
| 112 |
|
$resource = $this->downloader->download(new DiscoveredUri(new Uri('http://foobar.org'))); |
| 113 |
|
|
| 114 |
|
$this->assertInstanceOf('VDB\\Spider\\Resource', $resource); |
| 115 |
|
} |
| 116 |
|
|
| 117 |
|
/** |
| 118 |
|
* @covers VDB\Spider\Downloader\Downloader::download() |
|
@@ 125-137 (lines=13) @@
|
| 122 |
|
* @covers VDB\Spider\Downloader\Downloader::fetchResource() |
| 123 |
|
* @covers VDB\Spider\Downloader\Downloader::addPostFetchFilter() |
| 124 |
|
*/ |
| 125 |
|
public function testFilterMatches() |
| 126 |
|
{ |
| 127 |
|
$filterAlwaysMatch = $this->getMock('VDB\Spider\Filter\PostFetchFilterInterface'); |
| 128 |
|
$filterAlwaysMatch |
| 129 |
|
->expects($this->any()) |
| 130 |
|
->method('match') |
| 131 |
|
->will($this->returnValue(true)); |
| 132 |
|
$this->downloader->addPostFetchFilter($filterAlwaysMatch); |
| 133 |
|
|
| 134 |
|
$resource = $this->downloader->download(new DiscoveredUri(new Uri('http://foobar.org'))); |
| 135 |
|
|
| 136 |
|
$this->assertFalse($resource); |
| 137 |
|
} |
| 138 |
|
} |
| 139 |
|
|