Skip to content

Commit

Permalink
Update the tests so they pass again following the release of phinx 0.4.6
Browse files Browse the repository at this point in the history
This phinx release introduced changes in the naming scheme the migration files / the migration classes should follow, breaking the tests.

 This commit also removes the ``update()`` call after the ``dropForeignKey()`` calls : it was not necessary.
  • Loading branch information
HavokInspiration committed Sep 12, 2015
1 parent 325c93c commit 19f31d1
Show file tree
Hide file tree
Showing 12 changed files with 93 additions and 74 deletions.
9 changes: 5 additions & 4 deletions src/Template/Bake/config/snapshot.ctp
Original file line number Diff line number Diff line change
Expand Up @@ -151,14 +151,15 @@ class <%= $name %> extends AbstractMigration
public function down()
{
<%- foreach ($dropForeignKeys as $table => $columnsList): %>
<%- foreach ($dropForeignKeys as $table => $columnsList):
$maxKey = count($columnsList) - 1;
%>
$this->table('<%= $table %>')
<%- foreach ($columnsList as $columns): %>
<%- foreach ($columnsList as $key => $columns): %>
->dropForeignKey(
<%= $columns %>
)
)<%= ($key === $maxKey) ? ';' : '' %>
<%- endforeach; %>
->update();

<%- endforeach; %>
<%- foreach ($tables as $table): %>
Expand Down
41 changes: 32 additions & 9 deletions tests/TestCase/MigrationsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,20 @@ class MigrationsTest extends TestCase
*/
protected $Connection;

protected $timestamps = [
'test_composite_constraints_snapshot_pgsql' => 20150912015600,
'test_not_empty_snapshot_pgsql' => 20150912015601,
'test_auto_id_disabled_snapshot_pgsql' => 20150912015602,
'test_composite_constraints_snapshot_sqlite' => 20150912015603,
'test_not_empty_snapshot_sqlite' => 20150912015604,
'test_auto_id_disabled_snapshot_sqlite' => 20150912015605,
'test_composite_constraints_snapshot' => 20150912015606,
'test_not_empty_snapshot' => 20150912015607,
'test_auto_id_disabled_snapshot' => 20150912015608,
'testCreatePrimaryKey' => 20150912015609,
'testCreatePrimaryKeyUuid' => 20150912015610
];

