From 4e6e0540938b9434df3f5d01db55af0c102774be Mon Sep 17 00:00:00 2001 From: Yves P Date: Sat, 8 Aug 2015 00:01:39 +0200 Subject: [PATCH] Add a test that migrates the snapshot comparisons migrations This is to ensure that whatever the db engine used to bake a migration file, the resulting file can be migrated across all supported db engines --- tests/TestCase/MigrationsTest.php | 56 +++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/tests/TestCase/MigrationsTest.php b/tests/TestCase/MigrationsTest.php index bf184b03..77505f50 100644 --- a/tests/TestCase/MigrationsTest.php +++ b/tests/TestCase/MigrationsTest.php @@ -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 @@ -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] + ]; + } }