Example #1
0
 /**
  * Gets an array of the database migrations.
  *
  * @throws \InvalidArgumentException
  * @return AbstractMigration[]
  */
 public function getMigrations()
 {
     if (empty($this->_migrations)) {
         $fileNames = [];
         $versions = [];
         $phpFiles = glob($this->_config->getMigrationPath() . DIRECTORY_SEPARATOR . '*.php');
         foreach ($phpFiles as $filePath) {
             if (Util::isValidMigrationFileName(basename($filePath))) {
                 $version = Util::getVersionFromFileName(basename($filePath));
                 if (isset($versions[$version])) {
                     throw new \InvalidArgumentException(__d('union_dev', 'Duplicate migration - "%s" has the same version as "%s"', $filePath, $versions[$version]->getVersion()));
                 }
                 //  Convert the filename to a class name.
                 $class = Util::mapFileNameToClassName(basename($filePath));
                 if (isset($fileNames[$class])) {
                     throw new \InvalidArgumentException(__d('union_dev', 'Migration "%s" has the same name as "%s"', basename($filePath), $fileNames[$class]));
                 }
                 $fileNames[$class] = basename($filePath);
                 // Load the migration file.
                 /** @noinspection PhpIncludeInspection */
                 require_once $filePath;
                 if (!class_exists($class)) {
                     throw new \InvalidArgumentException(__d('union_dev', 'Could not find class "%s" in file "%s"', $class, $filePath));
                 }
                 //  Instantiate migration class.
                 $migration = new $class($version);
                 if (!$migration instanceof AbstractMigration) {
                     throw new \InvalidArgumentException(__d('union_dev', 'The class "%s" in file "%s" must extend \\Phinx\\Migration\\AbstractMigration', $class, $filePath));
                 }
                 $versions[$version] = $migration;
             }
         }
         ksort($versions);
         $this->_migrations = $versions;
     }
     return $this->_migrations;
 }
 /**
  * Normal behavior
  */
 public function testGetMigrationPath()
 {
     $config = new Config($this->getConfigArray());
     $this->assertEquals($this->getMigrationPath(), $config->getMigrationPath());
 }