protected function doDown() { $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; $ignoreMissing = strncmp(strtolower($this->ignoreMissing), 'y', 1) == 0; $num = $migrator->down($from, $to, $ignoreMissing); $this->log(sprintf('%d migrations are reverted.', $num)); }
/** * @dataProvider provideDownPattern */ public function testDown($versions, $from, $to) { $this->storage->expects($this->once())->method('getAppliedVersions')->will($this->returnValue($versions)); $this->storage->expects($this->any())->method('isAppliedVersion')->willReturn(true); $returnValues = array(); foreach ($versions as $index => $version) { $migra = $this->getMockForAbstractClass('Zeclib_Migration', array($version, $this->query)); $migra->applied = true; $cond = $this->isIncludedVersion($version, $from, $to) ? $this->once() : $this->never(); $migra->expects($cond)->method('down'); $returnValues[] = array($version, $migra); } $this->storage->expects($this->any())->method('loadMigration')->will($this->returnValueMap($returnValues)); $migrator = new Zeclib_Migrator($this->storage, $this->query); $migrator->down($from, $to); foreach ($returnValues as $values) { list($version, $migra) = $values; $expected = !$this->isIncludedVersion($version, $from, $to); $this->assertEquals($expected, $migra->applied, 'Migration version:' . $version); } }