|
12 | 12 | namespace Spiral\Migrations\Tests; |
13 | 13 |
|
14 | 14 | use Spiral\Migrations\Capsule; |
15 | | -use Spiral\Migrations\State; |
16 | 15 | use Spiral\Migrations\Exception\MigrationException; |
| 16 | +use Spiral\Migrations\State; |
17 | 17 |
|
18 | 18 | abstract class MigratorTest extends BaseTest |
19 | 19 | { |
| 20 | + public function testSortingOrder(): void |
| 21 | + { |
| 22 | + $files = [ |
| 23 | + '20200909.024119_333_333_migration_1.php' => 'A3', |
| 24 | + '20200909.030203_22_22_migration_1.php' => 'B2', |
| 25 | + '20200909.030203_23_23_migration_1.php' => 'B3', |
| 26 | + '20200909.024119_1_1_migration_1.php' => 'A1', |
| 27 | + '20200909.024119_22_22_migration_2.php' => 'A2', |
| 28 | + '20200909.024119_4444_4444_migration_2.php' => 'A4', |
| 29 | + '20200923.040608_0_0_migration_3.php' => 'C', |
| 30 | + '20200909.030203_1_1_migration_1.php' => 'B1', |
| 31 | + ]; |
| 32 | + $stub = file_get_contents(__DIR__ . '/../files/migration.stub'); |
| 33 | + foreach ($files as $name => $class) { |
| 34 | + file_put_contents(__DIR__ . "/../files/$name", sprintf($stub, $class)); |
| 35 | + } |
| 36 | + |
| 37 | + $migrations = $this->repository->getMigrations(); |
| 38 | + $classes = array_map( |
| 39 | + static function ($migration) { |
| 40 | + return get_class($migration); |
| 41 | + }, |
| 42 | + array_values($migrations) |
| 43 | + ); |
| 44 | + |
| 45 | + $this->assertSame(['A1', 'A2', 'A3', 'A4', 'B1', 'B2', 'B3', 'C'], $classes); |
| 46 | + } |
| 47 | + |
20 | 48 | public function testIsConfigured(): void |
21 | 49 | { |
22 | 50 | $this->assertFalse($this->migrator->isConfigured()); |
@@ -101,11 +129,9 @@ public function testCapsule(): void |
101 | 129 | $this->assertTrue($capsule->getTable('test')->exists()); |
102 | 130 | } |
103 | 131 |
|
104 | | - /** |
105 | | - * @expectedException \Spiral\Migrations\Exception\CapsuleException |
106 | | - */ |
107 | 132 | public function testCapsuleException(): void |
108 | 133 | { |
| 134 | + $this->expectException(\Spiral\Migrations\Exception\CapsuleException::class); |
109 | 135 | $capsule = new Capsule($this->db); |
110 | 136 |
|
111 | 137 | $capsule->execute([ |
|
0 commit comments