| author | ymh <ymh.work@gmail.com> |
| Fri, 25 Nov 2011 18:55:43 +0100 | |
| changeset 39 | 03b14b0fe101 |
| permissions | -rw-r--r-- |
|
39
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
1 |
<?php |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
2 |
|
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
3 |
namespace Doctrine\DBAL\Migrations\Tests\Functional; |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
4 |
|
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
5 |
use Doctrine\DBAL\DriverManager; |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
6 |
use Doctrine\DBAL\Schema\Schema; |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
7 |
use Doctrine\DBAL\Migrations\Configuration\Configuration; |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
8 |
|
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
9 |
class FunctionalTest extends \Doctrine\DBAL\Migrations\Tests\MigrationTestCase |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
10 |
{ |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
11 |
/** |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
12 |
* @var Configuration |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
13 |
*/ |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
14 |
private $config; |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
15 |
|
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
16 |
/** |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
17 |
* @var Connection |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
18 |
*/ |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
19 |
private $connection; |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
20 |
|
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
21 |
public function setUp() |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
22 |
{ |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
23 |
$this->connection = $this->getSqliteConnection(); |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
24 |
$this->config = new Configuration($this->connection); |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
25 |
$this->config->setMigrationsNamespace('Doctrine\DBAL\Migrations\Tests\Functional'); |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
26 |
$this->config->setMigrationsDirectory('.'); |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
27 |
} |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
28 |
|
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
29 |
public function testMigrateUp() |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
30 |
{ |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
31 |
$version = new \Doctrine\DBAL\Migrations\Version($this->config, 1, 'Doctrine\DBAL\Migrations\Tests\Functional\MigrationMigrateUp'); |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
32 |
|
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
33 |
$this->assertFalse($this->config->hasVersionMigrated($version)); |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
34 |
$version->execute('up'); |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
35 |
|
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
36 |
$schema = $this->connection->getSchemaManager()->createSchema(); |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
37 |
$this->assertTrue($schema->hasTable('foo')); |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
38 |
$this->assertTrue($schema->getTable('foo')->hasColumn('id')); |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
39 |
$this->assertTrue($this->config->hasVersionMigrated($version)); |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
40 |
} |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
41 |
|
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
42 |
public function testMigrateDown() |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
43 |
{ |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
44 |
$version = new \Doctrine\DBAL\Migrations\Version($this->config, 1, 'Doctrine\DBAL\Migrations\Tests\Functional\MigrationMigrateUp'); |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
45 |
|
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
46 |
$this->assertFalse($this->config->hasVersionMigrated($version)); |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
47 |
$version->execute('up'); |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
48 |
|
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
49 |
$schema = $this->connection->getSchemaManager()->createSchema(); |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
50 |
$this->assertTrue($schema->hasTable('foo')); |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
51 |
$this->assertTrue($schema->getTable('foo')->hasColumn('id')); |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
52 |
$this->assertTrue($this->config->hasVersionMigrated($version)); |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
53 |
|
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
54 |
$version->execute('down'); |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
55 |
$schema = $this->connection->getSchemaManager()->createSchema(); |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
56 |
$this->assertFalse($schema->hasTable('foo')); |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
57 |
$this->assertFalse($this->config->hasVersionMigrated($version)); |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
58 |
|
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
59 |
} |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
60 |
|
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
61 |
public function testSkipMigrateUp() |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
62 |
{ |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
63 |
$version = new \Doctrine\DBAL\Migrations\Version($this->config, 1, 'Doctrine\DBAL\Migrations\Tests\Functional\MigrationSkipMigration'); |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
64 |
|
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
65 |
$this->assertFalse($this->config->hasVersionMigrated($version)); |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
66 |
$version->execute('up'); |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
67 |
|
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
68 |
$schema = $this->connection->getSchemaManager()->createSchema(); |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
69 |
$this->assertFalse($schema->hasTable('foo')); |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
70 |
|
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
71 |
$this->assertTrue($this->config->hasVersionMigrated($version)); |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
72 |
} |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
73 |
|
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
74 |
public function testMigrateSeveralSteps() |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
75 |
{ |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
76 |
$this->config->registerMigration(1, 'Doctrine\DBAL\Migrations\Tests\Functional\MigrationMigrateUp'); |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
77 |
$this->config->registerMigration(2, 'Doctrine\DBAL\Migrations\Tests\Functional\MigrationSkipMigration'); |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
78 |
$this->config->registerMigration(3, 'Doctrine\DBAL\Migrations\Tests\Functional\MigrationMigrateFurther'); |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
79 |
|
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
80 |
$this->assertEquals(0, $this->config->getCurrentVersion()); |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
81 |
$migrations = $this->config->getMigrationsToExecute('up', 3); |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
82 |
|
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
83 |
$this->assertEquals(3, count($migrations)); |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
84 |
$this->assertInstanceOf('Doctrine\DBAL\Migrations\Tests\Functional\MigrationMigrateUp', $migrations[1]->getMigration()); |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
85 |
$this->assertInstanceOf('Doctrine\DBAL\Migrations\Tests\Functional\MigrationSkipMigration', $migrations[2]->getMigration()); |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
86 |
$this->assertInstanceOf('Doctrine\DBAL\Migrations\Tests\Functional\MigrationMigrateFurther', $migrations[3]->getMigration()); |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
87 |
|
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
88 |
$migration = new \Doctrine\DBAL\Migrations\Migration($this->config); |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
89 |
$migration->migrate(3); |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
90 |
|
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
91 |
$schema = $this->config->getConnection()->getSchemaManager()->createSchema(); |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
92 |
$this->assertTrue($schema->hasTable('foo')); |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
93 |
$this->assertTrue($schema->hasTable('bar')); |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
94 |
|
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
95 |
$this->assertEquals(3, $this->config->getCurrentVersion()); |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
96 |
$this->assertTrue($migrations[1]->isMigrated()); |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
97 |
$this->assertTrue($migrations[2]->isMigrated()); |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
98 |
$this->assertTrue($migrations[3]->isMigrated()); |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
99 |
} |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
100 |
|
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
101 |
public function testMigrateToLastVersion() |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
102 |
{ |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
103 |
$this->config->registerMigration(1, 'Doctrine\DBAL\Migrations\Tests\Functional\MigrationMigrateUp'); |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
104 |
$this->config->registerMigration(2, 'Doctrine\DBAL\Migrations\Tests\Functional\MigrationSkipMigration'); |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
105 |
$this->config->registerMigration(3, 'Doctrine\DBAL\Migrations\Tests\Functional\MigrationMigrateFurther'); |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
106 |
|
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
107 |
$migration = new \Doctrine\DBAL\Migrations\Migration($this->config); |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
108 |
$migration->migrate(); |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
109 |
|
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
110 |
$this->assertEquals(3, $this->config->getCurrentVersion()); |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
111 |
$migrations = $this->config->getMigrations(); |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
112 |
$this->assertTrue($migrations[1]->isMigrated()); |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
113 |
$this->assertTrue($migrations[2]->isMigrated()); |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
114 |
$this->assertTrue($migrations[3]->isMigrated()); |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
115 |
} |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
116 |
|
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
117 |
public function testDryRunMigration() |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
118 |
{ |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
119 |
$this->config->registerMigration(1, 'Doctrine\DBAL\Migrations\Tests\Functional\MigrationMigrateUp'); |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
120 |
$this->config->registerMigration(2, 'Doctrine\DBAL\Migrations\Tests\Functional\MigrationSkipMigration'); |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
121 |
$this->config->registerMigration(3, 'Doctrine\DBAL\Migrations\Tests\Functional\MigrationMigrateFurther'); |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
122 |
|
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
123 |
$migration = new \Doctrine\DBAL\Migrations\Migration($this->config); |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
124 |
$migration->migrate(3, true); |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
125 |
|
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
126 |
$schema = $this->config->getConnection()->getSchemaManager()->createSchema(); |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
127 |
$this->assertFalse($schema->hasTable('foo')); |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
128 |
$this->assertFalse($schema->hasTable('bar')); |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
129 |
|
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
130 |
$this->assertEquals(0, $this->config->getCurrentVersion()); |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
131 |
$migrations = $this->config->getMigrations(); |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
132 |
$this->assertFalse($migrations[1]->isMigrated()); |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
133 |
$this->assertFalse($migrations[2]->isMigrated()); |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
134 |
$this->assertFalse($migrations[3]->isMigrated()); |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
135 |
} |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
136 |
|
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
137 |
public function testMigrateDownSeveralSteps() |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
138 |
{ |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
139 |
$this->config->registerMigration(1, 'Doctrine\DBAL\Migrations\Tests\Functional\MigrationMigrateUp'); |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
140 |
$this->config->registerMigration(2, 'Doctrine\DBAL\Migrations\Tests\Functional\MigrationSkipMigration'); |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
141 |
$this->config->registerMigration(3, 'Doctrine\DBAL\Migrations\Tests\Functional\MigrationMigrateFurther'); |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
142 |
|
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
143 |
$migration = new \Doctrine\DBAL\Migrations\Migration($this->config); |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
144 |
$migration->migrate(3); |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
145 |
$this->assertEquals(3, $this->config->getCurrentVersion()); |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
146 |
$migration->migrate(0); |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
147 |
|
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
148 |
$schema = $this->config->getConnection()->getSchemaManager()->createSchema(); |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
149 |
$this->assertFalse($schema->hasTable('foo')); |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
150 |
$this->assertFalse($schema->hasTable('bar')); |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
151 |
|
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
152 |
$this->assertEquals(0, $this->config->getCurrentVersion()); |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
153 |
$migrations = $this->config->getMigrations(); |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
154 |
$this->assertFalse($migrations[1]->isMigrated()); |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
155 |
$this->assertFalse($migrations[2]->isMigrated()); |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
156 |
$this->assertFalse($migrations[3]->isMigrated()); |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
157 |
} |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
158 |
|
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
159 |
public function testAddSql() |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
160 |
{ |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
161 |
$this->config->registerMigration(1, 'Doctrine\DBAL\Migrations\Tests\Functional\MigrateAddSqlTest'); |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
162 |
|
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
163 |
$migration = new \Doctrine\DBAL\Migrations\Migration($this->config); |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
164 |
$migration->migrate(1); |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
165 |
|
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
166 |
$migrations = $this->config->getMigrations(); |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
167 |
$this->assertTrue($migrations[1]->isMigrated()); |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
168 |
|
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
169 |
$schema = $this->config->getConnection()->getSchemaManager()->createSchema(); |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
170 |
$this->assertTrue($schema->hasTable('test_add_sql_table')); |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
171 |
$check = $this->config->getConnection()->fetchAll('select * from test_add_sql_table'); |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
172 |
$this->assertNotEmpty($check); |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
173 |
$this->assertEquals('test', $check[0]['test']); |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
174 |
|
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
175 |
$migration->migrate(0); |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
176 |
$this->assertFalse($migrations[1]->isMigrated()); |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
177 |
$schema = $this->config->getConnection()->getSchemaManager()->createSchema(); |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
178 |
$this->assertFalse($schema->hasTable('test_add_sql_table')); |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
179 |
} |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
180 |
} |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
181 |
|
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
182 |
class MigrateAddSqlTest extends \Doctrine\DBAL\Migrations\AbstractMigration |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
183 |
{ |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
184 |
public function up(Schema $schema) |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
185 |
{ |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
186 |
$this->addSql("CREATE TABLE test_add_sql_table (test varchar(255))"); |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
187 |
$this->addSql("INSERT INTO test_add_sql_table (test) values (?)", array('test')); |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
188 |
} |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
189 |
|
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
190 |
public function down(Schema $schema) |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
191 |
{ |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
192 |
$this->addSql("DROP TABLE test_add_sql_table"); |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
193 |
} |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
194 |
} |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
195 |
|
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
196 |
class MigrationMigrateUp extends \Doctrine\DBAL\Migrations\AbstractMigration |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
197 |
{ |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
198 |
public function down(Schema $schema) |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
199 |
{ |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
200 |
$schema->dropTable('foo'); |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
201 |
} |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
202 |
|
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
203 |
public function up(Schema $schema) |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
204 |
{ |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
205 |
$table = $schema->createTable('foo'); |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
206 |
$table->addColumn('id', 'integer'); |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
207 |
} |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
208 |
} |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
209 |
|
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
210 |
class MigrationSkipMigration extends MigrationMigrateUp |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
211 |
{ |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
212 |
|
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
213 |
public function preUp(Schema $schema) |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
214 |
{ |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
215 |
$this->skipIf(true); |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
216 |
} |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
217 |
|
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
218 |
public function preDown(Schema $schema) |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
219 |
{ |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
220 |
$this->skipIf(true); |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
221 |
} |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
222 |
} |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
223 |
|
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
224 |
class MigrationMigrateFurther extends \Doctrine\DBAL\Migrations\AbstractMigration |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
225 |
{ |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
226 |
|
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
227 |
public function down(Schema $schema) |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
228 |
{ |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
229 |
$schema->dropTable('bar'); |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
230 |
} |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
231 |
|
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
232 |
public function up(Schema $schema) |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
233 |
{ |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
234 |
$table = $schema->createTable('bar'); |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
235 |
$table->addColumn('id', 'integer'); |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
236 |
} |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
237 |
|
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
238 |
} |