From 4dfdaaed2e7499698192e34a92d4977e1fc0a20f Mon Sep 17 00:00:00 2001 From: Lee Rowlands Date: Mon, 27 May 2019 17:11:07 +1000 Subject: [PATCH] Issue #3035980 by jhedstrom: Provide a better error when a NULL is passed to EntityStorageBase::load() --- core/lib/Drupal/Core/Entity/EntityStorageBase.php | 1 + .../Tests/Core/Config/Entity/ConfigEntityStorageTest.php | 3 +++ 2 files changed, 4 insertions(+) diff --git a/core/lib/Drupal/Core/Entity/EntityStorageBase.php b/core/lib/Drupal/Core/Entity/EntityStorageBase.php index 1a27a7738ac..6c26658781e 100644 --- a/core/lib/Drupal/Core/Entity/EntityStorageBase.php +++ b/core/lib/Drupal/Core/Entity/EntityStorageBase.php @@ -246,6 +246,7 @@ abstract class EntityStorageBase extends EntityHandlerBase implements EntityStor * {@inheritdoc} */ public function load($id) { + assert(!is_null($id), 'Cannot load a NULL ID.'); $entities = $this->loadMultiple([$id]); return isset($entities[$id]) ? $entities[$id] : NULL; } diff --git a/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityStorageTest.php b/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityStorageTest.php index 41a63ac4c55..be0ae4d1fef 100644 --- a/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityStorageTest.php +++ b/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityStorageTest.php @@ -559,6 +559,9 @@ class ConfigEntityStorageTest extends UnitTestCase { $entity = $this->entityStorage->load('foo'); $this->assertInstanceOf(EntityInterface::class, $entity); $this->assertSame('foo', $entity->id()); + + $this->setExpectedException(\AssertionError::class, 'Cannot load a NULL ID.'); + $this->entityStorage->load(NULL); } /**