Skip to content

Commit 56cd97f

Browse files
committed
code class not responsible for removed, code coverage corrections
1 parent 76aca4a commit 56cd97f

File tree

10 files changed

+48
-71
lines changed

10 files changed

+48
-71
lines changed

lib/Database/ez_mysqli.php

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,7 @@
99
use ezsql\DatabaseInterface;
1010

1111
class ez_mysqli extends ezsqlModel implements DatabaseInterface
12-
{
13-
/*
14-
* ezSQL error strings - mySQLi
15-
* @var array
16-
*/
17-
private $ezsql_mysql_str = array
18-
(
19-
1 => 'Require $name to select a database',
20-
2 => 'mySQL database connection is not active',
21-
3 => 'Unexpected error while trying to select database'
22-
);
23-
12+
{
2413
private static $isSecure = false;
2514
private static $secure = null;
2615

@@ -43,12 +32,12 @@ class ez_mysqli extends ezsqlModel implements DatabaseInterface
4332
private $database;
4433

4534
public function __construct(ConfigInterface $settings = null) {
46-
if ( ! \class_exists ('ezsqlModel') ) {
35+
if ( ! \class_exists('ezsqlModel') ) {
4736
if ( ! \interface_exists('Psr\Container\ContainerInterface') )
4837
throw new Exception(\CONFIGURATION_REQUIRES);
4938
}
5039

51-
if (empty($settings) || (!$settings instanceof ConfigInterface)) {
40+
if (empty($settings)) {
5241
throw new Exception(\MISSING_CONFIGURATION);
5342
}
5443

@@ -147,19 +136,15 @@ public function select($name = '', $charset = '')
147136
{
148137
$this->_connected = false;
149138
$name = empty($name) ? $this->database->getName() : $name;
150-
if ( ! $name ) {
151-
// Must have a database name
152-
$this->register_error($this->ezsql_mysql_str[1] . ' in ' . __FILE__ . ' on line ' . __LINE__);
153-
$this->show_errors ? \trigger_error($this->ezsql_mysql_str[1], \E_USER_WARNING) : null;
154-
} elseif ( ! $this->dbh ) {
139+
if ( ! $this->dbh ) {
155140
// Must have an active database connection
156-
$this->register_error($this->ezsql_mysql_str[2] . ' in ' . __FILE__ . ' on line ' . __LINE__);
157-
$this->show_errors ? \trigger_error($this->ezsql_mysql_str[2], \E_USER_WARNING) : null;
141+
$this->register_error(\FAILED_CONNECTION . ' in ' . __FILE__ . ' on line ' . __LINE__);
142+
$this->show_errors ? \trigger_error(\FAILED_CONNECTION, \E_USER_WARNING) : null;
158143
} elseif ( !\mysqli_select_db($this->dbh, $name) ) {
159144
// Try to connect to the database
160145
// Try to get error supplied by mysql if not use our own
161146
if ( !$str = \mysqli_error($this->dbh)) {
162-
$str = $this->ezsql_mysql_str[3];
147+
$str = 'Unexpected error while trying to select database';
163148
}
164149

165150
$this->register_error($str . ' in ' .__FILE__ . ' on line ' . __LINE__);

lib/Database/ez_pdo.php

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,6 @@
1111

1212
class ez_pdo extends ezsqlModel implements DatabaseInterface
1313
{
14-
/**
15-
* ezSQL error strings - PDO
16-
* @var array
17-
*/
18-
private $_ezsql_pdo_str = array
19-
(
20-
1 => 'Require $dsn and $user and $password to create a connection',
21-
2 => 'File based databases require $dsn to create a connection'
22-
);
23-
2414
private static $isSecure = false;
2515
private static $secure = null;
2616
private static $_options = [];
@@ -44,13 +34,13 @@ class ez_pdo extends ezsqlModel implements DatabaseInterface
4434

4535
private $database;
4636

47-
public function __construct(ConfigInterface $settings) {
48-
if ( ! \class_exists ('ezsqlModel') ) {
37+
public function __construct(ConfigInterface $settings = null) {
38+
if ( ! \class_exists('ezsqlModel') ) {
4939
if ( ! \interface_exists('Psr\Container\ContainerInterface') )
5040
throw new Exception(\CONFIGURATION_REQUIRES);
5141
}
5242

53-
if (empty($settings) || (!$settings instanceof ConfigInterface)) {
43+
if (empty($settings)) {
5444
throw new Exception(\MISSING_CONFIGURATION);
5545
}
5646

@@ -139,19 +129,7 @@ public function connect(
139129
$setUser = empty($user) ? $this->database->getUser() : $user;
140130
$setPassword = empty($password) ? $this->database->getPassword() : $password;
141131
$setOptions = empty($options) ? $this->database->getOptions() : $options;
142-
$IsFile = empty($isFile) ? $this->database->getIsFile() : $isFile;
143-
144-
if (!$IsFile) {
145-
// Must have a user and a password if not file based
146-
if ( empty($setDsn) || empty($setUser) || empty($setPassword )) {
147-
$this->register_error($this->_ezsql_pdo_str[1] . ' in ' . __FILE__ . ' on line ' . __LINE__);
148-
$this->show_errors ? \trigger_error($this->_ezsql_pdo_str[1], \E_USER_WARNING) : null;
149-
}
150-
} elseif (empty($setDsn)) {
151-
// Must have a dsn
152-
$this->register_error($this->_ezsql_pdo_str[2] . ' in ' . __FILE__ . ' on line ' . __LINE__);
153-
$this->show_errors ? \trigger_error($this->_ezsql_pdo_str[2], \E_USER_WARNING) : null;
154-
}
132+
$IsFile = empty($isFile) ? $this->database->getIsFile() : $isFile;
155133

156134
// Establish PDO connection
157135
try {

lib/Database/ez_pgsql.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@ class ez_pgsql extends ezsqlModel implements DatabaseInterface
3131
*/
3232
private $database;
3333

34-
public function __construct(ConfigInterface $settings)
34+
public function __construct(ConfigInterface $settings = null)
3535
{
36-
if ( ! \class_exists ('ezsqlModel') ) {
36+
if ( ! \class_exists('ezsqlModel') ) {
3737
if ( ! \interface_exists('Psr\Container\ContainerInterface') )
3838
throw new Exception(\CONFIGURATION_REQUIRES);
3939
}
4040

41-
if (empty($settings) || (!$settings instanceof ConfigInterface)) {
41+
if (empty($settings)) {
4242
throw new Exception(\MISSING_CONFIGURATION);
4343
}
4444

lib/Database/ez_sqlite3.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,14 @@ class ez_sqlite3 extends ezsqlModel implements DatabaseInterface
3232
* Constructor - allow the user to perform a quick connect at the
3333
* same time as initializing the ez_sqlite3 class
3434
*/
35-
public function __construct(ConfigInterface $settings)
35+
public function __construct(ConfigInterface $settings = null)
3636
{
37-
if ( ! \class_exists ('ezsqlModel') ) {
37+
if ( ! \class_exists('ezsqlModel') ) {
3838
if ( ! \interface_exists('Psr\Container\ContainerInterface') )
3939
throw new Exception(\CONFIGURATION_REQUIRES);
4040
}
4141

42-
if (empty($settings) || (!$settings instanceof ConfigInterface)) {
42+
if (empty($settings)) {
4343
throw new Exception(\MISSING_CONFIGURATION);
4444
}
4545

@@ -49,7 +49,7 @@ public function __construct(ConfigInterface $settings)
4949
// Turn on track errors
5050
ini_set('track_errors', '1');
5151

52-
if (empty($GLOBALS['ez'.\SQLITE3]))
52+
if (!isset($GLOBALS['ez'.\SQLITE3]))
5353
$GLOBALS['ez'.\SQLITE3] = $this;
5454
\setInstance($this);
5555
}

lib/Database/ez_sqlsrv.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,14 @@ class ez_sqlsrv extends ezsqlModel implements DatabaseInterface
4040
*/
4141
private $database;
4242

43-
public function __construct(ConfigInterface $settings)
43+
public function __construct(ConfigInterface $settings = null)
4444
{
45-
if ( ! \class_exists ('ezsqlModel') ) {
45+
if ( ! \class_exists('ezsqlModel') ) {
4646
if ( ! \interface_exists('Psr\Container\ContainerInterface') )
4747
throw new Exception(\CONFIGURATION_REQUIRES);
4848
}
4949

50-
if (empty($settings) || (!$settings instanceof ConfigInterface)) {
50+
if (empty($settings)) {
5151
throw new Exception(\MISSING_CONFIGURATION);
5252
}
5353

tests/mysqli/mysqliTest.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -526,16 +526,18 @@ public function testQuery_prepared() {
526526
/**
527527
* @covers ezsql\Database\ez_mysqli::__construct
528528
*/
529-
public function test__construct_Error() {
530-
$this->expectException(\Exception::class);
529+
public function test__construct_Error()
530+
{
531531
$this->expectExceptionMessageRegExp('/[Missing configuration details]/');
532532
$this->assertNull(new ez_mysqli());
533533
}
534534

535535
/**
536536
* @covers ezsql\Database\ez_mysqli::__construct
537537
*/
538-
public function test__construct() {
538+
public function test__construct()
539+
{
540+
unset($GLOBALS['ez'.\MYSQLI]);
539541
$settings = new Config('mysqli', [self::TEST_DB_USER, self::TEST_DB_PASSWORD, self::TEST_DB_NAME]);
540542
$this->assertNotNull(new ez_mysqli($settings));
541543
}

tests/pdo/pdo_mysqlTest.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -270,16 +270,18 @@ public function testMySQLConnectWithOptions() {
270270
/**
271271
* @covers ezsql\Database\ez_pdo::__construct
272272
*/
273-
public function test__Construct_Error() {
273+
public function test__Construct_Error()
274+
{
274275
$this->expectExceptionMessageRegExp('/[Missing configuration details]/');
275-
$this->assertNull(new ez_pdo('bad'));
276+
$this->assertNull(new ez_pdo());
276277
}
277278

278279
/**
279280
* @covers ezsql\Database\ez_pdo::__construct
280281
*/
281-
public function test__construct() {
282-
282+
public function test__construct()
283+
{
284+
unset($GLOBALS['ez'.\Pdo]);
283285
$dsn = 'mysql:host='.self::TEST_DB_HOST.';dbname='. self::TEST_DB_NAME.';port=3306';
284286
$settings = Config::initialize('pdo', [$dsn, self::TEST_DB_USER, self::TEST_DB_PASSWORD]);
285287
$this->assertNotNull(new ez_pdo($settings));

tests/postgresql/postgresqlTest.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -274,16 +274,18 @@ public function testSelecting()
274274
/**
275275
* @covers ezsql\Database\ez_pgsql::__construct
276276
*/
277-
public function test__Construct_Error() {
277+
public function test__Construct_Error()
278+
{
278279
$this->expectExceptionMessageRegExp('/[Missing configuration details]/');
279-
$this->assertNull(new ez_pgsql('bad'));
280+
$this->assertNull(new ez_pgsql());
280281
}
281282

282283
/**
283284
* @covers ezsql\Database\ez_pgsql::__construct
284285
*/
285-
public function test__construct() {
286-
286+
public function test__construct()
287+
{
288+
unset($GLOBALS['ez'.\PGSQL]);
287289
$settings = new Config('pgsql', [self::TEST_DB_USER, self::TEST_DB_PASSWORD, self::TEST_DB_NAME, self::TEST_DB_HOST, self::TEST_DB_PORT]);
288290
$this->assertNotNull(new ez_pgsql($settings));
289291
}

tests/sqlite/sqlite3Test.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace ezsql\Tests\sqlite;
44

5+
use Exception;
56
use ezsql\Database;
67
use ezsql\Config;
78
use ezsql\Database\ez_sqlite3;
@@ -276,13 +277,14 @@ public function testSelecting()
276277
*/
277278
public function test__Construct_Error() {
278279
$this->expectExceptionMessageRegExp('/[Missing configuration details]/');
279-
$this->assertNull(new ez_sqlite3('bad'));
280+
$this->assertNull(new ez_sqlite3());
280281
}
281282

282283
/**
283284
* @covers ezsql\Database\ez_sqlite3::__construct
284285
*/
285286
public function test__construct() {
287+
unset($GLOBALS['ez'.\SQLITE3]);
286288
$settings = new Config('sqlite3', [self::TEST_SQLITE_DB_DIR, self::TEST_SQLITE_DB]);
287289
$this->assertNotNull(new ez_sqlite3($settings));
288290
}

tests/sqlsrv/sqlsrvTest.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ public function testConnect()
6565
{
6666
$result = $this->object->connect(self::TEST_DB_USER, self::TEST_DB_PASSWORD, self::TEST_DB_NAME);
6767
$this->assertTrue($result);
68+
69+
$result = $this->object->connect('self::TEST_DB_USER', 'self::TEST_DB_PASSWORD', 'self::TEST_DB_NAME');
70+
$this->assertFalse($result);
6871
} // testConnect
6972

7073
/**
@@ -131,6 +134,7 @@ public function testQuery()
131134

132135
/**
133136
* @covers ezsql\Database\ez_sqlsrv::convert
137+
* @covers ezsql\Database\ez_sqlsrv::get_datatype
134138
*/
135139
public function testConvert()
136140
{
@@ -240,6 +244,7 @@ public function testDelete()
240244
* @covers ezsql\Database\ez_sqlsrv::query
241245
* @covers ezsql\Database\ez_sqlsrv::prepareValues
242246
* @covers ezsql\Database\ez_sqlsrv::query_prepared
247+
* @covers ezsql\Database\ez_sqlsrv::get_datatype
243248
*/
244249
public function testSelecting()
245250
{
@@ -297,13 +302,14 @@ public function testDisconnect() {
297302
public function test__Construct_Error()
298303
{
299304
$this->expectExceptionMessageRegExp('/[Missing configuration details]/');
300-
$this->assertNull(new ez_sqlsrv('bad'));
305+
$this->assertNull(new ez_sqlsrv());
301306
}
302307

303308
/**
304309
* @covers ezsql\Database\ez_sqlsrv::__construct
305310
*/
306311
public function test__construct() {
312+
unset($GLOBALS['ez'.\SQLSRV]);
307313
$settings = Config::initialize('sqlsrv', [self::TEST_DB_USER, self::TEST_DB_PASSWORD, self::TEST_DB_NAME]);
308314
$this->assertNotNull(new ez_sqlsrv($settings));
309315
}

0 commit comments

Comments
 (0)