Ejemplo n.º 1
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"));
 }
 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);
 }