protected function doApply() { $dataDir = $this->dataDir->getAbsolutePath(); $htmlDir = $this->htmlDir->getAbsolutePath(); define('HTML_REALDIR', rtrim(realpath($htmlDir), '/\\') . '/'); require_once HTML_REALDIR . '/define.php'; require_once HTML_REALDIR . HTML2DATA_DIR . '/require_base.php'; $query = SC_Query_Ex::getSingletonInstance(); $storage = new Zeclib_DefaultMigrationStorage($query, $this->system); $storage->versionTable = $this->versionTable; $storage->containerDirectories[] = $this->containerDir->getPath(); $migrator = new Zeclib_Migrator($storage, $query); $migrator->logger = new Zeclib_Phing_TaskMigrationLogger($this); $from = $this->from === '' ? null : $this->from; $to = $this->to === '' ? null : $this->to; $num = $migrator->up($from, $to); $this->log(sprintf('%d migrations are applied.', $num)); }
protected function doReset() { $dataDir = $this->dataDir->getAbsolutePath(); $htmlDir = $this->htmlDir->getAbsolutePath(); define('HTML_REALDIR', rtrim(realpath($htmlDir), '/\\') . '/'); require_once HTML_REALDIR . '/define.php'; require_once HTML_REALDIR . HTML2DATA_DIR . '/require_base.php'; $query = SC_Query_Ex::getSingletonInstance(); $storage = new Zeclib_DefaultMigrationStorage($query, $this->system); $storage->versionTable = $this->versionTable; $storage->containerDirectories[] = $this->containerDir->getPath(); $migrator = new Zeclib_Migrator($storage, $query); $migrator->logger = new Zeclib_Phing_TaskMigrationLogger($this); $ignoreMissing = strncmp(strtolower($this->ignoreMissing), 'y', 1) == 0; $num = $migrator->down(null, null, $ignoreMissing); $this->log(sprintf('%d migrations are reverted.', $num)); $migrator->clear(); $this->log(sprintf('All migrations are removed from storage.', $num)); $num = $migrator->up(null, null, $ignoreMissing); $this->log(sprintf('%d migrations are applied.', $num)); }
/** * @dataProvider provideUpPattern */ public function testUp($versions, $from, $to) { $this->storage->expects($this->once())->method('getPendingVersions')->will($this->returnValue($versions)); $returnValues = array(); foreach ($versions as $index => $version) { $migra = $this->getMockForAbstractClass('Zeclib_Migration', array($version, $this->query)); $migra->applied = false; $cond = $this->isIncludedVersion($version, $from, $to) ? $this->once() : $this->never(); $migra->expects($cond)->method('up'); $returnValues[] = array($version, $migra); } $this->storage->expects($this->any())->method('loadMigration')->will($this->returnValueMap($returnValues)); $migrator = new Zeclib_Migrator($this->storage, $this->query); $migrator->up($from, $to); foreach ($returnValues as $values) { list($version, $migra) = $values; $expected = $this->isIncludedVersion($version, $from, $to); $this->assertEquals($expected, $migra->applied, 'Migration version:' . $version); } }