Skip to content

Commit

Permalink
Fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
odan committed Feb 17, 2017
1 parent 7987e0b commit 6efa884
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 28 deletions.
25 changes: 10 additions & 15 deletions src/Migration/Adapter/Generator/PhinxMySqlGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
*/
class PhinxMySqlGenerator
{

/**
* Database adapter
*
Expand Down Expand Up @@ -206,9 +205,7 @@ protected function getTableMigrationNewTables($output, $new, $old)
}

$output = $this->getTableMigrationNewTablesColumns($output, $table, $tableName, $new, $old);

$output = $this->getTableMigrationOldTablesColumns($output, $tableName, $new, $old);

$output = $this->getTableMigrationIndexes($output, $table, $tableName, $new, $old);
}
return $output;
Expand Down Expand Up @@ -277,10 +274,10 @@ protected function getTableMigrationIndexes($output, $table, $tableName, $new, $
}
foreach ($table['indexes'] as $indexName => $indexSequences) {
if (!isset($old['tables'][$tableName]['indexes'][$indexName])) {
$output[] = $this->getIndexCreate($new, $tableName, $indexName);
$output = $this->getIndexCreate($output, $new, $tableName, $indexName);
} else {
if ($this->neq($new, $old, ['tables', $tableName, 'indexes', $indexName])) {
$output[] = $this->getIndexCreate($new, $tableName, $indexName);
$output = $this->getIndexCreate($output, $new, $tableName, $indexName);
}
}
}
Expand Down Expand Up @@ -884,30 +881,28 @@ public function getColumnLimit($columnData)
/**
* Generate index create.
*
* @param array $schema
* @param string $table
* @param string $indexName
* @return string
* @param array $output Output
* @param array $schema Schema
* @param string $table Tablename
* @param string $indexName Index name
* @return array Output
*/
protected function getIndexCreate($schema, $table, $indexName)
protected function getIndexCreate($output, $schema, $table, $indexName)
{
if ($indexName == 'PRIMARY') {
return '';
return $output;
}
$indexes = $schema['tables'][$table]['indexes'];
$indexSequences = $indexes[$indexName];

$indexFields = $this->getIndexFields($indexSequences);
$indexOptions = $this->getIndexOptions(array_values($indexSequences)[0]);

$output = [];
$output[] = sprintf("%sif(\$this->table('%s')->hasIndex('%s')) {", $this->ind2, $table, $indexName);
$output[] = sprintf("%s%s", $this->ind, $this->getIndexRemove($table, $indexName));
$output[] = sprintf("%s}", $this->ind2);
$output[] = sprintf("%s\$this->table(\"%s\")->addIndex(%s, %s)->save();", $this->ind2, $table, $indexFields, $indexOptions);

$result = implode($this->nl, $output);
return $result;
return $output;
}

/**
Expand Down
6 changes: 4 additions & 2 deletions tests/GenerateCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,23 @@
/**
* @coversDefaultClass \Odan\Migration\Command\GenerateCommand
*/
class GenerateCommandTest extends \PHPUnit_Framework_TestCase
class GenerateCommandTest extends \PHPUnit\Framework\TestCase
{

/**
* Test
*
* @covers ::execute
* @covers ::getSettings
* @covers ::read
* @expectedException Exception
*/
public function testGenerate()
{
$application = new Application();
$application->add(new GenerateCommand());

$command = $application->find('migration:generate');
$command = $application->find('generate');
$commandTester = new CommandTester($command);
$commandTester->execute(array('command' => $command->getName()));

Expand Down
50 changes: 48 additions & 2 deletions tests/PhinxGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,58 @@
/**
* @coversDefaultClass \Odan\Migration\Adapter\Generator\PhinxMySqlGenerator
*/
class GenerateMigrationTest extends \PHPUnit_Framework_TestCase
class GenerateMigrationTest extends \PHPUnit\Framework\TestCase
{

/**
* Test
*
* @covers ::createMigration
* @covers ::addChangeMethod
* @covers ::getTableMigration
* @covers ::getTableMigrationNewDatabase
* @covers ::getTableMigrationNewTables
* @covers ::getTableMigrationNewTablesColumns
* @covers ::getTableMigrationOldTablesColumns
* @covers ::getTableMigrationIndexes
* @covers ::getTableMigrationOldTables
* @covers ::appendLines
* @covers ::getForeignKeysMigrations
* @covers ::getAlterDatabaseCharset
* @covers ::getAlterDatabaseCollate
* @covers ::getCreateTable
* @covers ::getDropTable
* @covers ::getAlterTableEngine
* @covers ::getAlterTableCharset
* @covers ::getAlterTableCollate
* @covers ::getAlterTableComment
* @covers ::getColumnCreate
* @covers ::getColumnUpdate
* @covers ::getColumnRemove
* @covers ::getMySQLColumnType
* @covers ::getPhinxColumnType
* @covers ::getPhinxColumnOptions
* @covers ::getPhinxColumnOptionsDefault
* @covers ::getPhinxColumnOptionsNull
* @covers ::getPhinxColumnOptionsTimestamp
* @covers ::getPhinxColumnOptionsLimit
* @covers ::getPhinxColumnOptionsComment
* @covers ::getPhinxColumnOptionsNumeric
* @covers ::getPhinxColumnOptionsAfter
* @covers ::getOptionEnumValue
* @covers ::getColumnLimit
* @covers ::getIndexCreate
* @covers ::getIndexFields
* @covers ::getIndexOptions
* @covers ::getIndexRemove
* @covers ::getForeignKeyCreate
* @covers ::getForeignKeyOptions
* @covers ::getForeignKeyRuleValue
* @covers ::getForeignKeyRemove
* @covers ::getSetForeignKeyCheck
* @covers ::getSetUniqueChecks
* @covers ::eq
* @covers ::neq
*/
public function testGenerate()
{
Expand Down Expand Up @@ -69,7 +114,8 @@ public function getPdo($settings)
public function getSettings()
{
return array(
'dsn' => 'mysql:host=127.0.0.1;dbname=test',
'dsn' => 'mysql:host = 127.0.0.1;
dbname = test',
'username' => 'root',
'password' => '',
'options' => array(
Expand Down
16 changes: 8 additions & 8 deletions tests/diffs/newtable.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@
'TABLE_NAME' => 'newtable2',
'COLUMN_NAME' => 'id',
'ORDINAL_POSITION' => '1',
'COLUMN_DEFAULT' => NULL,
'COLUMN_DEFAULT' => null,
'IS_NULLABLE' => 'NO',
'DATA_TYPE' => 'int',
'CHARACTER_MAXIMUM_LENGTH' => NULL,
'CHARACTER_OCTET_LENGTH' => NULL,
'CHARACTER_MAXIMUM_LENGTH' => null,
'CHARACTER_OCTET_LENGTH' => null,
'NUMERIC_PRECISION' => '10',
'NUMERIC_SCALE' => '0',
'DATETIME_PRECISION' => NULL,
'CHARACTER_SET_NAME' => NULL,
'COLLATION_NAME' => NULL,
'DATETIME_PRECISION' => null,
'CHARACTER_SET_NAME' => null,
'COLLATION_NAME' => null,
'COLUMN_TYPE' => 'int(11)',
'COLUMN_KEY' => 'PRI',
'EXTRA' => 'auto_increment',
Expand All @@ -48,8 +48,8 @@
'Column_name' => 'id',
'Collation' => 'A',
'Cardinality' => '0',
'Sub_part' => NULL,
'Packed' => NULL,
'Sub_part' => null,
'Packed' => null,
'Null' => '',
'Index_type' => 'BTREE',
'Comment' => '',
Expand Down
1 change: 0 additions & 1 deletion tests/diffs/newtable_expected.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,5 @@ public function change()
} else {
$this->table("newtable")->addColumn('id', 'integer', array('null' => false, 'limit' => MysqlAdapter::INT_REGULAR, 'precision' => 10, 'identity' => 'enable'))->update();
}

}
}

0 comments on commit 6efa884

Please sign in to comment.