Completed
Push — master ( 22d3fd...d7530b )
by Risan Bagja
02:43
created

nik_page_parser_can_parse_result_page()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 28
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 28
rs 8.8571
cc 1
eloc 16
nc 1
nop 0
1
<?php
2
3
use Ktp\Parsers\NikResultPageParser;
4
use Psr\Http\Message\ResponseInterface;
5
use Symfony\Component\DomCrawler\Crawler;
6
7
class NikResultPageParserTest extends PHPUnit_Framework_TestCase {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
8
    /** @test */
9
    function nik_page_parser_can_retrieve_page_content()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
10
    {
11
        $pageParser = $this->getMockForAbstractClass(NikResultPageParser::class, ['foo']);
12
13
        $this->assertEquals('foo', $pageParser->page());
14
    }
15
16
    /** @test */
17
    function nik_page_parser_can_instantiate_crawler()
18
    {
19
        $pageParser = $this->getMockForAbstractClass(NikResultPageParser::class, ['foo']);
20
21
        $this->assertInstanceOf(Crawler::class, $pageParser->crawler());
22
    }
23
24
    /** @test */
25
    function nik_page_parser_can_be_instantiated_from_response()
26
    {
27
        $response = $this->getMockForAbstractClass(ResponseInterface::class);
28
29
        $response->expects($this->once())
30
            ->method('getBody')
31
            ->will($this->returnValue('foo'));
32
33
        $this->assertInstanceOf(NikResultPageParser::class, NikResultPageParser::fromResponse($response));
34
    }
35
36
    /** @test */
37
    function nik_page_parser_parse_should_return_null_when_nik_is_not_found()
38
    {
39
        $pageParser = $this->getMockForAbstractClass(NikResultPageParser::class, ['foo']);
40
41
        $this->assertNull($pageParser->parse());
42
    }
43
44
    /** @test */
45
    function nik_page_parser_can_parse_result_page()
46
    {
47
        $html = <<<EOD
48
<span class="field">123</span>
49
<span class="field">JOHN DOE</span>
50
<span class="field">LAKI-LAKI</span>
51
<span class="field">FOO</span>
52
<span class="field">BAR</span>
53
<span class="field">BAZ</span>
54
<span class="field">QUX</span>
55
EOD;
56
57
        $pageParser = $this->getMockForAbstractClass(NikResultPageParser::class, [$html]);
58
59
        $parsed = $pageParser->parse();
60
61
        $this->assertCount(7, $parsed);
62
63
        $this->assertEquals([
64
            'nik' => 123,
65
            'name' => 'JOHN DOE',
66
            'jenis_kelamin' => 'LAKI-LAKI',
67
            'kelurahan' => 'FOO',
68
            'kecamatan' => 'BAR',
69
            'kabupaten_kota' => 'BAZ',
70
            'provinsi' => 'QUX',
71
        ], $parsed);
72
    }
73
}
74