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();
                 }
             }
         }
     }
 }
 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);
                 }
             }
         }
     }
 }
Пример #3
0
function rsMapClasses()
{
    global $include_paths;
    $include_paths = array();
    $list = directoryList('packages', true);
    foreach ($list as $dir => $files) {
        foreach ($files as $file) {
            if (strpos($file, 'class.php') !== FALSE) {
                $class_name = rsFileToClass($file);
                $path = $dir . '/' . $file;
                if (!isset($include_paths[$class_name])) {
                    $include_paths[$class_name] = $path;
                } else {
                    $path1 = $include_paths[$class_name];
                    $path2 = $path;
                    throw new NamespaceConflictException('Namespace conflict!', $class_name, $path1, $path2);
                }
            }
        }
    }
    rsPersist();
}
Пример #4
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;
 }