From 4d821f3a3a435385b123c892882cdaa75fcb39a8 Mon Sep 17 00:00:00 2001 From: Yves P Date: Sun, 9 Aug 2015 17:11:29 +0200 Subject: [PATCH] The check for different migrations paths should only be done if a migrations path was already defined --- src/Migrations.php | 7 +++++-- tests/TestCase/MigrationsTest.php | 35 +++++++++++++++++++++++++------ 2 files changed, 34 insertions(+), 8 deletions(-) diff --git a/src/Migrations.php b/src/Migrations.php index 8ad11a3e..d16df106 100644 --- a/src/Migrations.php +++ b/src/Migrations.php @@ -11,6 +11,7 @@ */ namespace Migrations; +use Phinx\Config\Config; use Phinx\Config\ConfigInterface; use Symfony\Component\Console\Input\ArrayInput; use Symfony\Component\Console\Output\NullOutput; @@ -171,12 +172,14 @@ public function markMigrated($version, $options = []) */ protected function run($method, $params, $input) { - $migrationPath = $this->getConfig()->getMigrationPath(); + if ($this->configuration instanceof Config) { + $migrationPath = $this->getConfig()->getMigrationPath(); + } $this->setInput($input); $newConfig = $this->getConfig(true); $manager = $this->getManager($newConfig); - if ($newConfig->getMigrationPath() !== $migrationPath) { + if (isset($migrationPath) && $newConfig->getMigrationPath() !== $migrationPath) { $manager->resetMigrations(); } diff --git a/tests/TestCase/MigrationsTest.php b/tests/TestCase/MigrationsTest.php index bf184b03..3b1b0d6c 100644 --- a/tests/TestCase/MigrationsTest.php +++ b/tests/TestCase/MigrationsTest.php @@ -49,16 +49,24 @@ public function setUp() 'connection' => 'test', 'source' => 'TestsMigrations' ]; - $this->migrations = new Migrations($params); - - $input = $this->migrations->getInput('Migrate', [], $params); - $this->migrations->setInput($input); - $this->migrations->getManager($this->migrations->getConfig()); + // Get the PDO connection to have the same across the various objects needed to run the tests + $migrations = new Migrations(); + $input = $migrations->getInput('Migrate', [], $params); + $migrations->setInput($input); + $migrations->getManager($migrations->getConfig()); $this->Connection = ConnectionManager::get('test'); - $connection = $this->migrations->getManager()->getEnvironment('default')->getAdapter()->getConnection(); + $connection = $migrations->getManager()->getEnvironment('default')->getAdapter()->getConnection(); $this->Connection->driver()->connection($connection); + // Get an instance of the Migrations object on which we will run the tests + $this->migrations = new Migrations($params); + $this->migrations + ->getManager($migrations->getConfig()) + ->getEnvironment('default') + ->getAdapter() + ->setConnection($connection); + $tables = (new Collection($this->Connection))->listTables(); if (in_array('phinxlog', $tables)) { $ormTable = TableRegistry::get('phinxlog', ['connection' => $this->Connection]); @@ -194,6 +202,21 @@ public function testMarkMigratedErrors() */ public function testOverrideOptions() { + $result = $this->migrations->status(); + $expectedStatus = [ + [ + 'status' => 'down', + 'id' => '20150704160200', + 'name' => 'CreateNumbersTable' + ], + [ + 'status' => 'down', + 'id' => '20150724233100', + 'name' => 'UpdateNumbersTable' + ] + ]; + $this->assertEquals($expectedStatus, $result); + $result = $this->migrations->status(['source' => 'Migrations']); $expected = [ [