From 56cbbe38ba7055058b6b83af7437113792b348d5 Mon Sep 17 00:00:00 2001 From: "Jonathan H. Wage" Date: Wed, 16 May 2018 21:17:33 +0100 Subject: [PATCH] Fix issue with not being able to configure column_length with configuration files. --- .../AbstractFileConfiguration.php | 5 ++++ .../Configuration/XML/configuration.xsd | 1 + .../Configuration/XmlConfiguration.php | 4 +++ .../AbstractConfigurationTest.php | 6 ++++ .../AbstractFileConfigurationTest.php | 24 +++++++++------ .../Tests/Configuration/_files/config.json | 1 + .../Tests/Configuration/_files/config.php | 15 +++++----- .../Tests/Configuration/_files/config.xml | 2 +- .../Tests/Configuration/_files/config.yml | 1 + .../_files/config_migrations_list.php | 30 +++++++++---------- .../MigrationTableManipulatorTest.php | 7 +++-- 11 files changed, 62 insertions(+), 34 deletions(-) diff --git a/lib/Doctrine/Migrations/Configuration/AbstractFileConfiguration.php b/lib/Doctrine/Migrations/Configuration/AbstractFileConfiguration.php index b675e1020c..d6344e5bd0 100644 --- a/lib/Doctrine/Migrations/Configuration/AbstractFileConfiguration.php +++ b/lib/Doctrine/Migrations/Configuration/AbstractFileConfiguration.php @@ -23,6 +23,7 @@ abstract class AbstractFileConfiguration extends Configuration 'migrations_namespace', 'table_name', 'column_name', + 'column_length', 'executed_at_column_name', 'organize_migrations', 'name', @@ -88,6 +89,10 @@ protected function setConfiguration(array $config) : void $this->setMigrationsColumnName($config['column_name']); } + if (isset($config['column_length'])) { + $this->setMigrationsColumnLength($config['column_length']); + } + if (isset($config['executed_at_column_name'])) { $this->setMigrationsExecutedAtColumnName($config['executed_at_column_name']); } diff --git a/lib/Doctrine/Migrations/Configuration/XML/configuration.xsd b/lib/Doctrine/Migrations/Configuration/XML/configuration.xsd index e6551bc563..ff93498107 100644 --- a/lib/Doctrine/Migrations/Configuration/XML/configuration.xsd +++ b/lib/Doctrine/Migrations/Configuration/XML/configuration.xsd @@ -12,6 +12,7 @@ + diff --git a/lib/Doctrine/Migrations/Configuration/XmlConfiguration.php b/lib/Doctrine/Migrations/Configuration/XmlConfiguration.php index 9e562e9dda..200259db91 100644 --- a/lib/Doctrine/Migrations/Configuration/XmlConfiguration.php +++ b/lib/Doctrine/Migrations/Configuration/XmlConfiguration.php @@ -45,6 +45,10 @@ protected function doLoad(string $file) : void $config['column_name'] = (string) $xml->table['column']; } + if (isset($xml->table['column_length'])) { + $config['column_length'] = (int) $xml->table['column_length']; + } + if (isset($xml->table['executed_at_column'])) { $config['executed_at_column_name'] = (string) $xml->table['executed_at_column']; } diff --git a/tests/Doctrine/Migrations/Tests/Configuration/AbstractConfigurationTest.php b/tests/Doctrine/Migrations/Tests/Configuration/AbstractConfigurationTest.php index 24735be60f..4ae6768a0e 100644 --- a/tests/Doctrine/Migrations/Tests/Configuration/AbstractConfigurationTest.php +++ b/tests/Doctrine/Migrations/Tests/Configuration/AbstractConfigurationTest.php @@ -53,6 +53,12 @@ public function testMigrationsColumnName() : void self::assertEquals('doctrine_migration_column_test', $config->getMigrationsColumnName()); } + public function testMigrationsColumnLength() : void + { + $config = $this->loadConfiguration(); + self::assertEquals(200, $config->getMigrationsColumnLength()); + } + public function testMigrationsExecutedAtColumnName() : void { $config = $this->loadConfiguration(); diff --git a/tests/Doctrine/Migrations/Tests/Configuration/AbstractFileConfigurationTest.php b/tests/Doctrine/Migrations/Tests/Configuration/AbstractFileConfigurationTest.php index 400ab704b1..f688ec6c17 100644 --- a/tests/Doctrine/Migrations/Tests/Configuration/AbstractFileConfigurationTest.php +++ b/tests/Doctrine/Migrations/Tests/Configuration/AbstractFileConfigurationTest.php @@ -41,6 +41,7 @@ public function testSetConfiguration() : void 'setMigrationsNamespace', 'setMigrationsTableName', 'setMigrationsColumnName', + 'setMigrationsColumnLength', 'setMigrationsExecutedAtColumnName', 'setMigrationsAreOrganizedByYearAndMonth', 'setName', @@ -62,6 +63,10 @@ public function testSetConfiguration() : void ->method('setMigrationsColumnName') ->with('version_number'); + $fileConfiguration->expects($this->once()) + ->method('setMigrationsColumnLength') + ->with(200); + $fileConfiguration->expects($this->once()) ->method('setMigrationsExecutedAtColumnName') ->with('executed_at'); @@ -90,17 +95,18 @@ public function testSetConfiguration() : void ->with('custom_template'); $fileConfiguration->setTestConfiguration([ - 'migrations_namespace' => 'Doctrine', - 'table_name' => 'migration_version', - 'column_name' => 'version_number', - 'executed_at_column_name' => 'executed_at', - 'organize_migrations' => 'year_and_month', - 'name' => 'Migrations Test', - 'migrations_directory' => 'migrations_directory', - 'migrations' => [ + 'migrations_namespace' => 'Doctrine', + 'table_name' => 'migration_version', + 'column_name' => 'version_number', + 'column_length' => 200, + 'executed_at_column_name' => 'executed_at', + 'organize_migrations' => 'year_and_month', + 'name' => 'Migrations Test', + 'migrations_directory' => 'migrations_directory', + 'migrations' => [ [ 'version' => '001', - 'class' => 'Test', + 'class' => 'Test', ], ], 'custom_template' => 'custom_template', diff --git a/tests/Doctrine/Migrations/Tests/Configuration/_files/config.json b/tests/Doctrine/Migrations/Tests/Configuration/_files/config.json index e6f5dfd1b8..499e492666 100644 --- a/tests/Doctrine/Migrations/Tests/Configuration/_files/config.json +++ b/tests/Doctrine/Migrations/Tests/Configuration/_files/config.json @@ -3,6 +3,7 @@ "migrations_namespace" : "DoctrineMigrationsTest", "table_name" : "doctrine_migration_versions_test", "column_name" : "doctrine_migration_column_test", + "column_length" : 200, "executed_at_column_name" : "doctrine_migration_executed_at_column_test", "migrations_directory" : ".", "migrations" : [] diff --git a/tests/Doctrine/Migrations/Tests/Configuration/_files/config.php b/tests/Doctrine/Migrations/Tests/Configuration/_files/config.php index d7c76faaa7..b95bc0fb8f 100644 --- a/tests/Doctrine/Migrations/Tests/Configuration/_files/config.php +++ b/tests/Doctrine/Migrations/Tests/Configuration/_files/config.php @@ -3,11 +3,12 @@ declare(strict_types=1); return [ -'name' => 'Doctrine Sandbox Migrations', -'migrations_namespace' => 'DoctrineMigrationsTest', -'table_name' => 'doctrine_migration_versions_test', -'column_name' => 'doctrine_migration_column_test', -'executed_at_column_name' => 'doctrine_migration_executed_at_column_test', -'migrations_directory' => '.', -'migrations' => [], + 'name' => 'Doctrine Sandbox Migrations', + 'migrations_namespace' => 'DoctrineMigrationsTest', + 'table_name' => 'doctrine_migration_versions_test', + 'column_name' => 'doctrine_migration_column_test', + 'column_length' => 200, + 'executed_at_column_name' => 'doctrine_migration_executed_at_column_test', + 'migrations_directory' => '.', + 'migrations' => [], ]; diff --git a/tests/Doctrine/Migrations/Tests/Configuration/_files/config.xml b/tests/Doctrine/Migrations/Tests/Configuration/_files/config.xml index d2716e9b14..fae1fb3841 100644 --- a/tests/Doctrine/Migrations/Tests/Configuration/_files/config.xml +++ b/tests/Doctrine/Migrations/Tests/Configuration/_files/config.xml @@ -6,7 +6,7 @@ Doctrine Sandbox Migrations DoctrineMigrationsTest - +
. diff --git a/tests/Doctrine/Migrations/Tests/Configuration/_files/config.yml b/tests/Doctrine/Migrations/Tests/Configuration/_files/config.yml index f99fed5bf2..bbefc1e416 100644 --- a/tests/Doctrine/Migrations/Tests/Configuration/_files/config.yml +++ b/tests/Doctrine/Migrations/Tests/Configuration/_files/config.yml @@ -3,6 +3,7 @@ name: Doctrine Sandbox Migrations migrations_namespace: DoctrineMigrationsTest table_name: doctrine_migration_versions_test column_name: doctrine_migration_column_test +column_length: 200 executed_at_column_name: doctrine_migration_executed_at_column_test migrations_directory: . migrations: [] diff --git a/tests/Doctrine/Migrations/Tests/Configuration/_files/config_migrations_list.php b/tests/Doctrine/Migrations/Tests/Configuration/_files/config_migrations_list.php index d464e0a78d..42d0faf060 100644 --- a/tests/Doctrine/Migrations/Tests/Configuration/_files/config_migrations_list.php +++ b/tests/Doctrine/Migrations/Tests/Configuration/_files/config_migrations_list.php @@ -3,20 +3,20 @@ declare(strict_types=1); return [ -'name' => 'Doctrine Sandbox Migrations', -'table_name' => 'doctrine_migration_versions_test', -'migrations' => [ - [ - 'class' => 'Doctrine\\Migrations\\Tests\\Stub\\Version1Test', - 'version' => 'Version1Test', + 'name' => 'Doctrine Sandbox Migrations', + 'table_name' => 'doctrine_migration_versions_test', + 'migrations' => [ + [ + 'class' => 'Doctrine\\Migrations\\Tests\\Stub\\Version1Test', + 'version' => 'Version1Test', + ], + [ + 'class' => 'Doctrine\\Migrations\\Tests\\Stub\\Version2Test', + 'version' => 'Version2Test', + ], + [ + 'class' => 'Doctrine\\Migrations\\Tests\\Stub\\Version3Test', + 'version' => 'Version3Test', + ], ], - [ - 'class' => 'Doctrine\\Migrations\\Tests\\Stub\\Version2Test', - 'version' => 'Version2Test', - ], - [ - 'class' => 'Doctrine\\Migrations\\Tests\\Stub\\Version3Test', - 'version' => 'Version3Test', - ], -], ]; diff --git a/tests/Doctrine/Migrations/Tests/Functional/MigrationTableManipulatorTest.php b/tests/Doctrine/Migrations/Tests/Functional/MigrationTableManipulatorTest.php index 282c4a3c05..79ef671bc1 100644 --- a/tests/Doctrine/Migrations/Tests/Functional/MigrationTableManipulatorTest.php +++ b/tests/Doctrine/Migrations/Tests/Functional/MigrationTableManipulatorTest.php @@ -34,6 +34,7 @@ public function testCreateMigrationTable() : void self::assertTrue($table->hasColumn('version')); self::assertTrue($table->getColumn('version')->getNotnull()); + self::assertEquals(200, $table->getColumn('version')->getLength()); self::assertTrue($table->hasColumn('executed_at')); self::assertTrue($table->getColumn('executed_at')->getNotnull()); @@ -42,7 +43,7 @@ public function testCreateMigrationTable() : void public function testUpdateMigrationTable() : void { $createTablesSql = [ - 'CREATE TABLE doctrine_migration_versions (version varchar(255) NOT NULL, test varchar(255) DEFAULT NULL, PRIMARY KEY (version))', + 'CREATE TABLE doctrine_migration_versions (version varchar(200) NOT NULL, test varchar(255) DEFAULT NULL, PRIMARY KEY (version))', 'CREATE TABLE test (test varchar(255) NOT NULL)', ]; @@ -73,7 +74,9 @@ public function testUpdateMigrationTable() : void protected function setUp() : void { - $configuration = $this->getSqliteConfiguration(); + $configuration = $this->getSqliteConfiguration(); + $configuration->setMigrationsColumnLength(200); + $dependencyFactory = $configuration->getDependencyFactory(); $this->migrationTableManipulator = $dependencyFactory->getMigrationTableManipulator();