Skip to content

Commit 71db69e

Browse files
committed
corrections, update code coverage
1 parent adf9fde commit 71db69e

File tree

9 files changed

+78
-12
lines changed

9 files changed

+78
-12
lines changed

lib/Database/ez_mysqli.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,6 @@ public function select($name = '', $charset = '')
154154
{
155155
$this->_connected = false;
156156
$name = empty($name) ? $this->database->getName() : $name;
157-
$charset = empty($charset) ? $this->database->getCharset() : $charset;
158157
if ( ! $name ) {
159158
// Must have a database name
160159
$this->register_error($this->ezsql_mysql_str[3] . ' in ' . __FILE__ . ' on line ' . __LINE__);
@@ -180,13 +179,13 @@ public function select($name = '', $charset = '')
180179

181180
if ( $charset != '' ) {
182181
$encoding = \strtolower(\str_replace('-', '', $charset));
183-
$charset = array();
182+
$charsetArray = array();
184183
$recordSet = \mysqli_query($this->dbh, 'SHOW CHARACTER SET');
185184
while ( $row = \mysqli_fetch_array($recordSet, \MYSQLI_ASSOC) ) {
186-
$charset[] = $row['Charset'];
185+
$charsetArray[] = $row['Charset'];
187186
}
188187

189-
if ( \in_array($charset, $charset) ) {
188+
if ( \in_array($charset, $charsetArray) ) {
190189
\mysqli_query($this->dbh, 'SET NAMES \'' . $encoding . '\'');
191190
}
192191
}

tests/mysqli/mysqliTest.php

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,15 @@ protected function tearDown(): void
4747
}
4848
$this->object = null;
4949
}
50-
50+
51+
/**
52+
* @covers ezsql\Database\ez_mysqli::settings
53+
*/
54+
public function testSettings()
55+
{
56+
$this->assertTrue($this->object->settings() instanceof \ezsql\ConfigInterface);
57+
}
58+
5159
/**
5260
* @covers ezsql\Database\ez_mysqli::quick_connect
5361
*/
@@ -85,6 +93,7 @@ public function testConnect()
8593

8694
/**
8795
* @covers ezsql\Database\ez_mysqli::select
96+
* @covers ezsql\Database\ez_mysqli::reset
8897
*/
8998
public function testSelect()
9099
{
@@ -99,7 +108,10 @@ public function testSelect()
99108
set_error_handler(array($this, 'errorHandler'));
100109
$this->assertTrue($this->object->select(''));
101110
$this->object->disconnect();
102-
$this->assertFalse($this->object->select('notest'));
111+
$this->assertFalse($this->object->select('notest'));
112+
$this->object->connect();
113+
$this->object->reset();
114+
$this->assertFalse($this->object->select(self::TEST_DB_NAME));
103115
$this->object->connect();
104116
$this->assertFalse($this->object->select('notest'));
105117
$this->assertTrue($this->object->select(self::TEST_DB_NAME));
@@ -189,23 +201,23 @@ public function testGet_results()
189201
}
190202

191203
/**
192-
* @covers ezsql\Database\ez_mysqli::settings
204+
* @covers ezsql\Database\ez_mysqli::getHost
193205
*/
194206
public function testGetHost()
195207
{
196208
$this->assertEquals(self::TEST_DB_HOST, $this->object->getHost());
197209
}
198210

199211
/**
200-
* @covers ezsql\Database\ez_mysqli::settings
212+
* @covers ezsql\Database\ez_mysqli::getPort
201213
*/
202214
public function testGetPort()
203215
{
204216
$this->assertEquals(self::TEST_DB_PORT, $this->object->getPort());
205217
}
206218

207219
/**
208-
* @covers ezsql\Database\ez_mysqli::settings
220+
* @covers ezsql\Database\ez_mysqli::getCharset
209221
*/
210222
public function testGetCharset()
211223
{
@@ -265,13 +277,14 @@ public function testDrop()
265277

266278
/**
267279
* @covers ezsql\ezQuery::insert
280+
* @covers ezsql\Database\ez_mysqli::query
281+
* @covers ezsql\Database\ez_mysqli::prepareValues
268282
*/
269283
public function testInsert()
270284
{
271285
$object = Database::initialize('mysqli', [self::TEST_DB_USER, self::TEST_DB_PASSWORD, self::TEST_DB_NAME]);
272286
$this->assertEquals($this->object, $object);
273287
$object->connect();
274-
$object->prepareOff();
275288
$object->create('unit_test',
276289
\column('id', INTR, 11, \AUTO),
277290
\column('test_key', VARCHAR, 50),
@@ -392,7 +405,7 @@ public function testSelecting()
392405
$this->assertEquals('testing 1', $row->test_key);
393406
}
394407
}
395-
408+
396409
/**
397410
* @covers ezsql\ezQuery::create_select
398411
*/
@@ -479,6 +492,8 @@ public function testWhere()
479492

480493
/**
481494
* @covers ezsql\Database\ez_mysqli::query_prepared
495+
* @covers ezsql\Database\ez_mysqli::fetch_prepared_result
496+
* @covers ezsql\Database\ez_mysqli::prepareValues
482497
*/
483498
public function testQuery_prepared() {
484499
$this->object->prepareOff();

tests/pdo/pdo_mysqlTest.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,14 @@ protected function tearDown(): void
4444
$this->object = null;
4545
} // tearDown
4646

47-
47+
/**
48+
* @covers ezsql\Database\ez_pdo::settings
49+
*/
50+
public function testSettings()
51+
{
52+
$this->assertTrue($this->object->settings() instanceof \ezsql\ConfigInterface);
53+
}
54+
4855
/**
4956
* Here starts the MySQL PDO unit test
5057
*/
@@ -195,6 +202,9 @@ public function testDelete()
195202

196203
/**
197204
* @covers ezsql\ezQuery::selecting
205+
* @covers ezsql\Database\ez_pdo::query
206+
* @covers ezsql\Database\ez_pdo::prepareValues
207+
* @covers ezsql\Database\ez_pdo::query_prepared
198208
*/
199209
public function testSelecting()
200210
{

tests/pdo/pdo_pgsqlTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,9 @@ public function testDelete()
168168

169169
/**
170170
* @covers ezsql\ezQuery::selecting
171+
* @covers ezsql\Database\ez_pdo::query
172+
* @covers ezsql\Database\ez_pdo::prepareValues
173+
* @covers ezsql\Database\ez_pdo::query_prepared
171174
*/
172175
public function testSelecting()
173176
{

tests/pdo/pdo_sqliteTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,9 @@ public function testDelete()
196196

197197
/**
198198
* @covers ezsql\ezQuery::selecting
199+
* @covers ezsql\Database\ez_pdo::query
200+
* @covers ezsql\Database\ez_pdo::prepareValues
201+
* @covers ezsql\Database\ez_pdo::query_prepared
199202
*/
200203
public function testSelecting()
201204
{

tests/pdo/pdo_sqlsrvTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,9 @@ public function testDelete()
151151

152152
/**
153153
* @covers ezsql\ezQuery::selecting
154+
* @covers ezsql\Database\ez_pdo::query
155+
* @covers ezsql\Database\ez_pdo::prepareValues
156+
* @covers ezsql\Database\ez_pdo::query_prepared
154157
*/
155158
public function testSelecting()
156159
{

tests/postgresql/postgresqlTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,14 @@ protected function tearDown():void
4242
{
4343
$this->object = null;
4444
} // tearDown
45+
46+
/**
47+
* @covers ezsql\Database\ez_pgsql::settings
48+
*/
49+
public function testSettings()
50+
{
51+
$this->assertTrue($this->object->settings() instanceof \ezsql\ConfigInterface);
52+
}
4553

4654
/**
4755
* @covers ezsql\Database\ez_pgsql::quick_connect
@@ -217,6 +225,9 @@ public function testGetPort() {
217225

218226
/**
219227
* @covers ezsql\ezQuery::selecting
228+
* @covers ezsql\Database\ez_pgsql::query
229+
* @covers ezsql\Database\ez_pgsql::prepareValues
230+
* @covers ezsql\Database\ez_pgsql::query_prepared
220231
*/
221232
public function testSelecting()
222233
{

tests/sqlite/sqlite3Test.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,14 @@ protected function tearDown(): void
4848
$this->object = null;
4949
}
5050

51+
/**
52+
* @covers ezsql\Database\ez_sqlite3::settings
53+
*/
54+
public function testSettings()
55+
{
56+
$this->assertTrue($this->object->settings() instanceof \ezsql\ConfigInterface);
57+
}
58+
5159
/**
5260
* @covers ezsql\Database\ez_sqlite3::connect
5361
*/
@@ -211,6 +219,9 @@ public function testDelete()
211219

212220
/**
213221
* @covers ezsql\ezQuery::selecting
222+
* @covers ezsql\Database\ez_sqlite3::query
223+
* @covers ezsql\Database\ez_sqlite3::prepareValues
224+
* @covers ezsql\Database\ez_sqlite3::query_prepared
214225
*/
215226
public function testSelecting()
216227
{

tests/sqlsrv/sqlsrvTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@ protected function tearDown(): void
4040
$this->object = null;
4141
} // tearDown
4242

43+
/**
44+
* @covers ezsql\Database\ez_sqlsrv::settings
45+
*/
46+
public function testSettings()
47+
{
48+
$this->assertTrue($this->object->settings() instanceof \ezsql\ConfigInterface);
49+
}
50+
4351
/**
4452
* @covers ezsql\Database\ez_sqlsrv::quick_connect
4553
*/
@@ -228,6 +236,9 @@ public function testDelete()
228236

229237
/**
230238
* @covers ezsql\ezQuery::selecting
239+
* @covers ezsql\Database\ez_sqlsrv::query
240+
* @covers ezsql\Database\ez_sqlsrv::prepareValues
241+
* @covers ezsql\Database\ez_sqlsrv::query_prepared
231242
*/
232243
public function testSelecting()
233244
{

0 commit comments

Comments
 (0)