public function testReturnsCompleteMigrationObject()
 {
     $pdo = $this->aNewInitializedSchema();
     $logMigration = new LogMigration($pdo);
     $logMigration->logSuccess(MigrationFileMockFactory::mockMigrationFile("v0_test.sql", "hash0"));
     $migration = (new LoadMigrations($pdo))->allInstalledMigrations()[0];
     $this->assertEquals("1", $migration->getId());
     $this->assertTrue($migration->getInstalledAt() instanceof \DateTime);
     $this->assertEquals("v0_test.sql", $migration->getFilename());
     $this->assertEquals("hash0", $migration->getChecksum());
     $this->assertEquals(true, $migration->getSuccess());
 }
Example #2
0
 public function __invoke()
 {
     $fileScanner = new MigrationFileScanner($this->sqlDirectory);
     $loadMigrations = new LoadMigrations($this->pdo);
     $migrationsToInstall = (new Planner($fileScanner, $loadMigrations))->findMigrationsToInstall();
     $runMigration = new RunMigration($this->pdo);
     $logMigration = new LogMigration($this->pdo);
     foreach ($migrationsToInstall as $migration) {
         try {
             $runMigration->run($migration);
         } catch (\Exception $e) {
             $logMigration->logFailure($migration);
             throw new MigrationException("Could not Execute Migration " . $migration->getFile()->getPathname(), $e);
         }
         $logMigration->logSuccess($migration);
     }
 }