15
15
use Doctrine \Migrations \Metadata \Storage \MetadataStorage ;
16
16
use Doctrine \Migrations \MigratorConfiguration ;
17
17
use Doctrine \Migrations \ParameterFormatter ;
18
+ use Doctrine \Migrations \Provider \DBALSchemaDiffProvider ;
18
19
use Doctrine \Migrations \Provider \SchemaDiffProvider ;
19
20
use Doctrine \Migrations \Tests \Stub \Functional \MigrateNotTouchingTheSchema ;
21
+ use Doctrine \Migrations \Tests \Stub \Functional \MigrateWithDeferredSql ;
20
22
use Doctrine \Migrations \Tests \Stub \Functional \MigrationThrowsError ;
21
23
use Doctrine \Migrations \Tests \Stub \NonTransactional \MigrationNonTransactional ;
22
24
use Doctrine \Migrations \Version \DbalExecutor ;
@@ -73,6 +75,32 @@ public function testGetSql(): void
73
75
);
74
76
}
75
77
78
+ public function testQueriesOrder (): void
79
+ {
80
+ $ this ->config ->addMigrationsDirectory ('DoctrineMigrations \\' , __DIR__ . '/Stub/migrations-empty-folder ' );
81
+
82
+ $ conn = $ this ->getSqliteConnection ();
83
+ $ migrator = $ this ->createTestMigrator (
84
+ schemaDiff: new DBALSchemaDiffProvider ($ conn ->createSchemaManager (), $ conn ->getDatabasePlatform ()),
85
+ );
86
+
87
+ $ migration = new MigrateWithDeferredSql ($ conn , $ this ->logger );
88
+ $ plan = new MigrationPlan (new Version (MigrateWithDeferredSql::class), $ migration , Direction::UP );
89
+ $ planList = new MigrationPlanList ([$ plan ], Direction::UP );
90
+
91
+ $ sql = $ migrator ->migrate ($ planList , $ this ->migratorConfiguration );
92
+
93
+ self ::assertArrayHasKey (MigrateWithDeferredSql::class, $ sql );
94
+ self ::assertSame (
95
+ [
96
+ 'SELECT 1 ' ,
97
+ 'CREATE TABLE test (id INTEGER NOT NULL) ' ,
98
+ 'INSERT INTO test(id) VALUES(123) ' ,
99
+ ],
100
+ array_map (strval (...), $ sql [MigrateWithDeferredSql::class]),
101
+ );
102
+ }
103
+
76
104
public function testEmptyPlanShowsMessage (): void
77
105
{
78
106
$ migrator = $ this ->createTestMigrator ();
@@ -84,7 +112,7 @@ public function testEmptyPlanShowsMessage(): void
84
112
self ::assertStringContainsString ('No migrations ' , $ this ->logger ->records [0 ]['message ' ]);
85
113
}
86
114
87
- protected function createTestMigrator (): DbalMigrator
115
+ protected function createTestMigrator (SchemaDiffProvider | null $ schemaDiff = null ): DbalMigrator
88
116
{
89
117
$ eventManager = new EventManager ();
90
118
$ eventDispatcher = new EventDispatcher ($ this ->conn , $ eventManager );
@@ -94,7 +122,7 @@ protected function createTestMigrator(): DbalMigrator
94
122
$ stopwatch = new Stopwatch ();
95
123
$ paramFormatter = $ this ->createMock (ParameterFormatter::class);
96
124
$ storage = $ this ->createMock (MetadataStorage::class);
97
- $ schemaDiff = $ this ->createMock (SchemaDiffProvider::class);
125
+ $ schemaDiff ?? = $ this ->createMock (SchemaDiffProvider::class);
98
126
99
127
return new DbalMigrator (
100
128
$ this ->conn ,
0 commit comments