Completed
Pull Request — master (#27)
by Matthijs
02:20
created

ResourceTest::testGetCrawler()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
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 View Code Duplication
    protected function setUp()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
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::getCrawler
34
     */
35
    public function testGetCrawler()
36
    {
37
        $this->assertInstanceOf('Symfony\\Component\\DomCrawler\\Crawler', $this->resource->getCrawler());
38
    }
39
40
    /**
41
     * @covers VDB\Spider\Resource::getUri
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::getResponse
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::__sleep
60
     * @covers VDB\Spider\Resource::__wakeup
61
     */
62
    public function testSerialization()
63
    {
64
        $serialized = serialize($this->resource);
65
        $unserialized = unserialize($serialized);
66
67
        $this->assertInstanceOf('VDB\\Spider\\Resource', $unserialized);
68
        $this->assertInstanceOf('Psr\\Http\\Message\\ResponseInterface', $unserialized->getResponse());
69
        $this->assertInstanceOf('VDB\\Spider\\Uri\\DiscoveredUri', $unserialized->getUri());
70
        $this->assertEquals($this->resource->getUri()->__toString(), $unserialized->getUri()->__toString());
71
        $this->assertEquals($this->html, $unserialized->getResponse()->getBody()->__toString());
72
        $this->assertEquals($this->resource->getCrawler()->html(), $unserialized->getCrawler()->html());
73
    }
74
}
75