From 14128c997ed9d7ab5854860f243ccf05c72682f8 Mon Sep 17 00:00:00 2001 From: Anton Vasiliev Date: Sun, 22 Mar 2020 16:37:42 +0000 Subject: [PATCH 1/8] #11 - Implement new option 'skip-foreign-checks' --- src/Console/Commands/Migration.php | 31 ++++---- src/Migrations.php | 18 ++++- src/Mvc/Model/Migration.php | 12 +++- tests/_support/Helper/Mysql.php | 16 +++++ tests/cli/RunCest.php | 111 ++++++++++++++++++++++++++++- 5 files changed, 166 insertions(+), 22 deletions(-) diff --git a/src/Console/Commands/Migration.php b/src/Console/Commands/Migration.php index 154f31f..d79e303 100644 --- a/src/Console/Commands/Migration.php +++ b/src/Console/Commands/Migration.php @@ -14,14 +14,12 @@ namespace Phalcon\Migrations\Console\Commands; use Phalcon\Config; -use Phalcon\Cop\Parser; -use Phalcon\Migrations\Console\Color; -use Phalcon\Migrations\Migrations; -use Phalcon\Migrations\Script\ScriptException; -use Phalcon\Mvc\Model\Exception; use Phalcon\Config\Adapter\Ini as IniConfig; use Phalcon\Config\Adapter\Json as JsonConfig; use Phalcon\Config\Adapter\Yaml as YamlConfig; +use Phalcon\Cop\Parser; +use Phalcon\Migrations\Console\Color; +use Phalcon\Migrations\Migrations; /** * Migration Command @@ -69,8 +67,8 @@ public function getPossibleParams(): array /** * @throws CommandsException - * @throws ScriptException - * @throws Exception + * @throws \Phalcon\Db\Exception + * @throws \Exception */ public function run(): void { @@ -146,15 +144,16 @@ public function run(): void break; case 'run': Migrations::run([ - 'directory' => $path, - 'tableName' => $tableName, - 'migrationsDir' => $migrationsDir, - 'force' => $this->parser->has('force'), - 'tsBased' => $migrationsTsBased, - 'config' => $config, - 'version' => $this->parser->get('version'), - 'migrationsInDb' => $migrationsInDb, - 'verbose' => $this->parser->has('verbose'), + 'directory' => $path, + 'tableName' => $tableName, + 'migrationsDir' => $migrationsDir, + 'force' => $this->parser->has('force'), + 'tsBased' => $migrationsTsBased, + 'config' => $config, + 'version' => $this->parser->get('version'), + 'migrationsInDb' => $migrationsInDb, + 'verbose' => $this->parser->has('verbose'), + 'skip-foreign-checks' => $this->parser->has('skip-foreign-checks'), ]); break; case 'list': diff --git a/src/Migrations.php b/src/Migrations.php index 2ac2260..83daed7 100644 --- a/src/Migrations.php +++ b/src/Migrations.php @@ -28,6 +28,7 @@ use Phalcon\Migrations\Version\IncrementalItem; use Phalcon\Migrations\Version\ItemCollection as VersionCollection; use Phalcon\Migrations\Version\TimestampedItem; +use SplFileInfo; class Migrations { @@ -191,6 +192,7 @@ public static function generate(array $options) * @param array $options * @throws DbException * @throws RuntimeException + * @throws Exception */ public static function run(array $options) { @@ -198,6 +200,7 @@ public static function run(array $options) $listTables = new ListTablesIterator(); $optionStack->setOptions($options); $optionStack->setDefaultOption('verbose', false); + $optionStack->setDefaultOption('skip-foreign-checks', false); // Define versioning type to be used if (!empty($options['tsBased']) || $optionStack->getOption('tsBased')) { @@ -355,12 +358,18 @@ public static function run(array $options) $migrationStartTime = date('Y-m-d H:i:s'); if ($optionStack->getOption('tableName') === '@') { + /** @var SplFileInfo $fileInfo */ foreach ($iterator as $fileInfo) { if (!$fileInfo->isFile() || 0 !== strcasecmp($fileInfo->getExtension(), 'php')) { continue; } - ModelMigration::migrate($fileInfo->getBasename('.php'), $initialVersion, $versionItem); + ModelMigration::migrate( + $fileInfo->getBasename('.php'), + $initialVersion, + $versionItem, + $optionStack->getOption('skip-foreign-checks') + ); } } else { if (!empty($prefix)) { @@ -369,7 +378,12 @@ public static function run(array $options) $tables = explode(',', $optionStack->getOption('tableName')); foreach ($tables as $tableName) { - ModelMigration::migrate($tableName, $initialVersion, $versionItem); + ModelMigration::migrate( + $tableName, + $initialVersion, + $versionItem, + $optionStack->getOption('skip-foreign-checks') + ); } } diff --git a/src/Mvc/Model/Migration.php b/src/Mvc/Model/Migration.php index c7564d1..f969cdf 100644 --- a/src/Mvc/Model/Migration.php +++ b/src/Mvc/Model/Migration.php @@ -328,12 +328,14 @@ public static function shouldExportDataFromTable(string $table, array $exportTab * @param string $tableName * @param ItemInterface|null $fromVersion * @param ItemInterface|null $toVersion + * @param bool $skipForeignChecks * @throws Exception */ public static function migrate( string $tableName, ItemInterface $fromVersion = null, - ItemInterface $toVersion = null + ItemInterface $toVersion = null, + bool $skipForeignChecks = false ): void { $fromVersion = $fromVersion ?: VersionCollection::createItem($fromVersion); $toVersion = $toVersion ?: VersionCollection::createItem($toVersion); @@ -342,6 +344,10 @@ public static function migrate( return; // nothing to do } + if ($skipForeignChecks === true) { + self::$connection->execute('SET FOREIGN_KEY_CHECKS=0'); + } + if ($fromVersion->getStamp() < $toVersion->getStamp()) { $toMigration = self::createClass($toVersion, $tableName); @@ -378,6 +384,10 @@ public static function migrate( $toMigration->morph(); } } + + if ($skipForeignChecks === true) { + self::$connection->execute('SET FOREIGN_KEY_CHECKS=1'); + } } /** diff --git a/tests/_support/Helper/Mysql.php b/tests/_support/Helper/Mysql.php index 03b9cb9..71d8fc9 100644 --- a/tests/_support/Helper/Mysql.php +++ b/tests/_support/Helper/Mysql.php @@ -31,17 +31,23 @@ public function _initialize() public function _before(TestInterface $test) { + $this->setForeignKeys(); foreach ($this->getPhalconDb()->listTables() as $table) { $this->getPhalconDb()->dropTable($table); } + + $this->setForeignKeys(true); } public function _after(TestInterface $test) { + $this->setForeignKeys(); foreach ($this->getPhalconDb()->listTables() as $table) { $this->getPhalconDb()->dropTable($table); } + $this->setForeignKeys(true); + /** * Reset filename or DB connection */ @@ -123,4 +129,14 @@ public function batchInsert(string $table, array $columns, array $rows) $this->getPhalconDb()->execute($query); } + + /** + * Executes 'SET FOREIGN_KEY_CHECKS' query + * + * @param bool $enabled + */ + protected function setForeignKeys(bool $enabled = false): void + { + $this->getPhalconDb()->execute('SET FOREIGN_KEY_CHECKS=' . intval($enabled)); + } } diff --git a/tests/cli/RunCest.php b/tests/cli/RunCest.php index 7499966..11ec3f0 100644 --- a/tests/cli/RunCest.php +++ b/tests/cli/RunCest.php @@ -15,9 +15,15 @@ use CliTester; use Phalcon\Db\Column; +use Phalcon\Db\Reference; final class RunCest { + /** + * @var string + */ + protected $configPath = 'tests/_data/cli/migrations.php'; + /** * @param CliTester $I */ @@ -46,14 +52,113 @@ public function generateAndRun(CliTester $I): void ], ]); - $configPath = 'tests/_data/cli/migrations.php'; + $I->runShellCommand('php phalcon-migrations generate --config=' . $this->configPath); + $I->seeInShellOutput('Success: Version 1.0.0 was successfully generated'); + $I->seeResultCodeIs(0); + + $I->runShellCommand('php phalcon-migrations run --config=' . $this->configPath); + $I->seeInShellOutput('Success: Version 1.0.0 was successfully migrated'); + $I->seeResultCodeIs(0); + } + + /** + * @param CliTester $I + */ + public function skipForeignKeys(CliTester $I): void + { + $table1 = 'client'; + $table2 = 'x-skip-foreign-keys'; + + $this->createTablesWithForeignKey($I); - $I->runShellCommand('php phalcon-migrations generate --config=' . $configPath); + $I->runShellCommand('php phalcon-migrations generate --config=' . $this->configPath); $I->seeInShellOutput('Success: Version 1.0.0 was successfully generated'); $I->seeResultCodeIs(0); - $I->runShellCommand('php phalcon-migrations run --config=' . $configPath); + $migrationContent = file_get_contents(codecept_output_dir('1.0.0/' . $table2 . '.php')); + $I->assertNotFalse(strpos($migrationContent, "'referencedTable' => 'client',")); + + $I->getPhalconDb()->dropTable($table2); + $I->getPhalconDb()->dropTable($table1); + + $I->runShellCommand('php phalcon-migrations run --skip-foreign-checks --config=' . $this->configPath); $I->seeInShellOutput('Success: Version 1.0.0 was successfully migrated'); $I->seeResultCodeIs(0); } + + /** + * @param CliTester $I + */ + public function expectForeignKeyDbError(CliTester $I): void + { + $table1 = 'client'; + $table2 = 'x-skip-foreign-keys'; + + $this->createTablesWithForeignKey($I); + + $I->runShellCommand('php phalcon-migrations generate --config=' . $this->configPath); + $I->seeInShellOutput('Success: Version 1.0.0 was successfully generated'); + $I->seeResultCodeIs(0); + + $migrationContent = file_get_contents(codecept_output_dir('1.0.0/' . $table2 . '.php')); + $I->assertNotFalse(strpos($migrationContent, "'referencedTable' => 'client',")); + + $I->getPhalconDb()->dropTable($table2); + $I->getPhalconDb()->dropTable($table1); + + $I->runShellCommand('php phalcon-migrations run --config=' . $this->configPath, false); + $I->seeInShellOutput('Fatal Error: SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint'); + $I->seeResultCodeIs(1); + } + + /** + * DRY! + * + * @param CliTester $I + */ + protected function createTablesWithForeignKey(CliTester $I): void + { + $schema = getenv('MYSQL_TEST_DB_DATABASE'); + $table1 = 'client'; + $table2 = 'x-skip-foreign-keys'; + + $I->getPhalconDb()->createTable($table1, $schema, [ + 'columns' => [ + new Column('id', [ + 'type' => Column::TYPE_INTEGER, + 'size' => 11, + 'notNull' => true, + 'primary' => true, + ]), + ], + ]); + + $I->getPhalconDb()->createTable($table2, $schema, [ + 'columns' => [ + new Column('id', [ + 'type' => Column::TYPE_INTEGER, + 'size' => 10, + 'notNull' => true, + ]), + new Column('clientId', [ + 'type' => Column::TYPE_INTEGER, + 'size' => 11, + 'notNull' => true, + ]), + ], + 'references' => [ + new Reference( + 'fk_client_1', + [ + 'referencedSchema' => $schema, + 'referencedTable' => $table1, + 'columns' => ['clientId'], + 'referencedColumns' => ['id'], + 'onUpdate' => 'NO ACTION', + 'onDelete' => 'NO ACTION', + ] + ), + ], + ]); + } } From 88e664498bc51c5fe57c56a1fa1b6671e0f21bd6 Mon Sep 17 00:00:00 2001 From: Anton Vasiliev Date: Sun, 22 Mar 2020 16:38:19 +0000 Subject: [PATCH 2/8] #11 - Implement new Color method: fatal() --- phalcon-migrations | 8 ++++---- src/Console/Color.php | 24 ++++++++++++++++++++++-- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/phalcon-migrations b/phalcon-migrations index d326e6f..3ac7ea6 100644 --- a/phalcon-migrations +++ b/phalcon-migrations @@ -35,16 +35,16 @@ try { $command = new Migration($parser); $command->run(); } catch (CommandsException $commandsException) { - echo Color::error($commandsException->getMessage()); + echo Color::error($commandsException->getMessage(), 'Exception Error: '); exit(1); } catch (RuntimeException $runtimeException) { - echo Color::error($runtimeException->getMessage()); + echo Color::error($runtimeException->getMessage(), 'Runtime Error: '); exit(1); } catch (DbException $dbException) { - echo Color::error($dbException->getMessage()); + echo Color::error($dbException->getMessage(), 'DB Error: '); exit(1); } } catch (Throwable $e) { - fwrite(STDERR, 'FATAL ERROR: ' . $e->getMessage() . PHP_EOL); + echo Color::fatal($e->getMessage()); exit(1); } diff --git a/src/Console/Color.php b/src/Console/Color.php index f325932..dde1691 100644 --- a/src/Console/Color.php +++ b/src/Console/Color.php @@ -174,11 +174,12 @@ public static function head(string $msg): string * * @static * @param string $msg + * @param string $prefix * @return string */ - public static function error(string $msg): string + public static function error(string $msg, string $prefix = 'Error: '): string { - $msg = 'Error: ' . $msg; + $msg = $prefix . $msg; $space = self::tabSpaces($msg); $out = static::colorize(str_pad(' ', $space), Color::FG_WHITE, Color::AT_BOLD, Color::BG_RED) . PHP_EOL; $out .= static::colorize(' ' . $msg . ' ', Color::FG_WHITE, Color::AT_BOLD, Color::BG_RED) . PHP_EOL; @@ -187,6 +188,25 @@ public static function error(string $msg): string return $out; } + /** + * Color style for fatal error messages. + * + * @static + * @param string $msg + * @param string $prefix + * @return string + */ + public static function fatal(string $msg, string $prefix = 'Fatal Error: '): string + { + $msg = $prefix . $msg; + $space = self::tabSpaces($msg); + $out = static::colorize(str_pad(' ', $space), Color::FG_LIGHT_GRAY, Color::AT_BOLD, Color::BG_RED) . PHP_EOL; + $out .= static::colorize(' ' . $msg . ' ', Color::FG_LIGHT_GRAY, Color::AT_BOLD, Color::BG_RED) . PHP_EOL; + $out .= static::colorize(str_pad(' ', $space), Color::FG_LIGHT_GRAY, Color::AT_BOLD, Color::BG_RED) . PHP_EOL; + + return $out; + } + /** * Color style for success messages. * From 632bfd39a01befd56358fdb5bccb584201dfe758 Mon Sep 17 00:00:00 2001 From: Anton Vasiliev Date: Sun, 22 Mar 2020 16:39:06 +0000 Subject: [PATCH 3/8] #11 - Minor refactor --- src/Version/IncrementalItem.php | 6 +++--- tests/integration/Migration/Action/GenerateCest.php | 9 +++++++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/Version/IncrementalItem.php b/src/Version/IncrementalItem.php index b073481..1fff9f2 100644 --- a/src/Version/IncrementalItem.php +++ b/src/Version/IncrementalItem.php @@ -135,8 +135,8 @@ public static function between($initialVersion, $finalVersion, $versions) foreach ($versions as $version) { /** @var ItemInterface $version */ if ( - ($version->getStamp() >= $initialVersion->getStamp()) - && ($version->getStamp() <= $finalVersion->getStamp()) + $version->getStamp() >= $initialVersion->getStamp() && + $version->getStamp() <= $finalVersion->getStamp() ) { $betweenVersions[] = $version; } @@ -149,7 +149,7 @@ public static function between($initialVersion, $finalVersion, $versions) * @param ItemInterface[] $versions * @return array ItemInterface[] */ - public static function sortAsc($versions) + public static function sortAsc(array $versions): array { $sortData = []; foreach ($versions as $version) { diff --git a/tests/integration/Migration/Action/GenerateCest.php b/tests/integration/Migration/Action/GenerateCest.php index 2d092d4..a927d3e 100644 --- a/tests/integration/Migration/Action/GenerateCest.php +++ b/tests/integration/Migration/Action/GenerateCest.php @@ -41,6 +41,9 @@ public function construct(IntegrationTester $I): void $I->assertNull($class->getPrimaryColumnName()); } + /** + * @param IntegrationTester $I + */ public function getReferences(IntegrationTester $I): void { $I->wantToTest('Migration\Action\Generate - getReferences()'); @@ -69,6 +72,9 @@ public function getReferences(IntegrationTester $I): void $I->assertNotFalse(array_search("'referencedSchema' => 'public'", current($generatedReferences))); } + /** + * @param IntegrationTester $I + */ public function getReferencesWithoutSchema(IntegrationTester $I): void { $I->wantToTest('Migration\Action\Generate - getReferences() without schema'); @@ -140,6 +146,9 @@ public function getReferencesWithoutSchema(IntegrationTester $I): void $I->assertFalse($schemaFound2); } + /** + * @param IntegrationTester $I + */ public function getReferencesWithSchema(IntegrationTester $I): void { $I->wantToTest('Migration\Action\Generate - getReferences() with schema'); From 4b3ed4e1b3ba50e3c6f3cffae12bdc95c3a9a2b3 Mon Sep 17 00:00:00 2001 From: Anton Vasiliev Date: Sun, 22 Mar 2020 16:39:48 +0000 Subject: [PATCH 4/8] #11 - Fix skipping 'referencedTable' during migration construction --- src/Migration/Action/Generate.php | 4 ++-- tests/cli/GenerateCest.php | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Migration/Action/Generate.php b/src/Migration/Action/Generate.php index 762dd35..5ba1065 100644 --- a/src/Migration/Action/Generate.php +++ b/src/Migration/Action/Generate.php @@ -311,13 +311,13 @@ public function getReferences(bool $skipRefSchema = false): Generator ); } - yield $constraintName => $referencesOptions + [ + yield $constraintName => array_merge($referencesOptions, [ sprintf("'referencedTable' => %s", $this->wrapWithQuotes($reference->getReferencedTable())), "'columns' => [" . join(',', array_unique($referenceColumns)) . "]", "'referencedColumns' => [" . join(',', array_unique($referencedColumns)) . "]", sprintf("'onUpdate' => '%s'", $reference->getOnUpdate()), sprintf("'onDelete' => '%s'", $reference->getOnDelete()), - ]; + ]); } } diff --git a/tests/cli/GenerateCest.php b/tests/cli/GenerateCest.php index 9e1d4d5..8130378 100644 --- a/tests/cli/GenerateCest.php +++ b/tests/cli/GenerateCest.php @@ -87,6 +87,7 @@ public function generateWithSkipRefSchema(CliTester $I): void $content = file_get_contents(codecept_output_dir('1.0.0/cli-skip-ref-schema.php')); $I->assertFalse(strpos($content, "'referencedSchema' => '$schema',")); + $I->assertNotFalse(strpos($content, "'referencedTable' => 'client',")); } /** @@ -107,6 +108,7 @@ public function generateWithRefSchema(CliTester $I): void $content = file_get_contents(codecept_output_dir('1.0.0/cli-skip-ref-schema.php')); $I->assertNotFalse(strpos($content, "'referencedSchema' => '$schema',")); + $I->assertNotFalse(strpos($content, "'referencedTable' => 'client',")); } /** From d4cb91350061b0e6f1f731beec95209149d2f694 Mon Sep 17 00:00:00 2001 From: Anton Vasiliev Date: Sun, 22 Mar 2020 17:00:29 +0000 Subject: [PATCH 5/8] #11 - Add initial query with custom 'sql_mode' --- tests/mysql.suite.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/mysql.suite.yml b/tests/mysql.suite.yml index 02f2cd4..d689c39 100644 --- a/tests/mysql.suite.yml +++ b/tests/mysql.suite.yml @@ -14,5 +14,6 @@ modules: initial_queries: - "SET NAMES utf8;" - "CREATE DATABASE IF NOT EXISTS `%MYSQL_TEST_DB_DATABASE%`" + - "SET sql_mode='ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'" - "USE `%MYSQL_TEST_DB_DATABASE%`" step_decorators: ~ From 10641136651d9ab4d6d68869684b4d526801ccdb Mon Sep 17 00:00:00 2001 From: Anton Vasiliev Date: Sun, 22 Mar 2020 17:06:35 +0000 Subject: [PATCH 6/8] #11 - Update initial queries --- tests/mysql.suite.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/mysql.suite.yml b/tests/mysql.suite.yml index d689c39..05106ba 100644 --- a/tests/mysql.suite.yml +++ b/tests/mysql.suite.yml @@ -14,6 +14,7 @@ modules: initial_queries: - "SET NAMES utf8;" - "CREATE DATABASE IF NOT EXISTS `%MYSQL_TEST_DB_DATABASE%`" - - "SET sql_mode='ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'" + - "SET GLOBAL sql_mode='ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'" + - "SET GLOBAL FOREIGN_KEY_CHECKS=1" - "USE `%MYSQL_TEST_DB_DATABASE%`" step_decorators: ~ From f0a0a227965a50fe4c085378aa5c80cbb1ca138f Mon Sep 17 00:00:00 2001 From: Anton Vasiliev Date: Sun, 22 Mar 2020 17:13:02 +0000 Subject: [PATCH 7/8] #11 - Disable query 'SET FOREIGN_KEY_CHECKS=0' --- src/Migrations.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Migrations.php b/src/Migrations.php index 83daed7..fcf250b 100644 --- a/src/Migrations.php +++ b/src/Migrations.php @@ -508,7 +508,7 @@ private static function connectionSetup(array $options): void self::$storage = new $adapter($configArray); if ($database->adapter === 'Mysql') { - self::$storage->query('SET FOREIGN_KEY_CHECKS=0'); + //self::$storage->query('SET FOREIGN_KEY_CHECKS=0'); } if (!self::$storage->tableExists(self::MIGRATION_LOG_TABLE)) { From 630c8e202f2f36e4db5ea64b33feaecc051941e1 Mon Sep 17 00:00:00 2001 From: Anton Vasiliev Date: Sun, 22 Mar 2020 17:20:51 +0000 Subject: [PATCH 8/8] #11 - Change RunCest tests --- src/Migrations.php | 2 +- tests/cli/RunCest.php | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Migrations.php b/src/Migrations.php index fcf250b..83daed7 100644 --- a/src/Migrations.php +++ b/src/Migrations.php @@ -508,7 +508,7 @@ private static function connectionSetup(array $options): void self::$storage = new $adapter($configArray); if ($database->adapter === 'Mysql') { - //self::$storage->query('SET FOREIGN_KEY_CHECKS=0'); + self::$storage->query('SET FOREIGN_KEY_CHECKS=0'); } if (!self::$storage->tableExists(self::MIGRATION_LOG_TABLE)) { diff --git a/tests/cli/RunCest.php b/tests/cli/RunCest.php index 11ec3f0..3afaa6f 100644 --- a/tests/cli/RunCest.php +++ b/tests/cli/RunCest.php @@ -69,7 +69,7 @@ public function skipForeignKeys(CliTester $I): void $table1 = 'client'; $table2 = 'x-skip-foreign-keys'; - $this->createTablesWithForeignKey($I); + $this->createTablesWithForeignKey($I, $table1, $table2); $I->runShellCommand('php phalcon-migrations generate --config=' . $this->configPath); $I->seeInShellOutput('Success: Version 1.0.0 was successfully generated'); @@ -91,17 +91,17 @@ public function skipForeignKeys(CliTester $I): void */ public function expectForeignKeyDbError(CliTester $I): void { - $table1 = 'client'; - $table2 = 'x-skip-foreign-keys'; + $table1 = 'z-client'; + $table2 = 'skip-foreign-keys'; - $this->createTablesWithForeignKey($I); + $this->createTablesWithForeignKey($I, $table1, $table2); $I->runShellCommand('php phalcon-migrations generate --config=' . $this->configPath); $I->seeInShellOutput('Success: Version 1.0.0 was successfully generated'); $I->seeResultCodeIs(0); $migrationContent = file_get_contents(codecept_output_dir('1.0.0/' . $table2 . '.php')); - $I->assertNotFalse(strpos($migrationContent, "'referencedTable' => 'client',")); + $I->assertNotFalse(strpos($migrationContent, "'referencedTable' => '" . $table1 . "',")); $I->getPhalconDb()->dropTable($table2); $I->getPhalconDb()->dropTable($table1); @@ -115,12 +115,12 @@ public function expectForeignKeyDbError(CliTester $I): void * DRY! * * @param CliTester $I + * @param string $table1 + * @param string $table2 */ - protected function createTablesWithForeignKey(CliTester $I): void + protected function createTablesWithForeignKey(CliTester $I, string $table1, string $table2): void { $schema = getenv('MYSQL_TEST_DB_DATABASE'); - $table1 = 'client'; - $table2 = 'x-skip-foreign-keys'; $I->getPhalconDb()->createTable($table1, $schema, [ 'columns' => [