Passed
Push — master ( d151aa...1c6332 )
by Jean Paul
01:43
created

WebPageHandlerTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 24
c 1
b 0
f 0
dl 0
loc 61
rs 10
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testReadWithNoURL() 0 6 1
A testSetGetURL() 0 17 1
A testReadWithBadURL() 0 9 1
A testReadWithGoodURL() 0 9 1
1
<?php declare( strict_types = 1 );
2
3
namespace Coco\SourceWatcher\Tests\Watcher\Handler;
4
5
use Coco\SourceWatcher\Core\SourceWatcherException;
6
use Coco\SourceWatcher\Watcher\Handler\WebPageHandler;
7
use PHPUnit\Framework\TestCase;
8
9
/**
10
 * Class WebPageHandlerTest
11
 * @package Coco\SourceWatcher\Tests\Watcher\Handler
12
 */
13
class WebPageHandlerTest extends TestCase
14
{
15
    /**
16
     *
17
     */
18
    public function testSetGetURL () : void
19
    {
20
        $givenURL = "https://stackoverflow.com/jobs?q=Java&l=Florida+USA&d=100&u=Miles";
21
        $expectedURL = "https://stackoverflow.com/jobs?q=Java&l=Florida+USA&d=100&u=Miles";
22
23
        $webPageHandler = new WebPageHandler( $givenURL );
24
25
        $this->assertNotNull( $webPageHandler->getUrl() );
26
        $this->assertEquals( $expectedURL, $webPageHandler->getUrl() );
27
28
        $givenURL = "https://stackoverflow.com/jobs?q=PHP&l=Florida+USA&d=100&u=Miles";
29
        $expectedURL = "https://stackoverflow.com/jobs?q=PHP&l=Florida+USA&d=100&u=Miles";
30
31
        $webPageHandler->setUrl( $givenURL );
32
33
        $this->assertNotNull( $webPageHandler->getUrl() );
34
        $this->assertEquals( $expectedURL, $webPageHandler->getUrl() );
35
    }
36
37
    /**
38
     * @throws SourceWatcherException
39
     */
40
    public function testReadWithNoURL () : void
41
    {
42
        $this->expectException( SourceWatcherException::class );
43
44
        $webPageHandler = new WebPageHandler( "" );
45
        $webPageHandler->read();
46
    }
47
48
    /**
49
     * @throws SourceWatcherException
50
     */
51
    public function testReadWithBadURL () : void
52
    {
53
        $webPageHandler = new WebPageHandler( "this is not a URL" );
54
        $webPageHandler->read();
55
56
        $this->assertEmpty( $webPageHandler->getHtml() );
57
58
        $this->assertNotEmpty( $webPageHandler->getDom() );
59
        $this->assertEquals( 0, $webPageHandler->getDom()->childNodes->length );
60
    }
61
62
    /**
63
     * @throws SourceWatcherException
64
     */
65
    public function testReadWithGoodURL () : void
66
    {
67
        $webPageHandler = new WebPageHandler( "https://stackoverflow.com/jobs?q=Java&l=Florida+USA&d=100&u=Miles" );
68
        $webPageHandler->read();
69
70
        $this->assertNotEmpty( $webPageHandler->getHtml() );
71
72
        $this->assertNotEmpty( $webPageHandler->getDom() );
73
        $this->assertGreaterThan( 0, $webPageHandler->getDom()->childNodes->length );
74
    }
75
}
76