<?php
/**
* Moc10 Library
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.TXT.
* It is also available through the world-wide-web at this URL:
* http://www.moc10phplibrary.com/LICENSE.TXT
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to hide@address.com so we can send you a copy immediately.
*
* @category Moc10
* @package Moc10_Db
* @author Nick Sagona, III <hide@address.com>
* @copyright Copyright (c) 2009-2011 Moc 10 Media, LLC. (http://www.moc10media.com)
* @license http://www.moc10phplibrary.com/LICENSE.TXT New BSD License
*/
require_once dirname(__FILE__) . '/../../library/Moc10/Autoloader.php';
Moc10_Autoloader::bootstrap();
class Moc10_DbTest extends PHPUnit_Framework_TestCase
{
public function testDbGetInstance()
{
$d = Moc10_Db::getInstance('MySQLi', 'testdb', 'localhost', 'testuser', '12test34');
$class = 'Moc10_Db';
$this->assertTrue($d instanceof $class);
}
public function testDbQueryAndFetch()
{
$d = Moc10_Db::getInstance('MySQLi', 'testdb', 'localhost', 'testuser', '12test34');
$d->interface->query('SELECT email FROM users WHERE user_id = 1');
while (($row = $d->interface->fetch()) != false) {
$email = $row['email'];
}
$this->assertEquals('hide@address.com', $email);
}
public function testDbLastId()
{
$d = Moc10_Db::getInstance('MySQLi', 'testdb', 'localhost', 'testuser', '12test34');
$d->interface->query("INSERT INTO users SET username = 'test2', email = 'hide@address.com'");
$this->assertEquals(9, $d->interface->lastId());
}
public function testDbNumRows()
{
$d = Moc10_Db::getInstance('MySQLi', 'testdb', 'localhost', 'testuser', '12test34');
$d->interface->query('SELECT email FROM users WHERE user_id = 1');
$this->assertEquals(1, $d->interface->numRows());
}
public function testDbNumFields()
{
$d = Moc10_Db::getInstance('MySQLi', 'testdb', 'localhost', 'testuser', '12test34');
$d->interface->query('SELECT * FROM users');
$this->assertEquals(3, $d->interface->numFields());
}
public function testDbVersion()
{
$d = Moc10_Db::getInstance('MySQLi', 'testdb', 'localhost', 'testuser', '12test34');
$this->assertNotEquals(null, $d->interface->version());
}
}
?>