Completed
Pull Request — master (#16)
by Matthijs
04:40
created

ResourceTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 5
Bugs 0 Features 1
Metric Value
wmc 6
c 5
b 0
f 1
lcom 1
cbo 5
dl 0
loc 61
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 8 1
A testGetCrawler() 0 4 1
A testGetResponse() 0 4 1
A testSetFiltered() 0 6 1
A testGetIdentifier() 0 4 1
A testGetUri() 0 5 1
1
<?php
2
namespace VDB\Spider\Tests;
3
4
use Guzzle\Http\Message\Response;
5
use VDB\Spider\Resource;
6
use VDB\Uri\Uri;
7
8
/**
9
 */
10
class ResourceTest extends TestCase
11
{
12
    /**
13
     * @var Resource
14
     */
15
    protected $resource;
16
17
    protected function setUp()
18
    {
19
        $html = file_get_contents(__DIR__ . '/Fixtures/ResourceTestHTMLResource.html');
20
        $this->resource = new Resource(
21
            new Uri('/domains/special', 'http://example.org'),
22
            new Response(200, null, $html)
23
        );
24
    }
25
26
    /**
27
     * @covers VDB\Spider\Resource::getCrawler
28
     */
29
    public function testGetCrawler()
30
    {
31
        $this->assertInstanceOf('Symfony\\Component\\DomCrawler\\Crawler', $this->resource->getCrawler());
32
    }
33
34
    /**
35
     * @covers VDB\Spider\Resource::getUri
36
     */
37
    public function testGetUri()
38
    {
39
        $this->assertInstanceOf('VDB\\URI\Uri', $this->resource->getUri());
40
        $this->assertEquals('http://example.org/domains/special', $this->resource->getUri()->toString());
41
    }
42
43
    /**
44
     * @covers VDB\Spider\Resource::getResponse
45
     */
46
    public function testGetResponse()
47
    {
48
        $this->assertInstanceOf('Guzzle\\Http\\Message\\Response', $this->resource->getResponse());
49
    }
50
51
    /**
52
     * @covers VDB\Spider\Resource::setFiltered
53
     * @covers VDB\Spider\Resource::isFiltered
54
     * @covers VDB\Spider\Resource::getFilterReason
55
     */
56
    public function testSetFiltered()
57
    {
58
        $this->resource->setFiltered(true, 'goodReason');
59
        $this->assertTrue($this->resource->isFiltered());
60
        $this->assertEquals('goodReason', $this->resource->getFilterReason());
61
    }
62
63
    /**
64
     * @covers VDB\Spider\Resource::getIdentifier
65
     */
66
    public function testGetIdentifier()
67
    {
68
        $this->assertEquals('http://example.org/domains/special', $this->resource->getIdentifier());
69
    }
70
}
71