Exemple #1
0
 /**
  * @param AdapterInterface $adapter
  */
 public function __construct(AdapterInterface $adapter)
 {
     $this->adapter = $adapter;
     $classNameCreator = new ClassNameCreator((new ReflectionClass($this))->getFileName());
     $this->datetime = $classNameCreator->getDatetime();
     $this->className = $classNameCreator->getClassName();
     $this->fullClassName = $classNameCreator->getClassName();
 }
 public function testClassName()
 {
     $filepath = __DIR__ . '/../fake/structure/migration_directory_1/20150428140909_first_migration.php';
     $creator = new ClassNameCreator($filepath);
     $this->assertEquals('\\Fake\\Migration\\First', $creator->getClassName());
     $this->assertEquals('20150428140909', $creator->getDatetime());
     $filepath = __DIR__ . '/../fake/structure/migration_directory_1/20150518091732_second_change_of_something.php';
     $creator = new ClassNameCreator($filepath);
     $this->assertEquals('\\SecondChangeOfSomething', $creator->getClassName());
     $this->assertEquals('20150518091732', $creator->getDatetime());
     $filepath = __DIR__ . '/../fake/structure/migration_directory_3/20150709132012_third.php';
     $creator = new ClassNameCreator($filepath);
     $this->assertEquals('\\Phoenix\\Tests\\Fake\\Structure\\Third', $creator->getClassName());
     $this->assertEquals('20150709132012', $creator->getDatetime());
     $filepath = __DIR__ . '/../fake/structure/migration_directory_2/20150921111111_fourth_add.php';
     $creator = new ClassNameCreator($filepath);
     $this->assertEquals('\\FourthAdd', $creator->getClassName());
     $this->assertEquals('20150921111111', $creator->getDatetime());
 }
Exemple #3
0
 private function findMigrations($type)
 {
     $filesFinder = new FilesFinder();
     foreach ($this->config->getMigrationDirs() as $directory) {
         $filesFinder->addDirectory($directory);
     }
     $executedMigrations = $this->executedMigrations();
     $migrations = [];
     foreach ($filesFinder->getFiles() as $file) {
         require_once $file;
         $classNameCreator = new ClassNameCreator($file);
         $className = $classNameCreator->getClassName();
         $migrationIdentifier = $classNameCreator->getDatetime() . '|' . $className;
         if ($type == self::TYPE_UP && !isset($executedMigrations[$migrationIdentifier])) {
             $migrations[$migrationIdentifier] = new $className($this->adapter);
         } elseif ($type == self::TYPE_DOWN && isset($executedMigrations[$migrationIdentifier])) {
             $migrations[$migrationIdentifier] = new $className($this->adapter);
         }
     }
     ksort($migrations);
     return $migrations;
 }