You are here

public function DenormalizeTest::testDenormalizeEmptyCustomSerializedField in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/hal/tests/src/Kernel/DenormalizeTest.php \Drupal\Tests\hal\Kernel\DenormalizeTest::testDenormalizeEmptyCustomSerializedField()

Tests normalizing/denormalizing empty custom serialized fields.

File

core/modules/hal/tests/src/Kernel/DenormalizeTest.php, line 171

Class

DenormalizeTest
Tests HAL denormalization edge cases for EntityResource.

Namespace

Drupal\Tests\hal\Kernel

Code

public function testDenormalizeEmptyCustomSerializedField() {
  $entity = EntitySerializedField::create([
    'serialized_long' => serialize([]),
  ]);
  $normalized = $this->serializer
    ->normalize($entity);
  $this
    ->assertEquals([], $normalized['serialized_long'][0]['value']);
  $entity = $this->serializer
    ->denormalize($normalized, EntitySerializedField::class);
  $this
    ->assertEquals(serialize([]), $entity
    ->get('serialized_long')->value);
}