public function MockSerializer::deserialize in Config Entity Revisions 8
Same name and namespace in other branches
- 8.2 tests/src/Unit/ConfigEntityRevisionsRevertFormBaseTest.php \Drupal\Tests\config_entity_revisions\Unit\MockSerializer::deserialize()
- 1.x tests/src/Unit/ConfigEntityRevisionsRevertFormBaseTest.php \Drupal\Tests\config_entity_revisions\Unit\MockSerializer::deserialize()
Parameters
$data:
$type:
$format:
array $context:
Return value
string
Throws
\Exception
File
- tests/
src/ Unit/ ConfigEntityRevisionsRevertFormBaseTest.php, line 687
Class
- MockSerializer
- The serializer (sic) we'd normally mock above has deserialize as a final method. Instead of using it, define our own class here.
Namespace
Drupal\Tests\config_entity_revisions\UnitCode
public function deserialize($data, $type, $format, array $context = []) {
if ($data !== 'serialisedConfiguration') {
throw new \Exception("Mock Serializer class's deserialize method should be called with data = 'serialisedConfiguration'");
}
$this->wasCalled = TRUE;
$configEntity = $this->testClass
->prophesizeProxy(ConfigEntityRevisionsInterface::CLASS);
$configEntity
->enforceIsNew(Argument::type('bool'))
->shouldBeCalled()
->will(function ($args) {
if (!$args || $args[0]) {
throw new \Exception("enforceIsNew wasn't set to FALSE.");
}
});
$configEntity
->get(Argument::type('string'))
->shouldBeCalledTimes(1)
->willReturn('originalSettings');
$keyValuePairs =& $this->keyValuePairs;
$configEntity
->set(Argument::type('string'), Argument::any())
->will(function ($args) use (&$keyValuePairs) {
$keyValuePairs[$args[0]] = $args[1];
});
$configEntity
->save()
->shouldBeCalled();
return $configEntity
->reveal();
}