Completed
Push — master ( 6f4e11...e12aed )
by Matthijs
11:15 queued 07:09
created

ResourceTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 4
Bugs 0 Features 1
Metric Value
c 4
b 0
f 1
dl 0
loc 8
rs 9.4285
cc 1
eloc 5
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
    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
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