From 612966a988ef8718c95a4af62b84ea3fc5b193be Mon Sep 17 00:00:00 2001 From: Alexandre Quercia Date: Fri, 24 May 2024 19:23:09 +0200 Subject: [PATCH] fixup! fix: Database Migration does set current version in DB #98 --- tests/Migration/MysqlTestCase.php | 76 +++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 tests/Migration/MysqlTestCase.php diff --git a/tests/Migration/MysqlTestCase.php b/tests/Migration/MysqlTestCase.php new file mode 100644 index 00000000..955382bb --- /dev/null +++ b/tests/Migration/MysqlTestCase.php @@ -0,0 +1,76 @@ +. + */ + +/** + * Doctrine_Migration_TestCase + * + * @package Doctrine + * @author Konsta Vesterinen + * @license http://www.opensource.org/licenses/lgpl-license.php LGPL + * @category Object Relational Mapping + * @link www.doctrine-project.org + * @since 1.0 + * @version $Revision$ + */ +class Doctrine_Migration_Mysql_TestCase extends Doctrine_UnitTestCase +{ + private $migration; + + const TABLES = array( + 'MigrationPhonenumber', + 'MigrationUser', + 'MigrationProfile', + ); + + protected $tables = self::TABLES; + + public function setUp() + { + parent::setUp(); + + $connection = $this->openMysqlAdditionalConnection(); + $this->resetTablesOnConnection(self::TABLES, $connection); + + $this->migration = new Doctrine_Migration('migration_classes', $connection); + } + + public function test_afterSuccessfullMigration_willSetMigratedVersionAsCurrentVersionInMysqlDB() + { + $this->migration->setCurrentVersion(3); + + $this->migration->migrate(4); + + $this->assertEqual(4, $this->migration->getCurrentVersion()); + } + + public function test_afterFailedMigration_willKeepCurrentVersionInMysqlDB() + { + $this->migration->setCurrentVersion(0); + + try { + $this->migration->migrate(1); + + $this->fail('migration must fail'); + } catch (Doctrine_Migration_Exception $e) { + $this->assertEqual(0, $this->migration->getCurrentVersion()); + } + } +}