function TestObjectItemTest::testTestObjectItem
Tests the serialization of a field type that has an object.
File
- 
              core/modules/ field/ tests/ src/ Kernel/ TestObjectItemTest.php, line 45 
Class
- TestObjectItemTest
- Tests the serialization of an object.
Namespace
Drupal\Tests\field\KernelCode
public function testTestObjectItem() {
  $object = new \stdClass();
  $object->foo = 'bar';
  $entity = EntityTest::create();
  $entity->field_test->value = $object;
  $entity->save();
  // Verify that the entity has been created properly.
  $id = $entity->id();
  $entity = EntityTest::load($id);
  $this->assertInstanceOf(\stdClass::class, $entity->field_test->value);
  $this->assertEquals($object, $entity->field_test->value);
}Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.
