/** * {@inheritdoc} */ public function fromJson($jsonData, array $options = array()) { Assert::isInstanceOf($jsonData, 'stdClass'); $moduleFile = new ModuleFile(null, isset($options['path']) ? $options['path'] : null); $moduleFile->setVersion($this->versioner->parseVersion($jsonData)); $this->addJsonToModuleFile($jsonData, $moduleFile); return $moduleFile; }
public function testMigrateDoesNothingIfAlreadyCorrectVersion() { $data = (object) array(); $this->versioner->expects($this->once())->method('parseVersion')->with($data)->willReturn('0.10'); $this->versioner->expects($this->never())->method('updateVersion'); $this->migration1->expects($this->never())->method('up'); $this->migration2->expects($this->never())->method('up'); $this->migration3->expects($this->never())->method('up'); $this->migration1->expects($this->never())->method('down'); $this->migration2->expects($this->never())->method('down'); $this->migration3->expects($this->never())->method('down'); $this->manager->migrate($data, '0.10'); }
private function down($data, $sourceVersion, $targetVersion) { while (version_compare($sourceVersion, $targetVersion, '>')) { if (!isset($this->migrationsByTargetVersion[$sourceVersion])) { throw new MigrationFailedException(sprintf('No migration found to downgrade from version %s to %s.', $sourceVersion, $targetVersion)); } $migration = $this->migrationsByTargetVersion[$sourceVersion]; // Final version too low if (version_compare($migration->getSourceVersion(), $targetVersion, '<')) { throw new MigrationFailedException(sprintf('No migration found to downgrade from version %s to %s.', $sourceVersion, $targetVersion)); } $migration->down($data); $this->versioner->updateVersion($data, $migration->getSourceVersion()); $sourceVersion = $migration->getSourceVersion(); } }