Completed
Push — 2.0-dev ( 1c6990...5642d2 )
by Takehiro
09:57
created

OptionParserTest::testReadme2()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 23
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 23
rs 9.0856
cc 1
eloc 11
nc 1
nop 0
1
<?php
2
namespace Kwkm\MkLiveStatusClient\Tests;
3
4
use Kwkm\MkLiveStatusClient\LqlBuilder;
5
use Kwkm\MkLiveStatusClient\Table;
6
7
require_once __DIR__ . '/../../bootstrap.php';
8
9
class OptionParserTest extends \PHPUnit_Framework_TestCase
10
{
11
12
    public function testReadme1()
13
    {
14
        $lql = <<<EOF
15
GET contacts
16
OutputFormat: json
17
ResponseHeader: fixed16
18
19
20
EOF;
21
22
        $mock = \TestMock::on(
23
            new LqlBuilder(Table::CONTACTS)
24
        );
25
26
        $this->assertEquals(
27
            $lql,
28
            $mock->build(),
29
            'Retrieve all contacts.'
30
        );
31
    }
32
33
34
    public function testReadme2()
35
    {
36
        $lql = <<<EOF
37
GET contacts
38
Columns: name alias
39
ColumnHeaders: on
40
OutputFormat: json
41
ResponseHeader: fixed16
42
43
44
EOF;
45
46
        $mock = \TestMock::on(
47
            new LqlBuilder(Table::CONTACTS)
48
        );
49
        $mock->columns(array('name', 'alias'));
50
51
        $this->assertEquals(
52
            $lql,
53
            $mock->build(),
54
            'Retrieves just the columns name and alias.'
55
        );
56
    }
57
58
    public function testReadme3()
59
    {
60
        $lql = <<<EOF
61
GET services
62
Columns: host_name description state
63
ColumnHeaders: on
64
Filter: state = 2
65
OutputFormat: json
66
ResponseHeader: fixed16
67
68
69
EOF;
70
71
        $mock = \TestMock::on(
72
            new LqlBuilder(Table::SERVICES)
73
        );
74
        $mock->columns(array('host_name', 'description', 'state'))
75
            ->filterEqual('state', '2');
76
77
        $this->assertEquals(
78
            $lql,
79
            $mock->build(),
80
            'Gets all services with the current state 2 (critical).'
81
        );
82
    }
83
84
    public function testReadme4()
85
    {
86
        $lql = <<<EOF
87
GET services
88
Columns: host_name description state
89
ColumnHeaders: on
90
Filter: state = 2
91
Filter: in_notification_period = 1
92
OutputFormat: json
93
ResponseHeader: fixed16
94
95
96
EOF;
97
98
        $mock = \TestMock::on(
99
            new LqlBuilder(Table::SERVICES)
100
        );
101
        $mock->columns(array('host_name', 'description', 'state'))
102
            ->filterEqual('state', '2')
103
            ->filterEqual('in_notification_period', '1');
104
105
        $this->assertEquals(
106
            $lql,
107
            $mock->build(),
108
            'Gets all critical services which are currently within their notification period.'
109
        );
110
    }
111
}
112