Load and make a instance of the migration
public getMigration ( string $name, string $class, string $type, array $options = [] ) : boolean | CakeMigration | ||
$name | string | File name where migration resides |
$class | string | Migration class name |
$type | string | Can be 'app' or a plugin name |
$options | array | Extra options to send to CakeMigration class |
리턴 | boolean | CakeMigration | False in case of no file found, instance of the migration |
/** * testGetMigration method * * @return void */ function testGetMigration() { $result = $this->Version->getMigration('inexistent_migration', 'InexistentMigration', 'test_migration_plugin'); $this->assertFalse($result); $result = $this->Version->getMigration('001_schema_dump', 'M4af6d40056b04408808500cb58157726', 'test_migration_plugin'); $this->assertIsA($result, 'M4af6d40056b04408808500cb58157726'); $this->assertEqual($result->description, 'Version 001 (schema dump) of TestMigrationPlugin'); // Calling twice to check if it will not try to redeclare the class $result = $this->Version->getMigration('001_schema_dump', 'M4af6d40056b04408808500cb58157726', 'test_migration_plugin'); $this->assertIsA($result, 'M4af6d40056b04408808500cb58157726'); $this->assertEqual($result->description, 'Version 001 (schema dump) of TestMigrationPlugin'); }
/** * testGetMigration method * * @return void */ public function testGetMigration() { try { $this->Version->getMigration('inexistent_migration', 'InexistentMigration', 'test_migration_plugin'); $this->fail('No exception triggered'); } catch (MigrationVersionException $e) { $this->assertEqual('File `inexistent_migration.php` not found in the TestMigrationPlugin Plugin.', $e->getMessage()); } try { $this->Version->getMigration('blank_file', 'BlankFile', 'test_migration_plugin'); $this->fail('No exception triggered'); } catch (MigrationVersionException $e) { $this->assertEqual('Class `BlankFile` not found on file `blank_file.php` for TestMigrationPlugin Plugin.', $e->getMessage()); } $result = $this->Version->getMigration('001_schema_dump', 'M4af6d40056b04408808500cb58157726', 'test_migration_plugin'); $this->assertInstanceOf('M4af6d40056b04408808500cb58157726', $result); $this->assertEqual($result->description, 'Version 001 (schema dump) of TestMigrationPlugin'); // Calling twice to check if it will not try to redeclare the class $result = $this->Version->getMigration('001_schema_dump', 'M4af6d40056b04408808500cb58157726', 'test_migration_plugin'); $this->assertInstanceOf('M4af6d40056b04408808500cb58157726', $result); $this->assertEqual($result->description, 'Version 001 (schema dump) of TestMigrationPlugin'); }