Ejemplo n.º 1
0
function directoryList($path, $omit = '')
{
    $arr = scandir($path);
    $list = array();
    foreach ($arr as $file) {
        if ($file == '.' || $file == '..') {
            continue;
        }
        $real_path = $path . DIRECTORY_SEPARATOR . $file;
        $real_name = str_replace($omit, "", $real_path);
        if (is_dir($real_path)) {
            $list[] = array('is_dir' => true, 'name' => str_replace(".php", "", $file), 'list' => directoryList($real_path, $omit), 'path' => $real_name);
        } else {
            $content = file_get_contents($real_path);
            $temp = explode("-->", $content);
            $json = array();
            if (count($temp) > 1) {
                $temp2 = explode("<!--", $temp[0]);
                $json = (array) json_decode($temp2[1]);
            }
            $list[] = array('is_dir' => false, 'name' => str_replace(".php", "", $file), 'info' => $json, 'path' => $real_name);
        }
    }
    usort($list, function ($a, $b) {
        if ($a['list'] && !$b['list']) {
            return -1;
        } else {
            if (!$a['list'] && $b['list']) {
                return 1;
            }
        }
        return $a['name'] < $b['name'] ? -1 : 1;
    });
    return $list;
}
Ejemplo n.º 2
0
function directoryList($path, $omit = '')
{
    $arr = scandir($path);
    $list = array();
    foreach ($arr as $file) {
        if ($file == '.' || $file == '..') {
            continue;
        }
        $real_path = $path . DIRECTORY_SEPARATOR . $file;
        $real_name = str_replace($omit, "", $real_path);
        if (is_dir($real_path)) {
            $list[] = array('is_dir' => true, 'name' => $file, 'list' => directoryList($real_path, $omit), 'path' => $real_name);
        } else {
            $list[] = array('is_dir' => false, 'name' => $file, 'path' => $real_name);
        }
    }
    usort($list, function ($a, $b) {
        if ($a['list'] && !$b['list']) {
            return -1;
        } else {
            if (!$a['list'] && $b['list']) {
                return 1;
            }
        }
        return $a['name'] < $b['name'] ? -1 : 1;
    });
    return $list;
}
Ejemplo n.º 3
0
function directoryList($path, $omit = '')
{
    $arr = scandir($path);
    $list = array();
    foreach ($arr as $file) {
        if ($file == '.' || $file == '..') {
            continue;
        }
        $real_path = $path . DIRECTORY_SEPARATOR . $file;
        $real_name = str_replace($omit, "", $real_path);
        if (is_dir($real_path)) {
            $dir = array('is_dir' => true, 'name' => $file, 'list' => directoryList($real_path, $omit), 'path' => $real_name);
            $infofile = $real_path . DIRECTORY_SEPARATOR . 'package.json';
            $dir['info'] = json_decode(@file_get_contents($infofile));
            $list[] = $dir;
        }
    }
    usort($list, function ($a, $b) {
        if ($a['list'] && !$b['list']) {
            return -1;
        } else {
            if (!$a['list'] && $b['list']) {
                return 1;
            }
        }
        return $a['name'] < $b['name'] ? -1 : 1;
    });
    return $list;
}
 public function runUnitTests()
 {
     $this->info('<h1>Running Unit Tests</h1>');
     $list = directoryList('packages/' . str_replace('.', '/', $this->packageName()), true);
     foreach ($list as $dir => $files) {
         foreach ($files as $file) {
             if (strpos($file, '.class.php') !== FALSE && strpos($file, '.swp') === FALSE) {
                 $path = $dir . '/' . $file;
                 $res = exec('php -f ' . $path);
                 $classname = rsFileToClass($file);
                 require_once $path;
                 $obj = new $classname($this->packageName());
                 if ($obj instanceof UnitTest) {
                     $obj->run();
                 }
             }
         }
     }
 }
Ejemplo n.º 5
0
 public function testForParseErrors()
 {
     $this->info('<h1>Testing for Parse Errors</h1>');
     $list = directoryList('packages/' . str_replace('.', '/', $this->packageName()), true);
     foreach ($list as $dir => $files) {
         foreach ($files as $file) {
             if (strpos($file, '.class.php') !== FALSE && strpos($file, '.swp') === FALSE) {
                 $path = $dir . '/' . $file;
                 $res = exec('php -f ' . $path);
                 $classname = rsFileToClass($file);
                 if (strpos($res, 'Parse error') !== FALSE) {
                     $this->error('Parse error for: ' . $classname . ': ' . $res, 'Look at the parse error and fix it in ' . $path);
                     $this->fail();
                 } else {
                     require_once $path;
                     $this->info('Successfully required ' . $classname);
                 }
             }
         }
     }
 }
