mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-08 07:32:48 +08:00
暂时先加上 单元测试test根命名空间注册
This commit is contained in:
@@ -17,9 +17,9 @@ namespace think;
|
|||||||
class Db
|
class Db
|
||||||
{
|
{
|
||||||
// 数据库连接实例
|
// 数据库连接实例
|
||||||
private static $instance = [];
|
private static $instances = [];
|
||||||
// 当前数据库连接实例
|
// 当前数据库连接实例
|
||||||
private static $_instance = null;
|
private static $instance = null;
|
||||||
// 查询次数
|
// 查询次数
|
||||||
public static $queryTimes = 0;
|
public static $queryTimes = 0;
|
||||||
// 执行次数
|
// 执行次数
|
||||||
@@ -36,15 +36,15 @@ class Db
|
|||||||
public static function instance($config = [], $lite = false)
|
public static function instance($config = [], $lite = false)
|
||||||
{
|
{
|
||||||
$md5 = md5(serialize($config));
|
$md5 = md5(serialize($config));
|
||||||
if (!isset(self::$instance[$md5])) {
|
if (!isset(self::$instances[$md5])) {
|
||||||
// 解析连接参数 支持数组和字符串
|
// 解析连接参数 支持数组和字符串
|
||||||
$options = self::parseConfig($config);
|
$options = self::parseConfig($config);
|
||||||
// 如果采用lite方式 仅支持原生SQL 包括query和execute方法
|
// 如果采用lite方式 仅支持原生SQL 包括query和execute方法
|
||||||
$class = $lite ? '\\think\\db\\Lite' : '\\think\\db\\driver\\' . ucwords($options['type']);
|
$class = $lite ? '\\think\\db\\Lite' : '\\think\\db\\driver\\' . ucwords($options['type']);
|
||||||
self::$instance[$md5] = new $class($options);
|
self::$instances[$md5] = new $class($options);
|
||||||
}
|
}
|
||||||
self::$_instance = self::$instance[$md5];
|
self::$instance = self::$instances[$md5];
|
||||||
return self::$_instance;
|
return self::$instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -106,6 +106,6 @@ class Db
|
|||||||
// 调用驱动类的方法
|
// 调用驱动类的方法
|
||||||
public static function __callStatic($method, $params)
|
public static function __callStatic($method, $params)
|
||||||
{
|
{
|
||||||
return call_user_func_array([self::$_instance, $method], $params);
|
return call_user_func_array([self::$instance, $method], $params);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,6 +46,6 @@ if (APP_HOOK && isset($mode['tags'])) {
|
|||||||
if (APP_AUTO_BUILD && is_file(APP_PATH . 'build.php')) {
|
if (APP_AUTO_BUILD && is_file(APP_PATH . 'build.php')) {
|
||||||
Build::run(include APP_PATH . 'build.php');
|
Build::run(include APP_PATH . 'build.php');
|
||||||
}
|
}
|
||||||
|
Loader::addNamespace('tests', TEST_PATH);
|
||||||
// 执行应用
|
// 执行应用
|
||||||
!IN_UNIT_TEST && App::run();
|
!IN_UNIT_TEST && App::run();
|
||||||
|
|||||||
Reference in New Issue
Block a user