[limb-svn] r6869 - in 3.x/trunk/limb: active_record/tests/cases dbal/src/toolkit dbal/tests/cases web_app/tests/cases

svn at limb-project.com svn at limb-project.com
Sun Mar 30 12:21:58 MSD 2008


Author: pachanga
Date: 2008-03-30 12:21:57 +0400 (Sun, 30 Mar 2008)
New Revision: 6869
URL: http://fisheye.limb-project.com/changelog/limb/?cs=6869

Modified:
   3.x/trunk/limb/active_record/tests/cases/.setup.php
   3.x/trunk/limb/dbal/src/toolkit/lmbDbTools.class.php
   3.x/trunk/limb/dbal/tests/cases/.setup.php
   3.x/trunk/limb/web_app/tests/cases/.setup.php
Log:
-- lmbDbTools::isDefaultDbDsnAvailable() added-- tests use sqlite database by default

Modified: 3.x/trunk/limb/active_record/tests/cases/.setup.php
===================================================================
--- 3.x/trunk/limb/active_record/tests/cases/.setup.php	2008-03-30 08:20:27 UTC (rev 6868)
+++ 3.x/trunk/limb/active_record/tests/cases/.setup.php	2008-03-30 08:21:57 UTC (rev 6869)
@@ -1,5 +1,20 @@
 <?php
+if(!defined('LIMB_VAR_DIR'))
+{
+  @define('LIMB_VAR_DIR', dirname(__FILE__) . '/../../../var');
+  if(!is_dir(LIMB_VAR_DIR) && !mkdir(LIMB_VAR_DIR))
+    throw new Exception("Could not create LIMB_VAR_DIR at '" . LIMB_VAR_DIR . "' during tests execution");
+}
+
 require_once(dirname(__FILE__) . '/../../common.inc.php');
+if(!lmbToolkit::instance()->isDefaultDbDsnAvailable())
+{
+  $dsn = 'sqlite://localhost/' . LIMB_VAR_DIR . '/sqlite_tests.db';
+  echo "Using default sqlite test database '$dsn'\n";
+  lmbToolkit::instance()->setDefaultDbDSN($dsn);
+}
+
+require_once(dirname(__FILE__) . '/../../common.inc.php');
 require_once('limb/dbal/src/lmbDbDump.class.php');
 require_once('limb/core/src/lmbSet.class.php');
 require_once('limb/core/src/lmbCollection.class.php');

Modified: 3.x/trunk/limb/dbal/src/toolkit/lmbDbTools.class.php
===================================================================
--- 3.x/trunk/limb/dbal/src/toolkit/lmbDbTools.class.php	2008-03-30 08:20:27 UTC (rev 6868)
+++ 3.x/trunk/limb/dbal/src/toolkit/lmbDbTools.class.php	2008-03-30 08:21:57 UTC (rev 6869)
@@ -20,8 +20,8 @@
  */
 class lmbDbTools extends lmbAbstractTools
 {
-  protected $_db_configs = array('dsn' => null);
-  protected $_connections = array('dsn' => null);
+  protected $db_configs = array('dsn' => null);
+  protected $connections = array('dsn' => null);
   protected $cache_db_info = true;
   protected $db_info = array();
   protected $db_tables = array();
@@ -37,23 +37,42 @@
     return $this->db_env;
   }
 
+  function setDefaultDbDSN($dsn)
+  {
+    $this->setDbDSNByName('dsn', $dsn);
+  }
+
+  function getDefaultDbDSN()
+  {
+    return $this->getDbDSNByName('dsn');
+  }
+
+  function isDefaultDbDsnAvailable()
+  {
+    try
+    {
+      $dsn = $this->getDefaultDbDSN();
+      if(!$dsn)
+        return true;
+    }
+    catch(lmbException $e)
+    {
+      return false;
+    }
+  }
+
   function setDbDSNByName($name, $dsn)
   {
     if(is_object($dsn))
-      $this->_db_configs[$name] = $dsn;
+      $this->db_configs[$name] = $dsn;
     else
-      $this->_db_configs[$name] = new lmbDbDSN($dsn);
+      $this->db_configs[$name] = new lmbDbDSN($dsn);
   }
 
