public function testMigrationInitAndCheck()
 {
     // First time the App run, the object ObjA go in version 1
     $migration = new Migration();
     $migration->addObject('ObjA');
     $migration->show();
     $migration->check();
     $version = ObjectVersion::get('ObjA');
     $this->assertEquals($version, 1);
     // First time the App run, the object ObjB go in version 2
     $migration = new Migration();
     $migration->addObject('ObjB');
     $migration->show();
     $migration->check();
     $version = ObjectVersion::get('ObjB');
     $this->assertEquals($version, 2);
 }
Exemplo n.º 2
0
 public function _perform($class)
 {
     $version = ObjectVersion::get($class);
     echo 'Object ' . $class . ' is in version ' . $version . PHP_EOL;
     while (true) {
         $migrateFunction = 'migrate_' . $version . '_' . ($version + 1);
         if (method_exists($class, $migrateFunction) === false) {
             break;
         }
         echo 'Migrate from ' . $version . ' to ' . ($version + 1) . PHP_EOL;
         $ok = forward_static_call(array($class, $migrateFunction));
         if ($ok !== true) {
             echo 'Failed' . PHP_EOL;
             break;
         }
         $version = ObjectVersion::inc($class);
         echo 'Ok' . PHP_EOL;
     }
 }