function EntityFieldValueTraitTest::testGetFieldValueWithNonExistentField

Same name and namespace in other branches
  1. main core/tests/Drupal/KernelTests/Core/Entity/EntityFieldValueTraitTest.php \Drupal\KernelTests\Core\Entity\EntityFieldValueTraitTest::testGetFieldValueWithNonExistentField()

Tests getFieldValue() with non-existent field.

File

core/tests/Drupal/KernelTests/Core/Entity/EntityFieldValueTraitTest.php, line 157

Class

EntityFieldValueTraitTest
Tests the EntityFieldValueTrait.

Namespace

Drupal\KernelTests\Core\Entity

Code

public function testGetFieldValueWithNonExistentField() : void {
  $account = User::create([
    'name' => 'user1',
  ]);
  $account->save();
  $account = User::load($account->id());
  assert($account instanceof User);
  $this->expectException(\InvalidArgumentException::class);
  $this->expectExceptionMessage('Field nonexistent_field is unknown.');
  $this->getFieldValue($account, 'nonexistent_field', 'value');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.