merge mongo with master
This commit is contained in:
@ -14,10 +14,10 @@ require_once dirname(__FILE__) . '/../../model/DbExpr.php';
|
||||
require_once dirname(__FILE__) . '/../../model/Db.php';
|
||||
require_once dirname(__FILE__) . '/../../model/DbDriver.php';
|
||||
require_once dirname(__FILE__) . '/../../model/SqlDbDriver.php';
|
||||
require_once dirname(__FILE__) . '/../../exception/GeneralException.php';
|
||||
|
||||
class SqlDbDriverTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
private $driver;
|
||||
|
||||
public function setUp()
|
||||
@ -29,16 +29,21 @@ class SqlDbDriverTest extends PHPUnit_Framework_TestCase
|
||||
public function testConstruct()
|
||||
{
|
||||
$conf = array('hostname' => 'localhost', 'database' => 'db', 'username' => 'test', 'password' => '1234');
|
||||
$this->driver = $this->getMockForAbstractClass('SqlDbDriver', array($conf));
|
||||
try {
|
||||
$this->driver = $this->getMockForAbstractClass('SqlDbDriver', array($conf));
|
||||
}
|
||||
catch (GeneralException $expected) {
|
||||
$this->fail($expected->getMessage());
|
||||
}
|
||||
$this->assertInstanceOf('DbDriver', $this->driver);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Exception
|
||||
* @expectedExceptionMessage Configuration must have a "username".
|
||||
*/
|
||||
public function testConstructWrongConfig()
|
||||
{
|
||||
$conf = array('hostname' => 'localhost', 'database' => 'db');
|
||||
|
||||
$this->setExpectedException('GeneralException', 'Configuration must have a "username"');
|
||||
|
||||
$this->getMockForAbstractClass('SqlDbDriver', array($conf));
|
||||
}
|
||||
|
||||
@ -49,17 +54,17 @@ class SqlDbDriverTest extends PHPUnit_Framework_TestCase
|
||||
|
||||
public function testBeginTransaction()
|
||||
{
|
||||
$this->assertEquals($this->driver, $this->driver->beginTransaction());
|
||||
$this->assertSame($this->driver, $this->driver->beginTransaction());
|
||||
}
|
||||
|
||||
public function testCommit()
|
||||
{
|
||||
$this->assertEquals($this->driver, $this->driver->commit());
|
||||
$this->assertSame($this->driver, $this->driver->commit());
|
||||
}
|
||||
|
||||
public function testRollback()
|
||||
{
|
||||
$this->assertEquals($this->driver, $this->driver->rollback());
|
||||
$this->assertSame($this->driver, $this->driver->rollback());
|
||||
}
|
||||
|
||||
public function testQuery()
|
||||
@ -68,11 +73,11 @@ class SqlDbDriverTest extends PHPUnit_Framework_TestCase
|
||||
|
||||
$stmt = $this->driver->query('SELECT * FROM table');
|
||||
$this->assertInstanceOf('DbStmt', $stmt);
|
||||
$this->assertEquals('SELECT * FROM table', $stmt->string());
|
||||
$this->assertSame('SELECT * FROM table', $stmt->string());
|
||||
|
||||
$stmt = $this->driver->query('SELECT * FROM table', 'simple');
|
||||
$this->assertInstanceOf('DbStmt', $stmt);
|
||||
$this->assertEquals('SELECT * FROM table', $stmt->string());
|
||||
$this->assertSame('SELECT * FROM table', $stmt->string());
|
||||
}
|
||||
|
||||
public function testInsert()
|
||||
@ -81,7 +86,7 @@ class SqlDbDriverTest extends PHPUnit_Framework_TestCase
|
||||
->setDriverQuoteFunction();
|
||||
$bind = array('table.name' => 'tony', 'chair.age' => 21, 'height' => 185);
|
||||
$sql = $this->driver->insert('users', $bind);
|
||||
$this->assertEquals('INSERT INTO `users` (`table`.`name`, `chair`.`age`, `height`) VALUES (tony, 21, 185)', $sql);
|
||||
$this->assertSame('INSERT INTO `users` (`table`.`name`, `chair`.`age`, `height`) VALUES (tony, 21, 185)', $sql);
|
||||
}
|
||||
|
||||
public function testUpdate()
|
||||
@ -91,7 +96,7 @@ class SqlDbDriverTest extends PHPUnit_Framework_TestCase
|
||||
|
||||
$bind = array('table.name' => 'tony', 'chair.age' => 21, 'height' => 185);
|
||||
$sql = $this->driver->update('users', $bind);
|
||||
$this->assertEquals('UPDATE `users` SET `table`.`name`=tony, `chair`.`age`=21, `height`=185', $sql);
|
||||
$this->assertSame('UPDATE `users` SET `table`.`name`=tony, `chair`.`age`=21, `height`=185', $sql);
|
||||
}
|
||||
|
||||
public function testDeleteNoWHERE()
|
||||
@ -99,7 +104,7 @@ class SqlDbDriverTest extends PHPUnit_Framework_TestCase
|
||||
$this->setDriverPrepareFunction();
|
||||
|
||||
$sql = $this->driver->delete('users');
|
||||
$this->assertEquals('DELETE FROM `users`', $sql);
|
||||
$this->assertSame('DELETE FROM `users`', $sql);
|
||||
}
|
||||
|
||||
public function testDeleteWithWHEREArray()
|
||||
@ -108,7 +113,7 @@ class SqlDbDriverTest extends PHPUnit_Framework_TestCase
|
||||
->setDriverQuoteFunction();
|
||||
|
||||
$sql = $this->driver->delete('users', array('name?tony' => new DbExpr('='), 'height?185' => '>'));
|
||||
$this->assertEquals('DELETE FROM `users` WHERE name=tony AND height>185', $sql);
|
||||
$this->assertSame('DELETE FROM `users` WHERE name=tony AND height>185', $sql);
|
||||
}
|
||||
|
||||
public function testDeleteWithWHERESimpleCond()
|
||||
@ -116,7 +121,7 @@ class SqlDbDriverTest extends PHPUnit_Framework_TestCase
|
||||
$this->setDriverPrepareFunction();
|
||||
|
||||
$sql = $this->driver->delete('users', 'name=tony');
|
||||
$this->assertEquals('DELETE FROM `users` WHERE name=tony', $sql);
|
||||
$this->assertSame('DELETE FROM `users` WHERE name=tony', $sql);
|
||||
}
|
||||
|
||||
public function testDeleteWithWHEREKeyArray()
|
||||
@ -124,15 +129,15 @@ class SqlDbDriverTest extends PHPUnit_Framework_TestCase
|
||||
$this->setDriverPrepareFunction();
|
||||
|
||||
$sql = $this->driver->delete('users', array('name=tony' => 0));
|
||||
$this->assertEquals('DELETE FROM `users` WHERE name=tony', $sql);
|
||||
$this->assertSame('DELETE FROM `users` WHERE name=tony', $sql);
|
||||
}
|
||||
|
||||
public function testDeleteWithWHEREDbExpr()
|
||||
{
|
||||
$this->setDriverPrepareFunction();
|
||||
|
||||
|
||||
$sql = $this->driver->delete('users', new DbExpr('name=tony'));
|
||||
$this->assertEquals('DELETE FROM `users` WHERE name=tony', $sql);
|
||||
$this->assertSame('DELETE FROM `users` WHERE name=tony', $sql);
|
||||
}
|
||||
|
||||
protected function setDriverPrepareFunction()
|
||||
|
Reference in New Issue
Block a user