[limb-svn] r5851 - in 3.x/trunk/limb/dbal: src src/toolkit tests/cases/non-driver
svn at limb-project.com
svn at limb-project.com
Thu May 10 12:52:00 MSD 2007
Author: pachanga
Date: 2007-05-10 12:52:00 +0400 (Thu, 10 May 2007)
New Revision: 5851
URL: http://fisheye.limb-project.com/changelog/limb/?cs=5851
Added:
3.x/trunk/limb/dbal/tests/cases/non-driver/lmbDBALTest.class.php
Modified:
3.x/trunk/limb/dbal/src/lmbDBAL.class.php
3.x/trunk/limb/dbal/src/toolkit/lmbDbTools.class.php
Log:
-- lmbDBAL :: query($sql, $conn=null) added, it simply returns record set for select query
-- lmbDBAL :: execute($sql, $conn=null) added, it simply executes sql
-- lmbDBAL tests added
-- lmbDbTools :: setDefaultDbDSN($dsn) wraps $dsn with lmbDbDSN only if it's a string
Modified: 3.x/trunk/limb/dbal/src/lmbDBAL.class.php
===================================================================
--- 3.x/trunk/limb/dbal/src/lmbDBAL.class.php 2007-05-10 07:31:09 UTC (rev 5850)
+++ 3.x/trunk/limb/dbal/src/lmbDBAL.class.php 2007-05-10 08:52:00 UTC (rev 5851)
@@ -14,7 +14,7 @@
{
static function setDefaultDSN($dsn)
{
- require_once('limb/dbal/toolkit.inc.php');
+ lmb_require('limb/dbal/toolkit.inc.php');
lmbToolkit :: instance()->setDefaultDbDSN($dsn);
}
@@ -29,6 +29,23 @@
lmb_require($file);
return new $class($dsn);
}
+
+ static function query($sql, $conn = null)
+ {
+ if(!$conn)
+ $conn = lmbToolkit :: instance()->getDefaultDbConnection();
+
+ $stmt = $conn->newStatement($sql);
+ return $stmt->getRecordSet();
+ }
+
+ static function execute($sql, $conn = null)
+ {
+ if(!$conn)
+ $conn = lmbToolkit :: instance()->getDefaultDbConnection();
+
+ $conn->execute($sql);
+ }
}
?>
\ No newline at end of file
Modified: 3.x/trunk/limb/dbal/src/toolkit/lmbDbTools.class.php
===================================================================
--- 3.x/trunk/limb/dbal/src/toolkit/lmbDbTools.class.php 2007-05-10 07:31:09 UTC (rev 5850)
+++ 3.x/trunk/limb/dbal/src/toolkit/lmbDbTools.class.php 2007-05-10 08:52:00 UTC (rev 5851)
@@ -24,7 +24,10 @@
function setDefaultDbDSN($conf)
{
- $this->default_db_config = new lmbDbDSN($conf);
+ if(is_object($conf))
+ $this->default_db_config = $conf;
+ else
+ $this->default_db_config = new lmbDbDSN($conf);
}
function getDefaultDbDSN()
Added: 3.x/trunk/limb/dbal/tests/cases/non-driver/lmbDBALTest.class.php
===================================================================
--- 3.x/trunk/limb/dbal/tests/cases/non-driver/lmbDBALTest.class.php (rev 0)
+++ 3.x/trunk/limb/dbal/tests/cases/non-driver/lmbDBALTest.class.php 2007-05-10 08:52:00 UTC (rev 5851)
@@ -0,0 +1,87 @@
+<?php
+/**
+ * Limb Web Application Framework
+ *
+ * @link http://limb-project.com
+ *
+ * @copyright Copyright © 2004-2007 BIT
+ * @license LGPL http://www.gnu.org/copyleft/lesser.html
+ * @version $Id: lmbSimpleDbTest.class.php 4994 2007-02-08 15:36:08Z pachanga $
+ * @package dbal
+ */
+lmb_require('limb/dbal/src/lmbDBAL.class.php');
+lmb_require('limb/dbal/src/drivers/lmbDbConnection.interface.php');
+lmb_require('limb/dbal/src/drivers/lmbDbQueryStatement.interface.php');
+
+Mock::generate('lmbDbConnection', 'MockDbConnection');
+Mock::generate('lmbDbQueryStatement', 'MockDbQueryStatement');
+
+class lmbDBALTest extends UnitTestCase
+{
+ protected $toolkit;
+ protected $dsn;
+ protected $conn;
+
+ function setUp()
+ {
+ $this->toolkit = lmbToolkit :: save();
+ $this->dsn = $this->toolkit->getDefaultDbDSN();
+ $this->conn = new MockDbConnection();
+ }
+
+ function tearDown()
+ {
+ lmbToolkit :: restore();
+ }
+
+ function testSetDefaultDSN()
+ {
+ lmbDBAL :: setDefaultDSN($boo = new lmbObject());
+ $this->assertEqual($this->toolkit->getDefaultDbDSN(), $boo);
+ }
+
+ function testNewConnection()
+ {
+ $conn = lmbDBAL :: newConnection($this->dsn);
+ $this->assertIsA($conn, 'lmbDbConnection');
+ }
+
+ function testExecute()
+ {
+ $this->conn->expectOnce('execute', array($sql = 'SELECT 1=1'));
+ lmbDBAL :: execute($sql, $this->conn);
+ }
+
+ function testExecuteDefaultConnection()
+ {
+ $this->toolkit->setDefaultDbConnection($this->conn);
+ $this->conn->expectOnce('execute', array($sql = 'SELECT 1=1'));
+ lmbDBAL :: execute('SELECT 1=1');
+ }
+
+ function testQuery()
+ {
+ $stmt = new MockDbQueryStatement();
+ $this->conn->expectOnce('newStatement', array($sql = 'SELECT 1=1'));
+ $this->conn->setReturnValue('newStatement', $stmt, array($sql));
+ $stmt->expectOnce('getRecordSet');
+ $stmt->setReturnValue('getRecordSet', 'result');
+
+ $rs = lmbDBAL :: query($sql, $this->conn);
+ $this->assertEqual($rs, 'result');
+ }
+
+ function testQueryDefaultConnection()
+ {
+ $this->toolkit->setDefaultDbConnection($this->conn);
+ $stmt = new MockDbQueryStatement();
+ $this->conn->expectOnce('newStatement', array($sql = 'SELECT 1=1'));
+ $this->conn->setReturnValue('newStatement', $stmt, array($sql));
+ $stmt->expectOnce('getRecordSet');
+ $stmt->setReturnValue('getRecordSet', 'result');
+
+ $rs = lmbDBAL :: query($sql);
+ $this->assertEqual($rs, 'result');
+ }
+}
+?>
More information about the limb-svn
mailing list