Completed
Push — master ( 1732ea...d2cc80 )
by smiley
02:35
created

DBInstanceTest::testDBInstance()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 29
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 6
Bugs 0 Features 1
Metric Value
c 6
b 0
f 1
dl 0
loc 29
rs 8.8571
cc 2
eloc 19
nc 2
nop 3
1
<?php
2
/**
3
 * @filesource   DBInstanceTest.php
4
 * @created      21.02.2016
5
 * @author       Smiley <[email protected]>
6
 * @copyright    2016 Smiley
7
 * @license      MIT
8
 */
9
10
namespace chillerlan\DatabaseTest;
11
12
use chillerlan\Database\DBOptions;
13
use chillerlan\Database\Drivers\MySQLi\MySQLiDriver;
14
use chillerlan\Database\Drivers\PDO\PDOFirebirdDriver;
15
use chillerlan\Database\Drivers\PDO\PDOMySQLDriver;
16
use chillerlan\Database\Drivers\PDO\PDOPostgresDriver;
17
use chillerlan\Database\Drivers\PDO\PDOSQLiteDriver;
18
use chillerlan\Database\Drivers\PostgreSQL\PostgreSQLDriver;
19
use chillerlan\Database\Drivers\SQLite\SQLite3Driver;
20
use Dotenv\Dotenv;
21
22
class DBInstanceTest extends \PHPUnit_Framework_TestCase{
23
24
	/**
25
	 * @todo TRAVIS REMINDER!
26
	 */
27
	const DOTENV = '.env_travis';
28
29
	protected $options  = [];
30
	protected $drivers  = [];
31
	protected $resource = [];
32
33
	public function setUp(){
34
35
		(new Dotenv(__DIR__.'/../config', self::DOTENV))->load();
36
37
	}
38
39
	public function driverDataProvider(){
40
		return [
41
			// native
42
			['MYSQLI',       MySQLiDriver::class,       'mysqli'],
43
			['POSTGRESQL',   PostgreSQLDriver::class, 'resource'],
44
			['SQLITE3',      SQLite3Driver::class,     'SQLite3'],
45
46
			// PDO (obviously)
47
			['PDO_MYSQL',    PDOMySQLDriver::class,    'PDO'],
48
			['PDO_POSTGRES', PDOPostgresDriver::class, 'PDO'],
49
#			['PDO_FIREBIRD', PDOFirebirdDriver::class, 'PDO'], // https://github.com/asfernandes/firebird/blob/master/.travis.yml
0 ignored issues
show
Unused Code Comprehensibility introduced by
65% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
50
			['PDO_SQLITE',   PDOSQLiteDriver::class,   'PDO'],
51
		];
52
	}
53
54
	/**
55
	 * @dataProvider driverDataProvider
56
	 */
57
	public function testDBInstance($name, $driverInterface, $resourceInterface){
58
59
		$this->options[$name] = new DBOptions([
60
			'host'     => getenv('DB_'.$name.'_HOST'),
61
			'port'     => getenv('DB_'.$name.'_PORT'),
62
			'socket'   => getenv('DB_'.$name.'_SOCKET'),
63
			'database' => getenv('DB_'.$name.'_DATABASE'),
64
			'username' => getenv('DB_'.$name.'_USERNAME'),
65
			'password' => getenv('DB_'.$name.'_PASSWORD'),
66
		]);
67
68
		$this->drivers[$name]  = new $driverInterface($this->options[$name]);
69
		$this->resource[$name] = $this->drivers[$name]->connect();
70
71
		$this->assertInstanceOf($driverInterface, $this->drivers[$name]);
72
73
		if(gettype($this->resource[$name]) === 'object'){
74
			$this->assertInstanceOf($resourceInterface, $this->resource[$name]);
75
		}
76
		else{
77
			$this->assertInternalType($resourceInterface, $this->resource[$name]);
78
		}
79
80
		var_dump($driverInterface);
0 ignored issues
show
Security Debugging Code introduced by
var_dump($driverInterface); looks like debug code. Are you sure you do not want to remove it? This might expose sensitive data.
Loading history...
81
		var_dump($this->drivers[$name]->getClientInfo());
82
		var_dump($this->drivers[$name]->getServerInfo());
83
84
		$this->drivers[$name]->disconnect();
85
	}
86
87
}
88