function _createIniFileNames()
 {
     $name = mt_rand();
     $file = lmb_var_dir() . '/tmp_ini/' . $name . '.ini';
     $override_file = lmb_var_dir() . '/tmp_ini/' . $name . '.override.ini';
     return array($file, $override_file);
 }
 function testCacheCreation()
 {
     $cache_dir = lmb_var_dir() . '/some_dir';
     $cache = lmbCacheFactory::createConnection('file://' . $cache_dir);
     $this->assertEqual('file', $cache->getType());
     $this->assertEqual($cache_dir, $cache->getCacheDir());
 }
 function aggregate()
 {
     if (!rename($this->log_file, $new_name = tempnam(lmb_var_dir(), 'cache_log_aggregator'))) {
         throw new lmbException('Can\'t move file', array('source' => $this->log_file, 'destination' => $new_name));
     }
     $cmd = "cat " . $new_name . ' | awk \' {if($NF>1){data[$2"/"$1]++;}} END{for(i in data){print i"/"data[i];}}\'';
     $output = array();
     exec($cmd, $output);
     unlink($new_name);
     $info = array();
     foreach ($output as $string) {
         list($cache_name, $result, $count) = explode('/', $string);
         if (!isset($info[$cache_name])) {
             $info[$cache_name] = array();
         }
         if (lmbCacheLog::PREFIX_HIT === $result) {
             $info[$cache_name]['hits_count'] = $count;
         } elseif (lmbCacheLog::PREFIX_MISS === $result) {
             $info[$cache_name]['misses_count'] = $count;
         } else {
             throw new lmbException('WTF?', array($string));
         }
     }
     return $info;
 }
 function setUp()
 {
     parent::setUp();
     $this->conn = lmbToolkit::instance()->getDefaultDbConnection();
     $dir_for_tests = lmb_var_dir() . '/constructor/';
     $this->dir_for_test_case = $dir_for_tests . '/' . get_class($this);
     lmbFs::mkdir($this->dir_for_test_case);
 }
 function _createIniFile($contents, &$override_file = null)
 {
     $name = mt_rand();
     $file = lmb_var_dir() . '/tmp_ini/' . $name . '.ini';
     $override_file = lmb_var_dir() . '/tmp_ini/' . $name . '.override.ini';
     file_put_contents($file, $contents);
     return $file;
 }
 function testPackageInclude_CustomPath()
 {
     $this->createPackageMainFile('include_custom', lmb_var_dir());
     lmb_package_require('include_custom', lmb_var_dir());
     $this->assertTrue(lmb_package_registered('include_custom'));
     $this->assertTrue(lmb_Var_dir() . '/include_custom', lmb_package_get_path('include_custom'));
     $this->assertIdentical(1, lmbPackagesFunctionsTest::$counter);
 }
