For more information on configuring the database connection, see
the __construct() method.
/** * Tests that this adapter can connect to the database, and that the status is properly * persisted. * * @return void */ public function testDatabaseConnection() { $db = new MySql(array('autoConnect' => false) + $this->_dbConfig); $this->assertTrue($db->connect()); $this->assertTrue($db->isConnected()); $this->assertTrue($db->disconnect()); $this->assertFalse($db->isConnected()); }
/** * Tests that this adapter can connect to the database, and that the status is properly * persisted. */ public function testDatabaseConnection() { $db = new MySql(array('autoConnect' => false) + $this->_dbConfig); $this->assertTrue($db->connect()); $this->assertTrue($db->isConnected()); $this->assertTrue($db->disconnect()); $this->assertFalse($db->isConnected()); $db = new MySQL(array('autoConnect' => false, 'encoding' => null, 'persistent' => false, 'host' => 'localhost:3306', 'login' => 'garbage', 'password' => '', 'database' => 'garbage', 'init' => true) + $this->_dbConfig); $this->expectException(); $this->assertFalse($db->connect()); $this->assertFalse($db->isConnected()); $this->assertTrue($db->disconnect()); $this->assertFalse($db->isConnected()); }
/** * Skip the test if a MySQL adapter configuration is unavailable and preload test data. */ public function skip() { $this->skipIf(!MySql::enabled(), 'MySQL Extension is not loaded'); $dbConfig = Connections::get('test', array('config' => true)); $hasDb = isset($dbConfig['adapter']) && $dbConfig['adapter'] == 'MySql'; $message = 'Test database is either unavailable, or not using a MySQL adapter'; $this->skipIf(!$hasDb, $message); $this->db = new MySql($dbConfig); }
public function testConnectionGetAndReset() { Connections::add('conn-test', $this->config); Connections::add('conn-test-2', $this->config); $this->assertEqual(array('conn-test', 'conn-test-2'), Connections::get()); $this->skipIf(!MySql::enabled(), 'MySql is not enabled'); $this->skipIf(!$this->_canConnect('localhost', 3306), 'Cannot connect to localhost:3306'); $expected = $this->config + array('type' => 'database', 'filters' => array()); $this->assertEqual($expected, Connections::get('conn-test', array('config' => true))); $this->assertNull(Connections::reset()); $this->assertFalse(Connections::get()); $this->assertTrue(is_array(Connections::get())); }
public function testConnectionAutoInstantiation() { Connections::add('conn-test', $this->config); Connections::add('conn-test-2', $this->config); $this->skipIf(!MySql::enabled(), 'MySql is not enabled'); $this->skipIf(!$this->_canConnect('localhost', 3306), 'Cannot connect to localhost:3306'); $this->expectException('/mysql_get_server_info/'); $this->expectException('/mysql_select_db/'); $this->expectException('/mysql_pconnect/'); $result = Connections::get('conn-test'); $this->assertTrue($result instanceof MySql); $result = Connections::get('conn-test'); $this->assertTrue($result instanceof MySql); $this->assertNull(Connections::get('conn-test-2', array('autoCreate' => false))); }
/** * Skip the test if a MySQL or PostgreSQL adapter configuration is unavailable and * preload test data. */ public function skip() { $enabled = MySql::enabled() || PostgreSql::enabled(); $this->skipIf(!$enabled, 'MySQL or PostgreSQL Extension is not loaded'); $dbConfig = Connections::get('test', array('config' => true)); $validAdapter = in_array($dbConfig['adapter'], array('MySql', 'PostgreSql')); $hasDb = isset($dbConfig['adapter']) && $validAdapter; $message = 'Test database is either unavailable, or not using a MySQL/PostgreSQL adapter'; $this->skipIf(!$hasDb, $message); switch ($dbConfig['adapter']) { case "MySql": $this->db = new MySql($dbConfig); $this->mockPrefix = 'mysql'; break; case "PostgreSql": $this->db = new PostgreSql($dbConfig); $this->mockPrefix = 'postgresql'; break; } }
public function testConnectionGetAndReset() { Connections::add('conn-test', $this->config); Connections::add('conn-test-2', $this->config); $this->assertEqual(array('conn-test', 'conn-test-2'), Connections::get()); $enabled = MySql::enabled() || PostgreSql::enabled(); $this->skipIf(!$enabled, 'MySql or PostgreSQL is not enabled'); if (MySql::enabled()) { $this->_port = 3306; } if (PostgreSql::enabled()) { $this->_port = 5432; } $msg = "Cannot connect to localhost:{$this->_port}"; $this->skipIf(!$this->_canConnect('localhost', $this->_port), $msg); $expected = $this->config + array('type' => 'database', 'filters' => array()); $this->assertEqual($expected, Connections::get('conn-test', array('config' => true))); $this->assertNull(Connections::reset()); $this->assertFalse(Connections::get()); $this->assertTrue(is_array(Connections::get())); }
public function __construct(array $config = array()) { parent::__construct($config); $this->connection = $this; }
public function testEnabledFeatures() { $this->assertTrue(MySql::enabled()); $this->assertTrue(MySql::enabled('relationships')); $this->assertFalse(MySql::enabled('arrays')); }