コード例 #1
0
ファイル: test.php プロジェクト: jasonmoo/DumbledORM
    OrmTest::assertTrue("Creating test database {$dbname}.", true);
} catch (Exception $e) {
    throw new OrmTestException('Unable to create test database.  Probably missing proper config.php or a permissions issue. (' . $e->getMessage() . ')');
}
try {
    Db::execute("CREATE TABLE `{$dbname}`.`user` (\n    `id` int(11) NOT NULL AUTO_INCREMENT,\n    `name` varchar(255) NOT NULL,\n    `email` varchar(255) NOT NULL,\n    `active` tinyint(4) NOT NULL,\n    `created_at` datetime NOT NULL,\n    PRIMARY KEY (`id`)\n  ) ENGINE=InnoDB DEFAULT CHARSET=utf8;");
    Db::execute("CREATE TABLE `{$dbname}`.`phone_number` (\n    `id` int(11) NOT NULL AUTO_INCREMENT,\n    `user_id` int(11) NOT NULL,\n    `number` varchar(255) NOT NULL,\n    `type` varchar(255) NOT NULL,\n    `location` varchar(255),\n    PRIMARY KEY (`id`)\n  ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
    Db::execute("CREATE TABLE `{$dbname}`.`post` (\n    `id` int(11) NOT NULL AUTO_INCREMENT,\n    `user_id` int(11) NOT NULL,\n    `title` varchar(255) NOT NULL,\n    `body` text NOT NULL,\n    PRIMARY KEY (`id`)\n  ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
    Db::execute("CREATE TABLE `{$dbname}`.`post_meta` (\n    `id` int(11) NOT NULL AUTO_INCREMENT,\n    `post_id` int(11) NOT NULL,\n    `key` varchar(255) NOT NULL,\n    `val` varchar(255) NOT NULL,\n    PRIMARY KEY (`id`)\n  ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
    Db::execute("CREATE TABLE `{$dbname}`.`orphan` (\n    `id` int(11) NOT NULL AUTO_INCREMENT,\n    `name` varchar(255) NOT NULL,\n    `age` varchar(255) NOT NULL,\n    PRIMARY KEY (`id`)\n  ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
    OrmTest::assertTrue("Creating test database tables.", true);
} catch (Exception $e) {
    throw new OrmTestException('Unable to create test tables.  Probably a permissions issue. (' . $e->getMessage() . ')');
}
try {
    Builder::generateBase(null, $dbname);
    OrmTest::assertTrue("Checking for generated base classes in ./{$dbname}/base.php.", file_exists("./{$dbname}/base.php"));
    require "./{$dbname}/base.php";
    OrmTest::assertTrue('Checking for generated base classes in php scope.', class_exists('UserBase'));
} catch (Exception $e) {
    Db::query("drop database {$dbname}");
    exec("read -p 'Press enter to delete the test directory named: {$dbname}  OR CTRL+C TO ABORT'; rm -rf {$dbname}");
    throw new OrmTestException('Unable to generate model! (' . $e->getMessage() . ')');
}
try {
    foreach (array('Jason', 'Jim', 'Jerri', 'Al') as $name) {
        $user = new User(array('name' => $name, 'email' => "{$name}@not_a_domain.com", 'created_at' => new PlainSql('NOW()'), 'active' => 1));
        $user->save();
    }
    OrmTest::assertTrue('Testing save() on new object.', is_numeric($user->getId()));
    $user->setName("{$name} Johnson")->save();
コード例 #2
0
ファイル: generate.php プロジェクト: jasonmoo/DumbledORM
#!/usr/bin/php
<?php 
if (in_array($argv[1], array('--help', '-help', '-h', '-?'))) {
    ?>

Generate DumbledORM models.

  Usage:
  <?php 
    echo $argv[0];
    ?>
 <option>

  <option> 
      -h, -?, --help, -help            Print this help message
      -p, --prefix <prefix>            Prefix generated classes
      -d, --dir <directory>            Output directory for the model instead of the default ./model 

<?php 
} else {
    $params = array('p:' => 'prefix:', 'd:' => 'dir:');
    $opt = getopt(implode('', array_keys($params)), $params);
    require 'config.php';
    require 'dumbledorm.php';
    Builder::generateBase($opt['p'], $opt['d'] ? $opt['d'] : 'model');
}