Skip to content

Commit

Permalink
Merge pull request #110 from HavokInspiration/migrate-snapshot-tests
Browse files Browse the repository at this point in the history
Add a test that migrates the snapshot comparisons migrations
  • Loading branch information
HavokInspiration committed Aug 11, 2015
2 parents b0be2e6 + 4e6e054 commit 036d442
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions tests/TestCase/MigrationsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@
*/
namespace Migrations\Test;

use Cake\Core\Plugin;
use Cake\Database\Schema\Collection;
use Cake\Datasource\ConnectionManager;
use Cake\ORM\TableRegistry;
use Cake\TestSuite\TestCase;
use Migrations\Migrations;
use Phinx\Migration\Util;

/**
* Tests the Migrations class
Expand Down Expand Up @@ -222,4 +224,58 @@ public function testOverrideOptions()
$expected[0]['status'] = 'up';
$this->assertEquals($expected, $result);
}

/**
* Tests migrating the baked snapshots
*
* @dataProvider migrationsProvider
* @return void
*/
public function testMigrateSnapshots($basePath)
{
$destination = ROOT . 'config' . DS . 'SnapshotTests' . DS;
$timestamp = Util::getCurrentTimestamp();

if (!file_exists($destination)) {
mkdir($destination);
}

copy(
$basePath . 'testCompositeConstraintsSnapshot.php',
$destination . $timestamp . '_testCompositeConstraintsSnapshot.php'
);

$result = $this->migrations->migrate(['source' => 'SnapshotTests']);
$this->assertTrue($result);

$this->migrations->rollback(['source' => 'SnapshotTests']);

unlink($destination . $timestamp . '_testCompositeConstraintsSnapshot.php');

copy(
$basePath . 'testNotEmptySnapshot.php',
$destination . $timestamp . '_testNotEmptySnapshot.php'
);

$result = $this->migrations->migrate(['source' => 'SnapshotTests']);
$this->assertTrue($result);

$this->migrations->rollback(['source' => 'SnapshotTests']);

unlink($destination . $timestamp . '_testNotEmptySnapshot.php');
}

/**
* provides the path to the baked migrations
*
* @return array
*/
public function migrationsProvider()
{
return [
[Plugin::path('Migrations') . 'tests' . DS . 'comparisons' . DS . 'Migration' . DS],
[Plugin::path('Migrations') . 'tests' . DS . 'comparisons' . DS . 'Migration' . DS . 'sqlite' . DS],
[Plugin::path('Migrations') . 'tests' . DS . 'comparisons' . DS . 'Migration' . DS . 'pgsql' . DS]
];
}
}

0 comments on commit 036d442

Please sign in to comment.