Passed
Branch master (71c281)
by Wanderson
01:19
created

MySQLTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
dl 0
loc 47
rs 10
c 0
b 0
f 0
wmc 4
lcom 0
cbo 3
1
<?php
2
3
namespace Win\Connection;
4
5
use Win\Helper\Url;
6
use Win\Mvc\Application;
7
8
class MySQLTest extends \PHPUnit_Framework_TestCase {
9
10
	public function testPdoIsNullOnErrorConnection() {
11
		$dbConfig = [
12
			'host' => 'localhost',
13
			'user' => 'no-name',
14
			'pass' => 'no-pass',
15
			'dbname' => 'database-doesnt-exist'
16
		];
17
18
		new Application();
19
		$db = new MySQL($dbConfig);
20
		$this->assertNull($db->getPDO());
21
	}
22
23
	public function testRedirectToPage500() {
24
		$dbConfig = [
25
			'host' => 'localhost',
26
			'user' => 'no-name',
27
			'pass' => 'no-pass',
28
			'dbname' => 'database-doesnt-exist'
29
		];
30
31
		Url::instance()->setUrl('my-page/test');
32
		$app = new Application();
33
		$this->assertEquals($app->getPage(), 'my-page');
34
35
		new MySQL($dbConfig);
36
		$this->assertEquals($app->getPage(), '503');
37
	}
38
39
	public function testConnectionWithSuccess() {
40
		static::startMySQLConnection();
41
		$this->assertTrue(MySQL::instance()->getPDO() instanceof \PDO);
42
	}
43
44
	/**
45
	 * @return \PDO
46
	 */
47
	static function startMySQLConnection() {
48
		require BASE_PATH . '/app/config/database.php';
49
		$db['dbname'] = 'win_test';
50
		$mysql = new MySQL($db);
51
		return $mysql->getPDO();
52
	}
53
54
}
55