/** * Reset the table name based on conventions * */ public function resetTableName() { return $this->_tableName = Mad_Support_Inflector::tableize($this->baseClass()); }
/** * Generate model class stubs */ private function _generateModelStubs() { $name = !empty($this->_args) ? array_shift($this->_args) : null; if (!$name) { $this->_exit("You did not specify the name of the Model to generate"); } // CREATE FILES $modelFile = Mad_Support_Inflector::camelize($name); $modelName = Mad_Support_Inflector::classify($name); $tableName = Mad_Support_Inflector::tableize($name); // make namespace dir if (strstr($modelFile, '/')) { $this->_createDir(MAD_ROOT . '/app/models/' . dirname($modelFile) . '/'); } // template files & common vars $this->_tpl->author = $this->_author; $this->_tpl->className = $modelName; $this->_tpl->tableName = $tableName; // create Model file snippit $content = $this->_tpl->render('model.php'); $this->_createFile(MAD_ROOT . "/app/models/{$modelFile}.php", $content); // create Unit Test stub // make namespace dir if (strstr($modelFile, '/')) { $this->_createDir(MAD_ROOT . '/test/unit/' . dirname($modelFile) . '/'); } $this->_tpl->classFile = "models/{$modelName}.php"; $this->_tpl->package = 'Models'; $content = $this->_tpl->render('unit_test.php'); $this->_createFile(MAD_ROOT . "/test/unit/{$modelFile}Test.php", $content); // create Migration stub $this->_generateMigrationStub("create_{$tableName}"); // create fixture stub $this->_createFile(MAD_ROOT . "/test/fixtures/{$tableName}.yml", null); }
public function testTableize() { // most common scenarios (class => table) $this->assertEquals('dereks', Mad_Support_Inflector::tableize('Derek')); $this->assertEquals('dereks', Mad_Support_Inflector::tableize('Dereks')); $this->assertEquals('dereks_tests', Mad_Support_Inflector::tableize('dereksTest')); $this->assertEquals('dereks_tests', Mad_Support_Inflector::tableize('DereksTest')); $this->assertEquals('dereks_tests', Mad_Support_Inflector::tableize('Dereks_Test')); $this->assertEquals('dereks_tests', Mad_Support_Inflector::tableize('Dereks/Test')); // not as common (already underscore) $this->assertEquals('dereks', Mad_Support_Inflector::tableize('derek')); $this->assertEquals('dereks_tests', Mad_Support_Inflector::tableize('dereks_test')); $this->assertEquals('dereks_tests', Mad_Support_Inflector::tableize('dereks/test')); }