| 1 | <?php |
||
| 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 |