Ejemplo n.º 6
0
function rsGetConfig()
{
    $list = directoryList('packages', true);
    $data = '';
    foreach ($list as $dir => $files) {
        foreach ($files as $file) {
            if (strpos($file, 'config.php') !== FALSE) {
                require_once $dir . '/' . $file;
                $data .= file_get_contents($dir . '/' . $file);
            }
        }
    }
    $data = preg_replace('/define\\(([^,]*),([^)]*);/', 'if(!defined(\\1){define(\\1,\\2);}', $data);
    $data = str_replace('<?php', '', $data);
    $data = str_replace('?>', '', $data);
    $data = '<?php 
' . $data . '
?>';
    file_put_contents('managed_code/rs_config.php', $data);
    @chmod('managed_code/rs_config.php', 0664);
}
Ejemplo n.º 7
0
 /**
  * Makes sure that each of your db objects is able to 
  * be inserted, updated and deleted, inserts test data
  * of an appropriate type according to the type of db 
  * field and then inserts and reloads it to ensure the
  * data are identical when reloaded from the db. You
  * can also add a testData method to your db objects
  * that should return appropriate data to test each
  * field when passed the name of that field.
  */
 public function testBasicCrud()
 {
     $this->info('<h1>Testing Basic C.R.U.D</h1>');
     $ret = array();
     $list = directoryList('packages/' . str_replace('.', '/', $this->packageName()), true);
     foreach ($list as $dir => $files) {
         foreach ($files as $file) {
             if (strpos($file, '.class.php') !== FALSE && strpos($file, '.swp') === FALSE) {
                 $path = $dir . '/' . $file;
                 $res = exec('php -f ' . $path);
                 $classname = rsFileToClass($file);
                 if (strpos($res, 'Parse error') !== FALSE) {
                     echo $classname . ': ' . $res . "\n";
                 } else {
                     require_once $path;
                     if (strpos($classname, 'DbObject') === FALSE) {
                         @($obj = new $classname());
                         if ($obj instanceof DbObject) {
                             $ret[] = $classname;
                             echo '<h2>Testing: ' . $classname . '</h2>';
                             $obj->clearTable();
                             echo 'Cleared ' . $obj->tableName() . '<br />';
                             $this->insertNewObjectWithTestData($obj);
                             echo 'Saved: ' . $classname . ': ' . $obj->completeKey() . '<br />';
                             $obj = new $classname();
                             $obj->noForeign();
                             if ($loaded = $obj->fetchSingle()) {
                                 echo 'Loaded: ' . $classname . ': ' . $loaded->completeKey() . '<br />';
                                 foreach ($loaded->fields() as $field) {
                                     if (method_exists($obj, 'testData')) {
                                         $test_data = $obj->testData($field->name());
                                     } else {
                                         $test_data = $this->testData($field->getTypeAsString());
                                     }
                                     $loaded_data = $loaded->get($field->name());
                                     if ($test_data != $loaded_data && $test_data !== FALSE) {
                                         $this->dataModelError($field->name(), $test_data, $loaded_data, 'You need to check your fields in the table definition for: ' . $loaded->tableName());
                                     } else {
                                         $this->info('field: ' . $field->name() . ' is ' . $field->getTypeAsString());
                                     }
                                 }
                                 $obj = new $classname();
                                 try {
                                     $new = $this->insertNewObjectWithTestData($obj);
                                 } catch (DbCrudException $exc) {
                                     $error = 'tried to save a second object and got: ' . $exc->getMessage();
                                     $cause = 'make sure you have an auto increment key in your table if required';
                                     $this->error($error, $cause);
                                 }
                                 $this->info('Saved: ' . $classname . ': ' . $obj->completeKey() . ' (no duplicate keys)');
                                 $loaded->delete();
                                 $new->delete();
                                 $obj = new $classname();
                                 $obj->noForeign();
                                 if (!$obj->fetchSingle()) {
                                     $this->info('Deleted: ' . $classname . ', table is now empty');
                                 } else {
                                     $this->error('Could not delete: ' . $classname, 'Beats me. If you can load it you should be able to delete it! Do some testing. This might be a RocketSled bug');
                                 }
                                 SimpleQuery::create('TRUNCATE ' . $obj->tableName());
                                 $obj->clearQueryCache();
                             } else {
                                 $this->error('Failed to load: ' . $classname, 'This is probably something wrong with the table definition in your data model');
                             }
                         }
                     }
                 }
             }
         }
     }
     return $ret;
 }