Ejemplo n.º 1
0
 /**
  * config file不存在
  * 
  * @expectedException PHPUnit_Framework_Error
  */
 public function testNotExistsConfigFile()
 {
     $conf = new LtConfig();
     // $conf->configFile = dirname(__FILE__) . "/test_data/conf_not_exists.php";
     $conf->init();
     $conf->loadConfigFile(dirname(__FILE__) . "/test_data/conf_not_exists.php");
 }
Ejemplo n.º 2
0
 /**
  * -------------------------------------------------------------------
  * LtConfig要求: 
  * # 配置文件以return array()形式返回一个配置数组 
  * 
  * -------------------------------------------------------------------
  * LtConfig不在意: 
  * # 配置文件中用什么变量名和常量名 
  * 
  * -------------------------------------------------------------------
  * 本测试用例期望效果:
  * 通过LtConfig类能取到定义在config_file里面的配置信息
  */
 public function testMostUsedWay()
 {
     $conf = new LtConfig();
     $conf->init();
     $conf->loadConfigFile(dirname(__FILE__) . "/test_data/conf.php");
     $this->assertEquals("localhost", $conf->get("db.conn.host"));
     $this->assertEquals($conf->get("misc.test_array"), array("test_array_key_1" => "test_array_value_1", "test_array_key_2" => "test_array_value_2"));
     $this->assertEquals(time(), $conf->get("misc.now"));
 }
Ejemplo n.º 3
0
 /**
  * prepare config
  * @todo 先加载proj/conf下的配置,再加载app/conf下的配置,并自动覆盖重复项
  * 注意避开array_merge的坑
  * 或者,至少做个判断,app/conf不存在,去找proj/conf,不能不加载配置文件
  */
 protected function prepareConfig()
 {
     $this->configHandle = LtObjectUtil::singleton('LtConfig', false);
     if (!$this->devMode) {
         $configFile = 'conf/conf.php';
         $this->configHandle->storeHandle = clone $this->coreCacheHandle;
         $this->configHandle->storeHandle->prefix = $this->coreCacheHandle->prefix . '-conf';
     } else {
         $configFile = 'conf/conf_dev.php';
     }
     $this->configHandle->init();
     if ($this->app_dir && is_file($this->app_dir . $configFile)) {
         $this->configHandle->loadConfigFile($this->app_dir . $configFile);
     }
 }
 public function testPerformance()
 {
     /**
      * 用LtStoreFile作存储层提升性能
      */
     $cacheHandle = new LtStoreFile();
     $cacheHandle->init();
     // 准备confif_file
     $config_file = dirname(__FILE__) . "/test_data/conf.php";
     /**
      * 运行autoloader成功取到一个配置 
      * 这是为了证明:使用LtCache作为LtConfig的存储,功能是正常的
      */
     $conf = new LtConfig();
     $conf->storeHandle = $cacheHandle;
     $conf->loadConfigFile($config_file);
     $conf->init();
     $this->assertEquals("localhost", $conf->get("db.conn.host"));
     /**
      * 运行100次,要求在1秒内运行完
      */
     $base_memory_usage = memory_get_usage();
     $times = 100;
     $startTime = microtime(true);
     for ($i = 0; $i < $times; $i++) {
         $conf->get('db.conn.host');
     }
     $endTime = microtime(true);
     $totalTime = round($endTime - $startTime, 6);
     $averageTime = round($totalTime / $times, 6);
     $memory_usage = memory_get_usage() - $base_memory_usage;
     $averageMemory = formatSize($memory_usage / $times);
     $memory_usage = formatSize($memory_usage);
     if (LOTUS_UNITTEST_DEBUG) {
         echo "\n----------------------config-----------------------------\n";
         echo "times      \t{$times}\n";
         echo "totalTime   \t{$totalTime}s\taverageTime   \t{$averageTime}s\n";
         echo "memoryUsage \t{$memory_usage}\taverageMemory \t{$averageMemory}";
         echo "\n---------------------------------------------------------\n";
     }
     $this->assertTrue(1 > $totalTime);
 }