/**
* Setup method
*
Expand Down Expand Up @@ -430,13 +444,13 @@ public function testMigrateDateOption()
public function testMigrateSnapshots($basePath, $files)
{
$destination = ROOT . 'config' . DS . 'SnapshotTests' . DS;
$timestamp = Util::getCurrentTimestamp();

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

foreach ($files as $file) {
$timestamp = $this->timestamps[$file];
$copiedFileName = $timestamp . '_' . $file . '.php';
copy(
$basePath . $file . '.php',
Expand All @@ -462,21 +476,30 @@ public function migrationsProvider()
[
Plugin::path('Migrations') . 'tests' . DS . 'comparisons' . DS . 'Migration' . DS,
[
'testCompositeConstraintsSnapshot',
'testNotEmptySnapshot',
'testAutoIdDisabledSnapshot',
'test_composite_constraints_snapshot',
'test_not_empty_snapshot',
'test_auto_id_disabled_snapshot',
'testCreatePrimaryKey',
'testCreatePrimaryKeyUuid'
]
],
[
Plugin::path('Migrations') . 'tests' . DS . 'comparisons' . DS . 'Migration' . DS . 'sqlite' . DS,
['testCompositeConstraintsSnapshot', 'testNotEmptySnapshot', 'testAutoIdDisabledSnapshot']
],
[
Plugin::path('Migrations') . 'tests' . DS . 'comparisons' . DS . 'Migration' . DS . 'pgsql' . DS,
['testCompositeConstraintsSnapshot', 'testNotEmptySnapshot', 'testAutoIdDisabledSnapshot']
[
'test_composite_constraints_snapshot_pgsql',
'test_not_empty_snapshot_pgsql',
'test_auto_id_disabled_snapshot_pgsql'
]
]
,
[
Plugin::path('Migrations') . 'tests' . DS . 'comparisons' . DS . 'Migration' . DS . 'sqlite' . DS,
[
'test_composite_constraints_snapshot_sqlite',
'test_not_empty_snapshot_sqlite',
'test_auto_id_disabled_snapshot_sqlite'
]
],
];
}
}
36 changes: 26 additions & 10 deletions tests/TestCase/Shell/Task/MigrationSnapshotTaskTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Cake\Core\Plugin;
use Cake\TestSuite\StringCompareTrait;
use Cake\TestSuite\TestCase;
use Cake\Utility\Inflector;

/**
* MigrationSnapshotTaskTest class
Expand Down Expand Up @@ -85,9 +86,10 @@ public function testNotEmptySnapshot()
)
);

$result = $this->Task->bake('NotEmptySnapshot');
$bakeName = $this->getBakeName('TestNotEmptySnapshot');
$result = $this->Task->bake($bakeName);

$this->assertCorrectSnapshot(__FUNCTION__, $result);
$this->assertCorrectSnapshot($bakeName, $result);
}

public function testAutoIdDisabledSnapshot()
Expand All @@ -97,9 +99,10 @@ public function testAutoIdDisabledSnapshot()
$this->Task->params['connection'] = 'test';
$this->Task->params['plugin'] = 'BogusPlugin';

$result = $this->Task->bake('AutoIdDisabledSnapshot');
$bakeName = $this->getBakeName('TestAutoIdDisabledSnapshot');
$result = $this->Task->bake($bakeName);

$this->assertCorrectSnapshot(__FUNCTION__, $result);
$this->assertCorrectSnapshot($bakeName, $result);
}

public function testCompositeConstraintsSnapshot()
Expand All @@ -116,18 +119,31 @@ public function testCompositeConstraintsSnapshot()

$this->Task->params['require-table'] = false;
$this->Task->params['connection'] = 'test';
$result = $this->Task->bake('CompositeConstraintsSnapshot');

$this->assertCorrectSnapshot(__FUNCTION__, $result);
$bakeName = $this->getBakeName('TestCompositeConstraintsSnapshot');
$result = $this->Task->bake($bakeName);

$this->assertCorrectSnapshot($bakeName, $result);
}

public function getBakeName($name)
{
$dbenv = getenv("DB");
if ($dbenv !== 'mysql') {
$name .= ucfirst($dbenv);
}

return $name;
}

public function assertCorrectSnapshot($function, $result)
public function assertCorrectSnapshot($bakeName, $result)
{
$dbenv = getenv("DB");
if (file_exists($this->_compareBasePath . $dbenv . DS . $function . '.php')) {
$this->assertSameAsFile($dbenv . DS . $function . '.php', $result);
$bakeName = Inflector::underscore($bakeName);
if (file_exists($this->_compareBasePath . $dbenv . DS . $bakeName . '.php')) {
$this->assertSameAsFile($dbenv . DS . $bakeName . '.php', $result);
} else {
$this->assertSameAsFile($function . '.php', $result);
$this->assertSameAsFile($bakeName . '.php', $result);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
use Migrations\AbstractMigration;

class AutoIdDisabledSnapshot extends AbstractMigration
class TestAutoIdDisabledSnapshotPgsql extends AbstractMigration
{

public $autoId = false;
Expand Down Expand Up @@ -297,14 +297,12 @@ public function down()
)
->dropForeignKey(
'product_id'
)
->update();
);

$this->table('products')
->dropForeignKey(
'category_id'
)
->update();
);

$this->dropTable('articles');
$this->dropTable('categories');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
use Migrations\AbstractMigration;

class CompositeConstraintsSnapshot extends AbstractMigration
class TestCompositeConstraintsSnapshotPgsql extends AbstractMigration
{
public function up()
{
Expand Down Expand Up @@ -295,23 +295,20 @@ public function down()
)
->dropForeignKey(
'product_id'
)
->update();
);

$this->table('orders')
->dropForeignKey(
[
'product_category',
'product_id',
]
)
->update();
);

$this->table('products')
->dropForeignKey(
'category_id'
)
->update();
);

$this->dropTable('articles');
$this->dropTable('categories');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
use Migrations\AbstractMigration;

class NotEmptySnapshot extends AbstractMigration
class TestNotEmptySnapshotPgsql extends AbstractMigration
{
public function up()
{
Expand Down Expand Up @@ -257,14 +257,12 @@ public function down()
)
->dropForeignKey(
'product_id'
)
->update();
);

$this->table('products')
->dropForeignKey(
'category_id'
)
->update();
);

$this->dropTable('articles');
$this->dropTable('categories');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
use Migrations\AbstractMigration;

class AutoIdDisabledSnapshot extends AbstractMigration
class TestAutoIdDisabledSnapshotSqlite extends AbstractMigration
{

public $autoId = false;
Expand Down Expand Up @@ -296,14 +296,12 @@ public function down()
)
->dropForeignKey(
'product_id'
)
->update();
);

$this->table('products')
->dropForeignKey(
'category_id'
)
->update();
);

$this->dropTable('articles');
$this->dropTable('categories');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
use Migrations\AbstractMigration;

class CompositeConstraintsSnapshot extends AbstractMigration
class TestCompositeConstraintsSnapshotSqlite extends AbstractMigration
{
public function up()
{
Expand Down Expand Up @@ -294,23 +294,20 @@ public function down()
)
->dropForeignKey(
'product_id'
)
->update();
);

$this->table('orders')
->dropForeignKey(
[
'product_category',
'product_id',
]
)
->update();
);

$this->table('products')
->dropForeignKey(
'category_id'
)
->update();
);

$this->dropTable('articles');
$this->dropTable('categories');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
use Migrations\AbstractMigration;

class NotEmptySnapshot extends AbstractMigration
class TestNotEmptySnapshotSqlite extends AbstractMigration
{
public function up()
{
Expand Down Expand Up @@ -256,14 +256,12 @@ public function down()
)
->dropForeignKey(
'product_id'
)
->update();
);

$this->table('products')
->dropForeignKey(
'category_id'
)
->update();
);

$this->dropTable('articles');
$this->dropTable('categories');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
use Migrations\AbstractMigration;

class AutoIdDisabledSnapshot extends AbstractMigration
class TestAutoIdDisabledSnapshot extends AbstractMigration
{

public $autoId = false;
Expand Down Expand Up @@ -297,14 +297,12 @@ public function down()
)
->dropForeignKey(
'product_id'
)
->update();
);

$this->table('products')
->dropForeignKey(
'category_id'
)
->update();
);

$this->dropTable('articles');
$this->dropTable('categories');
Expand Down
Loading

0 comments on commit 19f31d1

Please sign in to comment.