Skip to content

Commit

Permalink
Merge pull request #112 from HavokInspiration/fix-migrations-class
Browse files Browse the repository at this point in the history
The check for different migrations paths should only be done if a migrations path was already defined
  • Loading branch information
HavokInspiration committed Aug 11, 2015
2 parents 036d442 + 4d821f3 commit 21156ca
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 8 deletions.
7 changes: 5 additions & 2 deletions src/Migrations.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}

Expand Down
35 changes: 29 additions & 6 deletions tests/TestCase/MigrationsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,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]);
Expand Down Expand Up @@ -196,6 +204,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 = [
[
Expand Down

0 comments on commit 21156ca

Please sign in to comment.