Exemple #7
0
function lmb_tests_init_var_dir($value)
{
    if (file_exists($value)) {
        lmbFs::rm($value);
    }
    lmbFs::mkdir($value);
    $real = realpath($value) . '/';
    lmb_var_dir($real);
}
 function testWrite()
 {
     $dsn = new lmbUri('file://' . lmb_var_dir() . '/logs/error' . uniqid() . '.log');
     $writer = new lmbLogFileWriter($dsn);
     $entry = new lmbLogEntry(LOG_ERR, 'foo');
     $writer->write($entry);
     $content = file_get_contents($writer->getLogFile());
     $this->assertPattern('/Error/', $content);
     $this->assertPattern('/foo/', $content);
 }
 function testWrite()
 {
     $php_log = lmb_var_dir() . '/php.log';
     ini_set('error_log', $php_log);
     $writer = new lmbLogPHPLogWriter(new lmbUri());
     $writer->write(new lmbLogEntry(LOG_ERR, 'foo'));
     $content = file_get_contents($php_log);
     $this->assertPattern('/Error/', $content);
     $this->assertPattern('/foo/', $content);
 }
 function testParse()
 {
     $dsn = lmb_var_dir() . '/input_stream';
     $params = 'foo_1=bar_1&foo_2=bar_2';
     file_put_contents($dsn, $params);
     $input_stream_parser = new lmbInputStreamParser();
     $parsed_params = $input_stream_parser->parse($dsn);
     $this->assertEqual($parsed_params['foo_1'], 'bar_1');
     $this->assertEqual($parsed_params['foo_2'], 'bar_2');
 }
 function setUp()
 {
     if (!is_dir(lmb_var_dir())) {
         mkdir(lmb_var_dir());
     }
     $this->tmp_dir = lmb_var_dir() . '/lmb_require/';
     $this->_rm($this->tmp_dir);
     mkdir($this->tmp_dir);
     $this->env = $_ENV;
 }
 function setUp()
 {
     lmbToolkit::save();
     $this->toolkit = lmbToolkit::merge(new lmbConfTools());
     $this->application_configs_dir = lmb_var_dir() . '/app/settings';
     lmbFs::mkdir($this->application_configs_dir);
     $this->package_configs_dir = lmb_var_dir() . '/package/settings';
     lmbFs::mkdir($this->package_configs_dir);
     $tests_include_apth = $this->application_configs_dir . ';' . $this->package_configs_dir;
     $this->toolkit->setConfIncludePath($tests_include_apth);
 }
 function setUp()
 {
     $this->base_dir = lmb_var_dir() . '/tpl';
     $this->tpl_dir = $this->base_dir;
     $this->cache_dir = $this->base_dir . '/compiled';
     $this->tags_dir = dirname(__FILE__) . '/../../src/tags';
     $this->filters_dir = dirname(__FILE__) . '/../../src/filters';
     lmbFs::rm(lmb_var_dir());
     lmbFs::mkdir(lmb_var_dir());
     lmbFs::mkdir($this->base_dir);
     lmbFs::mkdir($this->tpl_dir);
     lmbFs::mkdir($this->cache_dir);
 }
 function testWrite_SetEntryTitle()
 {
     $toolkit = lmbToolkit::instance();
     $toolkit->setLogEntryTitle('some_title');
     $dsn = new lmbUri('file://' . lmb_var_dir() . '/logs/info' . uniqid() . '.log');
     $conf = array('logs' => array('foo' => $dsn));
     $toolkit->setConf('log', $conf);
     $toolkit->log('message', $level = LOG_INFO, $params = array(), null, $log_name = 'foo');
     $writers = $toolkit->getLog('foo')->getWriters();
     $this->assertIsA($writers[0], 'lmbLogFileWriter');
     $content = file_get_contents($writers[0]->getLogFile());
     $this->assertPattern('/some_title/', $content);
     $this->assertPattern('/Info/', $content);
     $this->assertPattern('/message/', $content);
 }
Exemple #15
0
function lmb_tests_init_db_dsn()
{
    lmb_env_set('LIMB_CACHE_DB_META_IN_FILE', false);
    if (lmbToolkit::instance()->isDefaultDbDSNAvailable()) {
        $dsn = lmbToolkit::instance()->getDefaultDbDSN();
        static $reported_about;
        if (is_null($reported_about) || $reported_about != $dsn) {
            $pass = $dsn->_getUri()->getPassword();
            $masked_dsn = str_replace($pass, str_pad('*', strlen($pass), '*'), $dsn->toString());
            echo "INFO: Using database '{$masked_dsn}'\n";
            $reported_about = $dsn;
        }
    } else {
        $default_value = 'sqlite://localhost/' . lmb_var_dir() . '/sqlite_tests.db';
        $dsn = lmb_env_get('LIMB_TEST_DB_DSN', $default_value);
        lmbToolkit::instance()->setDefaultDbDSN($dsn);
        echo "INFO: Using default test database '{$dsn}'\n";
    }
}
 function __construct()
 {
     $dir = lmb_var_dir() . '/cache2';
     $this->dsn = 'file:///' . $dir . '?wrapper[]=mint&wrapper[]=taggable';
 }
 function __construct()
 {
     $this->dsn = 'file:///' . lmb_var_dir() . '/cache2';
 }
 function setUp()
 {
     $this->cache = new lmbTaggableCacheWrapper(lmbCacheFactory::createConnection('file:///' . lmb_var_dir() . '/cache'));
 }
 function _createIni($contents)
 {
     file_put_contents($file = lmb_var_dir() . '/tmp_ini/' . mt_rand() . '.ini', $contents);
     return new lmbCachedIni($file, $this->cache_dir);
 }
 function __construct()
 {
     $dir = lmb_var_dir() . '/cache';
     $this->dsn = 'file:///' . $dir . '?need_serialization=0';
 }
 function _writeToFile($serialized)
 {
     $tmp_serialized_file = lmb_var_dir() . '/serialized.' . mt_rand() . uniqid();
     file_put_contents($tmp_serialized_file, $serialized);
     return $tmp_serialized_file;
 }
    protected function _makeCallFromDifferentThread($method, $arguments)
    {
        $filename = lmb_var_dir() . '/diff_thread.php';
        $cur_file_dir = dirname(__FILE__);
        $include_path = get_include_path();
        $cur_process_dir = getcwd();
        $arguments_str = implode("', '", $arguments);
        $setup_file = realpath($cur_file_dir . '/../../../common.inc.php');
        if (lmb_env_has('LIMB_DB_DSN')) {
            $limb_db_dsn = "lmb_env_setor('LIMB_DB_DSN', '" . lmb_env_get('LIMB_DB_DSN') . "');";
        } else {
            $limb_db_dsn = '';
        }
        if (lmb_env_has('LIMB_VAR_DIR')) {
            $limb_var_dir = "lmb_env_setor('LIMB_VAR_DIR', '" . lmb_env_get('LIMB_VAR_DIR') . "');";
        } else {
            $limb_var_dir = '';
        }
        if ($this->storage_init_file) {
            $storage_init_file = "lmb_require('{$this->storage_init_file}');";
        } else {
            $storage_init_file = '';
        }
        $request_code = <<<EOD
<?php
    ob_start();
    chdir('{$cur_process_dir}');
    set_include_path('{$include_path}');
    require_once('{$setup_file}');

    {$limb_db_dsn}
    {$limb_var_dir}
    {$storage_init_file}

    lmb_require('limb/cache2/src/lmbCacheFactory.class.php');
    \$cache = lmbCacheFactory::createConnection('{$this->dsn}');
    ob_end_clean();
    echo serialize(\$cache->{$method}('{$arguments_str}'));
EOD;
        file_put_contents($filename, $request_code);
        $response = shell_exec("php {$filename}");
        $result = unserialize($response);
        if (false === $result) {
            throw new lmbException("Can't parse response", array('response' => $response));
        } else {
            return $result;
        }
    }
