public function testGenerateBlank()
    {
        $result = generateInstallSchemaTable('unit_test', [], 'A testing table');
        $fixture = '$table = $installer->getConnection()->newTable(
            $installer->getTable(\'unit_test\')
    )->addColumn(
            \'unit_test_id\',
            \\Magento\\Framework\\DB\\Ddl\\Table::TYPE_INTEGER,
            null,
            array (
  \'identity\' => true,\'nullable\' => false,\'primary\' => true,\'unsigned\' => true,
),
            \'Entity ID\'
        )->addColumn(
            \'title\',
            \\Magento\\Framework\\DB\\Ddl\\Table::TYPE_TEXT,
            255,
            array (
  \'nullable\' => false,
),
            \'Demo Title\'
        )->addColumn(
            \'creation_time\',
            \\Magento\\Framework\\DB\\Ddl\\Table::TYPE_TIMESTAMP,
            null,
            array (
),
            \'Creation Time\'
        )->addColumn(
            \'update_time\',
            \\Magento\\Framework\\DB\\Ddl\\Table::TYPE_TIMESTAMP,
            null,
            array (
),
            \'Modification Time\'
        )->addColumn(
            \'is_active\',
            \\Magento\\Framework\\DB\\Ddl\\Table::TYPE_SMALLINT,
            null,
            array (
  \'nullable\' => false,\'default\' => \'1\',
),
            \'Is Active\'
        )->setComment(
             \'A testing table\'
         );
$installer->getConnection()->createTable($table);';
        $this->assertEquals($result, $fixture);
    }
Esempio n. 2
0
function createSchemaClass($module_info, $model_name)
{
    $className = str_replace('_', '\\', $module_info->name) . '\\Setup\\InstallSchema';
    $path = getPathFromClass($className);
    $template = createClassTemplate($className, false, '\\Magento\\Framework\\Setup\\InstallSchemaInterface');
    $contents = str_replace('<$body$>', templateInstallFunction(), $template);
    if (!file_exists($path)) {
        output("Creating: " . $path);
        writeStringToFile($path, $contents);
    } else {
        output("File Already Exists: " . $path);
    }
    $table_name = createTableNameFromModuleInfoAndModelName($module_info, $model_name);
    $install_code = generateInstallSchemaTable($table_name);
    $contents = file_get_contents($path);
    $end_setup = '$installer->endSetup();';
    $contents = str_replace($end_setup, "\n//START table setup\n" . $install_code . "\n//END   table setup\n" . $end_setup, $contents);
    writeStringToFile($path, $contents);
}