ComplexDataNormalizerTest.php in Zircon Profile 8
File
core/modules/serialization/tests/src/Unit/Normalizer/ComplexDataNormalizerTest.php
View source
<?php
namespace Drupal\Tests\serialization\Unit\Normalizer;
use Drupal\Core\TypedData\ComplexDataInterface;
use Drupal\Core\TypedData\TraversableTypedDataInterface;
use Drupal\serialization\Normalizer\ComplexDataNormalizer;
use Drupal\Tests\UnitTestCase;
use Symfony\Component\Serializer\Serializer;
class ComplexDataNormalizerTest extends UnitTestCase {
const TEST_FORMAT = 'test_format';
protected $normalizer;
public function setUp() {
$this->normalizer = new ComplexDataNormalizer();
}
public function testSupportsNormalization() {
$this
->assertTrue($this->normalizer
->supportsNormalization(new TestComplexData()));
$this
->assertFalse($this->normalizer
->supportsNormalization(new \stdClass()));
}
public function testNormalize() {
$context = [
'test' => 'test',
];
$serializer_prophecy = $this
->prophesize(Serializer::class);
$serializer_prophecy
->normalize('A', static::TEST_FORMAT, $context)
->shouldBeCalled();
$serializer_prophecy
->normalize('B', static::TEST_FORMAT, $context)
->shouldBeCalled();
$this->normalizer
->setSerializer($serializer_prophecy
->reveal());
$complex_data = new TestComplexData([
'a' => 'A',
'b' => 'B',
]);
$this->normalizer
->normalize($complex_data, static::TEST_FORMAT, $context);
}
}
class TestComplexData implements \IteratorAggregate, ComplexDataInterface {
private $values;
public function __construct(array $values = []) {
$this->values = $values;
}
public function getIterator() {
return new \ArrayIterator($this->values);
}
public function applyDefaultValue($notify = TRUE) {
}
public static function createInstance($definition, $name = NULL, TraversableTypedDataInterface $parent = NULL) {
}
public function get($property_name) {
}
public function getConstraints() {
}
public function getDataDefinition() {
}
public function getName() {
}
public function getParent() {
}
public function getProperties($include_computed = FALSE) {
}
public function getPropertyPath() {
}
public function getRoot() {
}
public function getString() {
}
public function getValue() {
}
public function isEmpty() {
}
public function onChange($name) {
}
public function set($property_name, $value, $notify = TRUE) {
}
public function setContext($name = NULL, TraversableTypedDataInterface $parent = NULL) {
}
public function setValue($value, $notify = TRUE) {
}
public function toArray() {
}
public function validate() {
}
}