Exemple #23
0
function lmb_tests_cleanup_var_dir()
{
    $var_dir = lmb_var_dir();
    lmbFs::rm($var_dir);
    echo "INFO: Var dir cleaned up in {$var_dir}\n";
}
    function _createCommandClass($class, $execute_body = null, $validate_body = null, $help_body = null, $constructor_body = null)
    {
        if (!$constructor_body) {
            $constructor_body = '';
        }
        if (!$execute_body) {
            $execute_body = 'function execute() {}';
        }
        if (!$validate_body) {
            $validate_body = 'function validate() { return true; }';
        }
        if (!$help_body) {
            $help_body = 'function help() {}';
        }
        $php = <<<EOD
<?php
class {$class} extends lmbCliBaseCmd
{
  {$constructor_body}
  {$execute_body}
  {$validate_body}
  {$help_body}
}
?>
EOD;
        $file = lmb_var_dir() . '/tmp_cmd/' . $class . '.class.php';
        file_put_contents($file, $php);
        return $file;
    }
 function testLmbVarDir_Set()
 {
     $old_value = lmb_env_get('LIMB_VAR_DIR');
     $new_value = $old_value . '/';
     lmb_var_dir($new_value);
     $this->assertIdentical($new_value, lmb_var_dir());
     lmb_env_set('LIMB_VAR_DIR', $old_value);
 }
 function getDefaultLog()
 {
     return $this->createLog('file://' . lmb_var_dir() . '/logs/error.log');
 }
 protected function _getConfigPath($config_name)
 {
     return lmb_var_dir() . '/configs/' . $config_name;
 }
 function testLogException_testDefaultLogName()
 {
     $log_file_path_1 = 'file://' . lmb_var_dir() . 'testLogException_testDefaultLogName_1';
     $log_file_path_2 = 'file://' . lmb_var_dir() . 'testLogException_testDefaultLogName_2';
     $conf = array('logs' => array('foo' => $log_file_path_1, 'default' => $log_file_path_2));
     $this->toolkit->setConf('log', $conf);
     $this->toolkit->setLogEntryTitle('entry title');
     $this->toolkit->logException(new lmbInvalidArgumentException('exmessage', $code = 42));
     $log_file_content = file_get_contents($log_file_path_2);
     $this->assertPattern('/exmessage/', $log_file_content);
 }
 function testGetPartialHtmlCacheStorage()
 {
     $cache = new lmbCacheFileConnection('file://' . lmb_var_dir() . '/cache2/testGetPartialHtmlCacheStorage');
     lmbToolkit::instance()->setCache('default', $cache);
     $this->assertEqual(lmbToolkit::instance()->getPartialHtmlCacheStorage(), $cache);
 }
 function _createIni($contents)
 {
     file_put_contents($file = lmb_var_dir() . '/tmp_ini/' . mt_rand() . '.ini', $contents);
     return new lmbIni($file);
 }