aboutsummaryrefslogtreecommitdiffstats
path: root/tests/dbal/migrator_test.php
diff options
context:
space:
mode:
authorNils Adermann <naderman@naderman.de>2011-07-15 11:57:53 -0400
committerNathan Guse <nathaniel.guse@gmail.com>2013-01-09 16:39:59 -0600
commitf817e20f287a21e2dddfba9721f5e02dce162d29 (patch)
treef78eec7bd0b090fb564048b87d01669b155e1627 /tests/dbal/migrator_test.php
parent0e9b7bcae98ec5f864ad8f183ded4fc0040cec28 (diff)
downloadforums-f817e20f287a21e2dddfba9721f5e02dce162d29.tar
forums-f817e20f287a21e2dddfba9721f5e02dce162d29.tar.gz
forums-f817e20f287a21e2dddfba9721f5e02dce162d29.tar.bz2
forums-f817e20f287a21e2dddfba9721f5e02dce162d29.tar.xz
forums-f817e20f287a21e2dddfba9721f5e02dce162d29.zip
[feature/migrations] Basic migrations with schema and data changes
The migrator takes care of applying migrations as necessary. RFC: http://area51.phpbb.com/phpBB/viewtopic.php?f=84&t=41337 PHPBB3-9737
Diffstat (limited to 'tests/dbal/migrator_test.php')
-rw-r--r--tests/dbal/migrator_test.php80
1 files changed, 80 insertions, 0 deletions
diff --git a/tests/dbal/migrator_test.php b/tests/dbal/migrator_test.php
new file mode 100644
index 0000000000..1e7d1343fc
--- /dev/null
+++ b/tests/dbal/migrator_test.php
@@ -0,0 +1,80 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2011 phpBB Group
+* @license http://opensource.org/licenses/gpl-license.php GNU Public License
+*
+*/
+
+require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
+require_once dirname(__FILE__) . '/../../phpBB/includes/db/migrator.php';
+require_once dirname(__FILE__) . '/../../phpBB/includes/db/migration.php';
+require_once dirname(__FILE__) . '/../../phpBB/includes/db/db_tools.php';
+
+require_once dirname(__FILE__) . '/migration/dummy.php';
+require_once dirname(__FILE__) . '/migration/unfulfillable.php';
+
+class phpbb_dbal_migrator_test extends phpbb_database_test_case
+{
+ protected $db;
+ protected $db_tools;
+ protected $migrator;
+
+ public function getDataSet()
+ {
+ return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/migrator.xml');
+ }
+
+ public function setup()
+ {
+ parent::setup();
+
+ $this->db = $this->new_dbal();
+ $this->db_tools = new phpbb_db_tools($this->db);
+ $this->migrator = new phpbb_db_migrator($this->db, $this->db_tools, MIGRATIONS_TABLE);
+ }
+
+ public function test_update()
+ {
+ $this->migrator->set_migrations(array('phpbb_dbal_migration_dummy'));
+
+ // schema
+ $this->migrator->update();
+ $this->assertFalse($this->migrator->finished());
+
+ // data
+ $this->migrator->update();
+ $this->assertTrue($this->migrator->finished());
+
+ $this->assertSqlResultEquals(
+ array(array('extra_column' => '1')),
+ "SELECT extra_column FROM phpbb_config WHERE config_name = 'foo'",
+ 'Dummy migration created extra_column with value 1 in all rows.'
+ );
+
+ // cleanup
+ $this->db_tools->sql_column_remove('phpbb_config', 'extra_column');
+ }
+
+ public function test_unfulfillable()
+ {
+ $this->migrator->set_migrations(array('phpbb_dbal_migration_unfulfillable', 'phpbb_dbal_migration_dummy'));
+
+ while (!$this->migrator->finished())
+ {
+ $this->migrator->update();
+ }
+
+ $this->assertTrue($this->migrator->finished());
+
+ $this->assertSqlResultEquals(
+ array(array('extra_column' => '1')),
+ "SELECT extra_column FROM phpbb_config WHERE config_name = 'foo'",
+ 'Dummy migration was run, even though an unfulfillable migration was found.'
+ );
+
+ // cleanup
+ $this->db_tools->sql_column_remove('phpbb_config', 'extra_column');
+ }
+}