Issue #3035980 by jhedstrom: Provide a better error when a NULL is passed to EntityStorageBase::load()

merge-requests/1119/head
Lee Rowlands 2019-05-27 17:11:07 +10:00
parent 2adeb979e2
commit 4dfdaaed2e
No known key found for this signature in database
GPG Key ID: 2B829A3DF9204DC4
2 changed files with 4 additions and 0 deletions

View File

@ -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;
}

View File

@ -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);
}
/**