php-censor/tests/B8Framework/DatabaseTest.php

55 lines
1.4 KiB
PHP
Raw Normal View History

2016-04-17 08:34:12 +02:00
<?php
namespace Tests\b8;
use b8\Database;
class DatabaseTest extends \PHPUnit_Framework_TestCase
{
protected $_host = 'localhost';
protected $_user = 'b8_test';
protected $_pass = 'b8_test';
protected $_name = 'b8_test';
public function testGetReadConnection()
{
Database::setDetails($this->_name, $this->_user, $this->_pass);
2016-04-21 06:58:09 +02:00
Database::setReadServers([$this->_host]);
2016-04-17 08:34:12 +02:00
$connection = Database::getConnection('read');
$this->assertInstanceOf('\b8\Database', $connection);
}
public function testGetWriteConnection()
{
Database::setDetails($this->_name, $this->_user, $this->_pass);
2016-04-21 06:58:09 +02:00
Database::setWriteServers([$this->_host]);
2016-04-17 08:34:12 +02:00
$connection = Database::getConnection('write');
$this->assertInstanceOf('\b8\Database', $connection);
}
public function testGetDetails()
{
Database::setDetails($this->_name, $this->_user, $this->_pass);
2016-04-21 06:58:09 +02:00
Database::setReadServers(['localhost']);
2016-04-17 08:34:12 +02:00
$details = Database::getConnection('read')->getDetails();
$this->assertTrue(is_array($details));
$this->assertTrue(($details['db'] == $this->_name));
$this->assertTrue(($details['user'] == $this->_user));
$this->assertTrue(($details['pass'] == $this->_pass));
}
/**
* @expectedException \Exception
*/
public function testConnectionFailure()
{
Database::setDetails('non_existant', 'invalid_user', 'incorrect_password');
2016-04-21 06:58:09 +02:00
Database::setReadServers(['localhost']);
2016-04-17 08:34:12 +02:00
Database::getConnection('read');
}
}