1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Spider package. |
5
|
|
|
* |
6
|
|
|
* (c) Matthijs van den Bos <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace VDB\Spider\Tests\Discoverer; |
13
|
|
|
|
14
|
|
|
use VDB\Spider\Discoverer\XPathExpressionDiscoverer; |
15
|
|
|
use VDB\Spider\Discoverer\DiscovererSet; |
16
|
|
|
use VDB\Spider\Filter\Prefetch\UriFilter; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* |
20
|
|
|
*/ |
21
|
|
|
class DiscovererSetTest extends DiscovererTestCase |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* @var DiscovererSet |
25
|
|
|
*/ |
26
|
|
|
private $discovererSet; |
27
|
|
|
|
28
|
|
|
|
29
|
|
|
public function setUp() |
30
|
|
|
{ |
31
|
|
|
parent::setUp(); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @covers VDB\Spider\Discoverer\DiscovererSet |
36
|
|
|
*/ |
37
|
|
|
public function testConstructor() |
|
|
|
|
38
|
|
|
{ |
39
|
|
|
$this->discovererSet = new DiscovererSet([new XPathExpressionDiscoverer("//a")]); |
40
|
|
|
|
41
|
|
|
$uris = $this->discovererSet->discover($this->spiderResource); |
42
|
|
|
$this->assertCount(1, $uris); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @covers VDB\Spider\Discoverer\DiscovererSet |
47
|
|
|
*/ |
48
|
|
|
public function testSetDiscoverer() |
|
|
|
|
49
|
|
|
{ |
50
|
|
|
$this->discovererSet = new DiscovererSet(); |
51
|
|
|
$this->discovererSet->set(new XPathExpressionDiscoverer("//a")); |
52
|
|
|
|
53
|
|
|
$uris = $this->discovererSet->discover($this->spiderResource); |
54
|
|
|
$this->assertCount(1, $uris); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @covers VDB\Spider\Discoverer\DiscovererSet |
59
|
|
|
*/ |
60
|
|
|
public function testFilter() |
|
|
|
|
61
|
|
|
{ |
62
|
|
|
$this->discovererSet = new DiscovererSet([new XPathExpressionDiscoverer("//a")]); |
63
|
|
|
|
64
|
|
|
$this->discovererSet->addFilter(new UriFilter(['/^.*contact.*$/'])); |
65
|
|
|
|
66
|
|
|
$uris = $this->discovererSet->discover($this->spiderResource); |
67
|
|
|
$this->assertCount(0, $uris); |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.