Completed
Push — master ( 0770f4...706bc6 )
by Adam
03:13 queued 01:02
created

DatabaseTest   A

Complexity

Total Complexity 21

Size/Duplication

Total Lines 199
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 4

Importance

Changes 12
Bugs 0 Features 0
Metric Value
wmc 21
c 12
b 0
f 0
lcom 2
cbo 4
dl 0
loc 199
rs 10

21 Methods

Rating   Name   Duplication   Size   Complexity  
A getConnection() 0 4 1
A getDataSet() 0 3 1
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
3
4
namespace DBAL\Tests;
5
6
use DBAL\Database;
7
use PHPUnit\Framework\TestCase;
8
use PHPUnit\DbUnit\TestCaseTrait;
9
10
class DatabaseTest extends TestCase{
11
    
12
    use TestCaseTrait;
13
    
14
    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...
15
    CONST HOSTNAME = 'localhost';
16
    CONST DATABASE = 'my_database';
17
    CONST USER = 'my_user';
18
    CONST PASSWORD = 'my_password';
19
    
20
    public function getConnection() {
21
        $pdo = new \PDO('mysql:'.self::HOSTNAME, self::USER, self::PASSWORD);
22
        return $this->createDefaultDBConnection($pdo, self::DATABASE);
23
    }
24
    
25
    public function getDataSet(){
26
        $this->getConnection()->createDataSet(['test_table']);
27
    }
28
    /**
29
     * @covers DBAL\Database::__construct
30
     * @covers DBAL\Database::connectToServer
31
     */
32
    public static function setUpBeforeClass(){
33
        self::$db = new Database(self::HOSTNAME, self::USER, self::PASSWORD, self::DATABASE);
34
    }
35
    
36
    /**
37
     * @covers DBAL\Database::__destruct
38
     */
39
    public static function tearDownAfterClass(){
40
        self::$db = null;
41
    }
42
43
    /**
44
     * @covers DBAL\Database::__construct
45
     * @covers DBAL\Database::connectToServer
46
     */
47
    public function testConnect(){
48
        $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...
49
    }
50
    
51
    /**
52
     * @covers DBAL\Database
53
     */
54
    public function testConnectFailure(){
55
        $this->assertFalse(false);
56
    }
57
    
58
    /**
59
     * @covers DBAL\Database::query
60
     */
61
    public function testQuery(){
62
        $query = self::$db->query("SELECT * FROM `test_table` WHERE `id` = ?", array(1));
63
        $this->assertArrayHasKey('0', $query);
64
        $this->assertCount(1, $query);
65
    }
66
    
67
    /**
68
     * @covers DBAL\Database::select
69
     * @covers DBAL\Database::buildSelectQuery
70
     * @covers DBAL\Database::where
71
     * @covers DBAL\Database::orderBy
72
     * @covers DBAL\Database::limit
73
     * @covers DBAL\Database::executeQuery
74
     */
75
    public function testSelect(){
76
        $simpleSelect = self::$db->select('test_table', array('id' => array('>', 1)), '*', array('id' => 'ASC'));
77
        $this->assertArrayHasKey('name', $simpleSelect);
78
    }
79
    
80
    /**
81
     * @covers DBAL\Database::selectAll
82
     * @covers DBAL\Database::buildSelectQuery
83
     * @covers DBAL\Database::where
84
     * @covers DBAL\Database::orderBy
85
     * @covers DBAL\Database::limit
86
     * @covers DBAL\Database::executeQuery
87
     */
88
    public function testSelectAll(){
89
        $this->assertFalse(false);
90
    }
91
    
92
    /**
93
     * @covers DBAL\Database::select
94
     * @covers DBAL\Database::selectAll
95
     * @covers DBAL\Database::buildSelectQuery
96
     * @covers DBAL\Database::where
97
     * @covers DBAL\Database::orderBy
98
     * @covers DBAL\Database::limit
99
     * @covers DBAL\Database::executeQuery
100
     */
101
    public function testSelectFailure(){
102
        $this->assertFalse(false);
103
    }
104
    
105
    /**
106
     * @covers DBAL\Database::insert
107
     * @covers DBAL\Database::fields
108
     * @covers DBAL\Database::executeQuery
109
     * @covers DBAL\Database::numRows
110
     */
111
    public function testInsert(){
112
        $this->assertFalse(false);
113
    }
114
    
115
    /**
116
     * @covers DBAL\Database::insert
117
     * @covers DBAL\Database::fields
118
     * @covers DBAL\Database::executeQuery
119
     * @covers DBAL\Database::numRows
120
     */
121
    public function tsetInsertFailure(){
122
        $this->assertFalse(false);
123
    }
124
    
125
    /**
126
     * @covers DBAL\Database::update
127
     * @covers DBAL\Database::fields
128
     * @covers DBAL\Database::where
129
     * @covers DBAL\Database::limit
130
     * @covers DBAL\Database::executeQuery
131
     * @covers DBAL\Database::numRows
132
     */
133
    public function testUpdate(){
134
        $this->assertFalse(false);
135
    }
136
    
137
    /**
138
     * @covers DBAL\Database::update
139
     * @covers DBAL\Database::fields
140
     * @covers DBAL\Database::where
141
     * @covers DBAL\Database::limit
142
     * @covers DBAL\Database::executeQuery
143
     * @covers DBAL\Database::numRows
144
     */
145
    public function testUpdateFailure(){
146
        $this->assertFalse(false);
147
    }
148
    
149
    /**
150
     * @covers DBAL\Database::delete
151
     * @covers DBAL\Database::where
152
     * @covers DBAL\Database::limit
153
     * @covers DBAL\Database::executeQuery
154
     * @covers DBAL\Database::numRows
155
     */
156
    public function testDelete(){
157
        $this->assertFalse(false);
158
    }
159
    
160
    /**
161
     * @covers DBAL\Database::delete
162
     * @covers DBAL\Database::where
163
     * @covers DBAL\Database::limit
164
     * @covers DBAL\Database::executeQuery
165
     * @covers DBAL\Database::numRows
166
     */
167
    public function testDeleteFailure(){
168
        $this->assertFalse(false);
169
    }
170
    
171
    /**
172
     * @covers DBAL\Database::count
173
     * @covers DBAL\Database::where
174
     * @covers DBAL\Database::executeQuery
175
     */
176
    public function testCount(){
177
        $this->assertFalse(false);
178
    }
179
    
180
    /**
181
     * @covers DBAL\Database::fulltextIndex
182
     */
183
    public function testFulltextIndex(){
184
        $this->assertFalse(false);
185
    }
186
    
187
    /**
188
     * @covers DBAL\Database::numRows
189
     * @covers DBAL\Database::rowCount
190
     */
191
    public function testNumRows(){
192
        $this->assertFalse(false);
193
    }
194
    
195
    /**
196
     * @covers DBAL\Database::lastInsertId
197
     */
198
    public function testLastInsertID(){
199
        $this->assertFalse(false);
200
    }
201
    
202
    /**
203
     * @covers DBAL|Database::setCaching
204
     */
205
    public function testCaching(){
206
        $this->assertFalse(false);
207
    }
208
}
209