-  function setDefaultDbDSN($dsn)
-  {
-    $this->setDbDSNByName('dsn', $dsn);
-  }
-
   function getDbDSNByName($name)
   {
-    if(isset($this->_db_configs[$name]) && is_object($this->_db_configs[$name]))
-      return $this->_db_configs[$name];
+    if(isset($this->db_configs[$name]) && is_object($this->db_configs[$name]))
+      return $this->db_configs[$name];
 
     $conf = $this->toolkit->getConf('db');
 
@@ -71,14 +90,9 @@
       $this->setDbDSNByName($name, new lmbDbDSN($env[$name]));
     }
 
-    return $this->_db_configs[$name];
+    return $this->db_configs[$name];
   }
 
-  function getDefaultDbDSN()
-  {
-    return $this->getDbDSNByName('dsn');
-  }
-
   function getDbDSN($env)
   {
     $conf = $this->toolkit->getConf('db');
@@ -92,26 +106,26 @@
 
   function setDbConnectionByName($name, $conn)
   {
-    $this->_connections[$name] = $conn;
+    $this->connections[$name] = $conn;
   }
 
-  function setDefaultDbConnection($conn)
-  {
-    $this->setDbConnectionByName('dsn', $conn);
-  }
-
   function getDbConnectionByName($name)
   {
-    if(isset($this->_connections[$name]) && is_object($this->_connections[$name]))
-      return $this->_connections[$name];
+    if(isset($this->connections[$name]) && is_object($this->connections[$name]))
+      return $this->connections[$name];
 
     if(!is_object($dsn = $this->toolkit->getDbDSNByName($name)))
       throw new lmbException($name . ' database DSN is not valid');
 
     $this->setDbConnectionByName($name, $this->createDbConnection($dsn));
-    return $this->_connections[$name];
+    return $this->connections[$name];
   }
 
+  function setDefaultDbConnection($conn)
+  {
+    $this->setDbConnectionByName('dsn', $conn);
+  }
+
   function getDefaultDbConnection()
   {
     return $this->getDbConnectionByName('dsn');

Modified: 3.x/trunk/limb/dbal/tests/cases/.setup.php
===================================================================
--- 3.x/trunk/limb/dbal/tests/cases/.setup.php	2008-03-30 08:20:27 UTC (rev 6868)
+++ 3.x/trunk/limb/dbal/tests/cases/.setup.php	2008-03-30 08:21:57 UTC (rev 6869)
@@ -5,3 +5,12 @@
   if(!is_dir(LIMB_VAR_DIR) && !mkdir(LIMB_VAR_DIR))
     throw new Exception("Could not create LIMB_VAR_DIR at '" . LIMB_VAR_DIR . "' during tests execution");
 }
+
+require_once(dirname(__FILE__) . '/../../common.inc.php');
+if(!lmbToolkit::instance()->isDefaultDbDsnAvailable())
+{
+  $dsn = 'sqlite://localhost/' . LIMB_VAR_DIR . '/sqlite_tests.db';
+  echo "Using default sqlite test database '$dsn'\n";
+  lmbToolkit::instance()->setDefaultDbDSN($dsn);
+}
+

Modified: 3.x/trunk/limb/web_app/tests/cases/.setup.php
===================================================================
--- 3.x/trunk/limb/web_app/tests/cases/.setup.php	2008-03-30 08:20:27 UTC (rev 6868)
+++ 3.x/trunk/limb/web_app/tests/cases/.setup.php	2008-03-30 08:21:57 UTC (rev 6869)
@@ -1,5 +1,15 @@
 <?php
+if(!defined('LIMB_VAR_DIR'))
+{
+  @define('LIMB_VAR_DIR', dirname(__FILE__) . '/../../../var');
+  if(!is_dir(LIMB_VAR_DIR) && !mkdir(LIMB_VAR_DIR))
+    throw new Exception("Could not create LIMB_VAR_DIR at '" . LIMB_VAR_DIR . "' during tests execution");
+}
 
 require_once(dirname(__FILE__) . '/../../common.inc.php');
-
-
+if(!lmbToolkit::instance()->isDefaultDbDsnAvailable())
+{
+  $dsn = 'sqlite://localhost/' . LIMB_VAR_DIR . '/sqlite_tests.db';
+  echo "Using default sqlite test database '$dsn'\n";
+  lmbToolkit::instance()->setDefaultDbDSN($dsn);
+}



More information about the limb-svn mailing list