Skip to content

Commit 2fe046d

Browse files
committed
fixup! fix: Database Migration does set current version in DB #98
1 parent a699c32 commit 2fe046d

File tree

1 file changed

+76
-0
lines changed

1 file changed

+76
-0
lines changed

tests/Migration/MysqlTestCase.php

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<?php
2+
/*
3+
* $Id$
4+
*
5+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
6+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
7+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
8+
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
9+
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
10+
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
11+
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
12+
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
13+
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
14+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
15+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
16+
*
17+
* This software consists of voluntary contributions made by many individuals
18+
* and is licensed under the LGPL. For more information, see
19+
* <http://www.doctrine-project.org>.
20+
*/
21+
22+
/**
23+
* Doctrine_Migration_TestCase
24+
*
25+
* @package Doctrine
26+
* @author Konsta Vesterinen <[email protected]>
27+
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
28+
* @category Object Relational Mapping
29+
* @link www.doctrine-project.org
30+
* @since 1.0
31+
* @version $Revision$
32+
*/
33+
class Doctrine_Migration_Mysql_TestCase extends Doctrine_UnitTestCase
34+
{
35+
private $migration;
36+
37+
const TABLES = array(
38+
'MigrationPhonenumber',
39+
'MigrationUser',
40+
'MigrationProfile',
41+
);
42+
43+
protected $tables = self::TABLES;
44+
45+
public function setUp()
46+
{
47+
parent::setUp();
48+
49+
$connection = $this->openMysqlAdditionalConnection();
50+
$this->resetTablesOnConnection(self::TABLES, $connection);
51+
52+
$this->migration = new Doctrine_Migration('migration_classes', $connection);
53+
}
54+
55+
public function test_afterSuccessfullMigration_willSetMigratedVersionAsCurrentVersionInMysqlDB()
56+
{
57+
$this->migration->setCurrentVersion(3);
58+
59+
$this->migration->migrate(4);
60+
61+
$this->assertEqual(4, $this->migration->getCurrentVersion());
62+
}
63+
64+
public function test_afterFailedMigration_willKeepCurrentVersionInMysqlDB()
65+
{
66+
$this->migration->setCurrentVersion(0);
67+
68+
try {
69+
$this->migration->migrate(1);
70+
71+
$this->fail('migration must fail');
72+
} catch (Doctrine_Migration_Exception $e) {
73+
$this->assertEqual(0, $this->migration->getCurrentVersion());
74+
}
75+
}
76+
}

0 commit comments

Comments
 (0)