public function DenormalizeTest::testDenormalizeInvalidCustomSerializedField in Drupal 9
Same name and namespace in other branches
- 8 core/modules/hal/tests/src/Kernel/DenormalizeTest.php \Drupal\Tests\hal\Kernel\DenormalizeTest::testDenormalizeInvalidCustomSerializedField()
Tests normalizing/denormalizing invalid custom serialized fields.
File
- core/
modules/ hal/ tests/ src/ Kernel/ DenormalizeTest.php, line 157
Class
- DenormalizeTest
- Tests HAL denormalization edge cases for EntityResource.
Namespace
Drupal\Tests\hal\KernelCode
public function testDenormalizeInvalidCustomSerializedField() {
$entity = EntitySerializedField::create([
'serialized_long' => serialize([
'Hello world!',
]),
]);
$normalized = $this->serializer
->normalize($entity);
$this
->assertEquals([
'Hello world!',
], $normalized['serialized_long'][0]['value']);
$normalized['serialized_long'][0]['value'] = 'boo';
$this
->expectException(\LogicException::class);
$this
->expectExceptionMessage('The generic FieldItemNormalizer cannot denormalize string values for "value" properties of the "serialized_long" field (field item class: Drupal\\Core\\Field\\Plugin\\Field\\FieldType\\StringLongItem).');
$this->serializer
->denormalize($normalized, EntitySerializedField::class);
}