DataTablesResponseTest   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 101
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
eloc 32
dl 0
loc 101
c 1
b 0
f 0
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A testSetRecordTotal() 0 6 1
A test__construct() 0 11 1
A testAddRow() 0 8 1
A testSetRecordFiltered() 0 6 1
A testSetError() 0 6 1
A testSetRow() 0 9 1
A testJsonSerialize() 0 6 1
1
<?php
2
3
/*
4
 * This file is part of the jquery-datatables-bundle package.
5
 *
6
 * (c) 2018 WEBEWEB
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace WBW\Bundle\JQuery\DataTablesBundle\Tests\Model;
13
14
use WBW\Bundle\JQuery\DataTablesBundle\Model\DataTablesResponse;
15
use WBW\Bundle\JQuery\DataTablesBundle\Tests\AbstractTestCase;
16
17
/**
18
 * DataTables response test.
19
 *
20
 * @author webeweb <https://github.com/webeweb>
21
 * @package WBW\Bundle\JQuery\DataTablesBundle\Tests\Model
22
 */
23
class DataTablesResponseTest extends AbstractTestCase {
24
25
    /**
26
     * Test addRow()
27
     *
28
     * @return void
29
     */
30
    public function testAddRow(): void {
31
32
        $obj = new DataTablesResponse();
33
        $obj->setWrapper($this->dtWrapper);
34
35
        $this->assertCount(0, $obj->getData());
36
        $this->assertSame($obj, $obj->addRow());
37
        $this->assertCount(1, $obj->getData());
38
    }
39
40
    /**
41
     * Test jsonSerialize()
42
     *
43
     * @return void
44
     */
45
    public function testJsonSerialize(): void {
46
47
        $obj = new DataTablesResponse();
48
49
        $res = ["data" => [], "draw" => null, "recordsFiltered" => null, "recordsTotal" => null];
50
        $this->assertEquals($res, $obj->jsonSerialize());
51
    }
52
53
    /**
54
     * Test setError()
55
     *
56
     * @return void
57
     */
58
    public function testSetError(): void {
59
60
        $obj = new DataTablesResponse();
61
62
        $obj->setError("error");
63
        $this->assertEquals("error", $obj->getError());
64
    }
65
66
    /**
67
     * Test setRecordFiltered()
68
     *
69
     * @return void
70
     */
71
    public function testSetRecordFiltered(): void {
72
73
        $obj = new DataTablesResponse();
74
75
        $obj->setRecordsFiltered(1);
76
        $this->assertEquals(1, $obj->getRecordsFiltered());
77
    }
78
79
    /**
80
     * Test setRecordTotal()
81
     *
82
     * @return void
83
     */
84
    public function testSetRecordTotal(): void {
85
86
        $obj = new DataTablesResponse();
87
88
        $obj->setRecordsTotal(2);
89
        $this->assertEquals(2, $obj->getRecordsTotal());
90
    }
91
92
    /**
93
     * Test setRow()
94
     *
95
     * @return void
96
     */
97
    public function testSetRow(): void {
98
99
        $obj = new DataTablesResponse();
100
        $obj->setWrapper($this->dtWrapper)->addRow();
101
102
        $obj->setRow("name", "GitHub");
103
        $res = ["name" => "GitHub", "position" => null, "office" => null, "age" => null, "startDate" => null, "salary" => null, "actions" => null];
104
        $this->assertCount(1, $obj->getData());
105
        $this->assertEquals($res, $obj->getData()[0]);
106
    }
107
108
    /**
109
     * Test __construct()
110
     *
111
     * @return void
112
     */
113
    public function test__construct(): void {
114
115
        $obj = new DataTablesResponse();
116
117
        $this->assertEquals([], $obj->getData());
118
        $this->assertEquals(0, $obj->getDraw());
119
        $this->assertNull($obj->getError());
120
        $this->assertEquals(0, $obj->getRecordsFiltered());
121
        $this->assertEquals(0, $obj->getRecordsTotal());
122
        $this->assertNull($obj->getWrapper());
123
        $this->assertEquals(0, $obj->rowsCount());
124
    }
125
}
126