/** * @expectedException \Webmozart\Json\Conversion\ConversionFailedException */ public function testConvertValidationErrorsToConversionException() { $options = array('option' => 'value'); $jsonData = (object) array('foo' => 'bar'); $this->innerConverter->expects($this->once())->method('toJson')->with('DATA', $options)->willReturn($jsonData); $this->jsonValidator->expects($this->once())->method('validate')->willReturn(array('First error', 'Second error')); $this->converter->toJson('DATA', $options); }
/** * {@inheritdoc} */ public function fromJson($jsonData, array $options = array()) { $this->assertObject($jsonData); $this->assertVersionIsset($jsonData); $this->assertVersionSupported($jsonData->version); if ($jsonData->version !== $this->currentVersion) { $this->migrationManager->migrate($jsonData, $this->currentVersion); } return $this->innerConverter->fromJson($jsonData, $options); }
/** * Saves a configuration file. * * The configuration file is saved to the same path that it was read from. * * @param ConfigFile $configFile The configuration file to save. * * @throws WriteException If the file cannot be written. * @throws InvalidConfigException If the file contains invalid configuration. */ public function saveConfigFile(ConfigFile $configFile) { try { $jsonData = $this->configFileConverter->toJson($configFile); } catch (ConversionFailedException $e) { throw new InvalidConfigException(sprintf('The data written to %s could not be converted: %s', $configFile->getPath(), $e->getMessage()), 0, $e); } $json = $this->encode($jsonData, $configFile->getPath()); $this->storage->write($configFile->getPath(), $json); if ($this->factoryManager) { $this->factoryManager->autoGenerateFactoryClass(); } }
/** * @expectedException \Webmozart\Json\Conversion\ConversionFailedException */ public function testFromJsonFailsIfVersionIsMissing() { $this->migrationManager->expects($this->never())->method('migrate'); $this->innerConverter->expects($this->never())->method('fromJson'); $this->converter->fromJson((object) array()); }
/** * {@inheritdoc} */ public function fromJson($jsonData, array $options = array()) { $this->validate($jsonData); return $this->innerConverter->fromJson($jsonData, $options); }