1515use Doctrine \Migrations \Metadata \Storage \MetadataStorage ;
1616use Doctrine \Migrations \MigratorConfiguration ;
1717use Doctrine \Migrations \ParameterFormatter ;
18+ use Doctrine \Migrations \Provider \DBALSchemaDiffProvider ;
1819use Doctrine \Migrations \Provider \SchemaDiffProvider ;
1920use Doctrine \Migrations \Tests \Stub \Functional \MigrateNotTouchingTheSchema ;
21+ use Doctrine \Migrations \Tests \Stub \Functional \MigrateWithDeferredSql ;
2022use Doctrine \Migrations \Tests \Stub \Functional \MigrationThrowsError ;
2123use Doctrine \Migrations \Tests \Stub \NonTransactional \MigrationNonTransactional ;
2224use Doctrine \Migrations \Version \DbalExecutor ;
@@ -73,6 +75,32 @@ public function testGetSql(): void
7375 );
7476 }
7577
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+
76104 public function testEmptyPlanShowsMessage (): void
77105 {
78106 $ migrator = $ this ->createTestMigrator ();
@@ -84,7 +112,7 @@ public function testEmptyPlanShowsMessage(): void
84112 self ::assertStringContainsString ('No migrations ' , $ this ->logger ->records [0 ]['message ' ]);
85113 }
86114
87- protected function createTestMigrator (): DbalMigrator
115+ protected function createTestMigrator (? SchemaDiffProvider $ schemaDiff = null ): DbalMigrator
88116 {
89117 $ eventManager = new EventManager ();
90118 $ eventDispatcher = new EventDispatcher ($ this ->conn , $ eventManager );
@@ -94,7 +122,7 @@ protected function createTestMigrator(): DbalMigrator
94122 $ stopwatch = new Stopwatch ();
95123 $ paramFormatter = $ this ->createMock (ParameterFormatter::class);
96124 $ storage = $ this ->createMock (MetadataStorage::class);
97- $ schemaDiff = $ this ->createMock (SchemaDiffProvider::class);
125+ $ schemaDiff = $ schemaDiff ?: $ this ->createMock (SchemaDiffProvider::class);
98126
99127 return new DbalMigrator (
100128 $ this ->conn ,
0 commit comments