Completed
Push — master ( b413e0...dee30b )
by Adam
05:20 queued 02:15
created

DatabaseTest   A

Complexity

Total Complexity 19

Size/Duplication

Total Lines 185
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 2

Importance

Changes 10
Bugs 0 Features 0
Metric Value
wmc 19
c 10
b 0
f 0
lcom 2
cbo 2
dl 0
loc 185
rs 10

19 Methods

Rating   Name   Duplication   Size   Complexity  
A setUpBeforeClass() 0 3 1
A tearDownAfterClass() 0 3 1
A testConnect() 0 3 1
A testConnectFailure() 0 3 1
A testQuery() 0 5 1
A testSelect() 0 4 1
A testSelectAll() 0 3 1
A testSelectFailure() 0 3 1
A testInsert() 0 3 1
A tsetInsertFailure() 0 3 1
A testUpdate() 0 3 1
A testUpdateFailure() 0 3 1
A testDelete() 0 3 1
A testDeleteFailure() 0 3 1
A testCount() 0 3 1
A testFulltextIndex() 0 3 1
A testNumRows() 0 3 1
A testLastInsertID() 0 3 1
A testCaching() 0 3 1
1
<?php
2
namespace DBAL\Tests;
3
4
use DBAL\Database;
5
use PHPUnit\Framework\TestCase;
6
7
class DatabaseTest extends TestCase{
8
    
9
    public static $db;
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $db. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
10
    
11
    /**
12
     * @covers DBAL\Database::__construct
13
     * @covers DBAL\Database::connectToServer
14
     */
15
    public static function setUpBeforeClass(){
16
        self::$db = new Database('db4free.net;port=3307', 'example_user_1', 'Password123', 'test_database_1');
17
    }
18
    
19
    /**
20
     * @covers DBAL\Database::__destruct
21
     */
22
    public static function tearDownAfterClass(){
23
        self::$db = null;
24
    }
25
    
26
    /**
27
     * @covers DBAL\Database::__construct
28
     * @covers DBAL\Database::connectToServer
29
     */
30
    public function testConnect(){
31
        $this->assertObjectHasAttribute('db', self::$db);
0 ignored issues
show
Bug introduced by
It seems like self::$db can be null; however, assertObjectHasAttribute() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
32
    }
33
    
34
    /**
35
     * @covers DBAL\Database
36
     */
37
    public function testConnectFailure(){
38
        $this->assertFalse(false);
39
    }
40
    
41
    /**
42
     * @covers DBAL\Database::query
43
     */
44
    public function testQuery(){
45
        $query = self::$db->query("SELECT * FROM `test_table` WHERE `id` = ?", array(1));
46
        $this->assertArrayHasKey('0', $query);
47
        $this->assertCount(1, $query);
48
    }
49
    
50
    /**
51
     * @covers DBAL\Database::select
52
     * @covers DBAL\Database::buildSelectQuery
53
     * @covers DBAL\Database::where
54
     * @covers DBAL\Database::orderBy
55
     * @covers DBAL\Database::limit
56
     * @covers DBAL\Database::executeQuery
57
     */
58
    public function testSelect(){
59
        $simpleSelect = self::$db->select('test_table', array('id' => array('>', 1)), '*', array('id' => 'ASC'));
60
        $this->assertArrayHasKey('name', $simpleSelect);
61
    }
62
    
63
    /**
64
     * @covers DBAL\Database::selectAll
65
     * @covers DBAL\Database::buildSelectQuery
66
     * @covers DBAL\Database::where
67
     * @covers DBAL\Database::orderBy
68
     * @covers DBAL\Database::limit
69
     * @covers DBAL\Database::executeQuery
70
     */
71
    public function testSelectAll(){
72
        $this->assertFalse(false);
73
    }
74
    
75
    /**
76
     * @covers DBAL\Database::select
77
     * @covers DBAL\Database::selectAll
78
     * @covers DBAL\Database::buildSelectQuery
79
     * @covers DBAL\Database::where
80
     * @covers DBAL\Database::orderBy
81
     * @covers DBAL\Database::limit
82
     * @covers DBAL\Database::executeQuery
83
     */
84
    public function testSelectFailure(){
85
        $this->assertFalse(false);
86
    }
87
    
88
    /**
89
     * @covers DBAL\Database::insert
90
     * @covers DBAL\Database::fields
91
     * @covers DBAL\Database::executeQuery
92
     * @covers DBAL\Database::numRows
93
     */
94
    public function testInsert(){
95
        $this->assertFalse(false);
96
    }
97
    
98
    /**
99
     * @covers DBAL\Database::insert
100
     * @covers DBAL\Database::fields
101
     * @covers DBAL\Database::executeQuery
102
     * @covers DBAL\Database::numRows
103
     */
104
    public function tsetInsertFailure(){
105
        $this->assertFalse(false);
106
    }
107
    
108
    /**
109
     * @covers DBAL\Database::update
110
     * @covers DBAL\Database::fields
111
     * @covers DBAL\Database::where
112
     * @covers DBAL\Database::limit
113
     * @covers DBAL\Database::executeQuery
114
     * @covers DBAL\Database::numRows
115
     */
116
    public function testUpdate(){
117
        $this->assertFalse(false);
118
    }
119
    
120
    /**
121
     * @covers DBAL\Database::update
122
     * @covers DBAL\Database::fields
123
     * @covers DBAL\Database::where
124
     * @covers DBAL\Database::limit
125
     * @covers DBAL\Database::executeQuery
126
     * @covers DBAL\Database::numRows
127
     */
128
    public function testUpdateFailure(){
129
        $this->assertFalse(false);
130
    }
131
    
132
    /**
133
     * @covers DBAL\Database::delete
134
     * @covers DBAL\Database::where
135
     * @covers DBAL\Database::limit
136
     * @covers DBAL\Database::executeQuery
137
     * @covers DBAL\Database::numRows
138
     */
139
    public function testDelete(){
140
        $this->assertFalse(false);
141
    }
142
    
143
    /**
144
     * @covers DBAL\Database::delete
145
     * @covers DBAL\Database::where
146
     * @covers DBAL\Database::limit
147
     * @covers DBAL\Database::executeQuery
148
     * @covers DBAL\Database::numRows
149
     */
150
    public function testDeleteFailure(){
151
        $this->assertFalse(false);
152
    }
153
    
154
    /**
155
     * @covers DBAL\Database::count
156
     * @covers DBAL\Database::where
157
     * @covers DBAL\Database::executeQuery
158
     */
159
    public function testCount(){
160
        $this->assertFalse(false);
161
    }
162
    
163
    /**
164
     * @covers DBAL\Database::fulltextIndex
165
     */
166
    public function testFulltextIndex(){
167
        $this->assertFalse(false);
168
    }
169
    
170
    /**
171
     * @covers DBAL\Database::numRows
172
     * @covers DBAL\Database::rowCount
173
     */
174
    public function testNumRows(){
175
        $this->assertFalse(false);
176
    }
177
    
178
    /**
179
     * @covers DBAL\Database::lastInsertId
180
     */
181
    public function testLastInsertID(){
182
        $this->assertFalse(false);
183
    }
184
    
185
    /**
186
     * @covers DBAL|Database::setCaching
187
     */
188
    public function testCaching(){
189
        $this->assertFalse(false);
190
    }
191
}
192