class MockSerializer 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
- 1.x tests/src/Unit/ConfigEntityRevisionsRevertFormBaseTest.php \Drupal\Tests\config_entity_revisions\Unit\MockSerializer
The serializer (sic) we'd normally mock above has deserialize as a final method. Instead of using it, define our own class here.
Hierarchy
- class \Drupal\Tests\config_entity_revisions\Unit\MockSerializer
Expanded class hierarchy of MockSerializer
File
- tests/
src/ Unit/ ConfigEntityRevisionsRevertFormBaseTest.php, line 650
Namespace
Drupal\Tests\config_entity_revisions\UnitView source
class MockSerializer {
/**
* @var ConfigEntityRevisionsRevertFormBaseTest
*/
public $testClass = NULL;
/**
* @var bool
*/
public $wasCalled = FALSE;
/**
* @var array
*/
public $keyValuePairs = [];
/**
* Constructor. Store a copy of the test class so we can use its prophecy.
*
* @param ConfigEntityRevisionsRevertFormBaseTest $testClass
* The test class instance.
*/
public function __construct(ConfigEntityRevisionsRevertFormBaseTest $testClass) {
$this->testClass = $testClass;
}
/**
* @param $data
* @param $type
* @param $format
* @param array $context
*
* @return string
* @throws \Exception
*/
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();
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
MockSerializer:: |
public | property | ||
MockSerializer:: |
public | property | ||
MockSerializer:: |
public | property | ||
MockSerializer:: |
public | function | ||
MockSerializer:: |
public | function | Constructor. Store a copy of the test class so we can use its prophecy. |