ResourceTest   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 20
dl 0
loc 61
rs 10
c 0
b 0
f 0
wmc 5

5 Methods

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