Since: 1.3
Author: Bernhard Schussek (bschussek@gmail.com)
Exemplo n.º 1
0
 /**
  * @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);
 }
Exemplo n.º 2
0
 /**
  * {@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);
 }
Exemplo n.º 3
0
 /**
  * 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();
     }
 }
Exemplo n.º 4
0
 /**
  * @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());
 }
Exemplo n.º 5
0
 /**
  * {@inheritdoc}
  */
 public function fromJson($jsonData, array $options = array())
 {
     $this->validate($jsonData);
     return $this->innerConverter->fromJson($jsonData, $options);
 }