EntityStorageStubFactory
in package
A stub of the Drupal's default SqlContentEntityStorage class.
Table of Contents
Properties
- $entityDataStorage : array<string|int, mixed>
- A static storge for entity data per entity type.
Methods
- create() : EntityStorageInterface|MockObject
- Creates a new Entity Storage Stub object.
- entityToValues() : array<string|int, mixed>
- Converts entity to an array with values.
- processAutoincrementId() : int|string
- Processes the autoincrement id to generate next values correctly.
- valuesToEntity() : EntityTypeInterface
- Creates an entity from values array.
- __construct() : mixed
- Disables the constructor to use only static methods.
Properties
$entityDataStorage
A static storge for entity data per entity type.
private
static array<string|int, mixed>
$entityDataStorage
= []
Methods
create()
Creates a new Entity Storage Stub object.
public
static create(string $entityClassOrName[, string $annotation = NULL ][, array<string|int, mixed>|null $storageOptions = NULL ]) : EntityStorageInterface|MockObject
Parameters
- $entityClassOrName : string
-
The original class to use for stub, or an entity type for types in.
- $annotation : string = NULL
-
The annotation to use. If missing - tries ContentEntityType and ConfigEntityType. Examples:
- \Drupal\Core\Entity\Annotation\ContentEntityType
- \Drupal\Core\Entity\Annotation\ConfigEntityType or other annotations.
- $storageOptions : array<string|int, mixed>|null = NULL
-
The array of options:
- constructorArguments: additional arguments to the constructor.
- mockMethods: list of methods to make mockable.
- addMethods: list of additional methods.
- skipPrePostSave: a flag to use direct save on the storage without calling preSave and postSave functions. Can be useful if that functions have dependencies which hard to mock.
- skipModuleFile: skips including of ".module" file.
Tags
Return values
EntityStorageInterface|MockObject —The mocked Entity Storage Stub.
entityToValues()
Converts entity to an array with values.
public
static entityToValues(mixed $entity) : array<string|int, mixed>
Parameters
- $entity : mixed
-
The entity to use.
Return values
array<string|int, mixed> —The array with values.
processAutoincrementId()
Processes the autoincrement id to generate next values correctly.
public
static processAutoincrementId(mixed &$storage[, int|string $currentId = NULL ]) : int|string
Parameters
- $storage : mixed
-
A static storage to use.
- $currentId : int|string = NULL
-
The current id to use, or NULL to get the next autoincremented value.
Return values
int|string —The passed value or autoincremented, if passed is NULL.
valuesToEntity()
Creates an entity from values array.
public
static valuesToEntity(EntityTypeInterface $entityType[, array<string|int, mixed> $values = [] ]) : EntityTypeInterface
Parameters
- $entityType : EntityTypeInterface
-
The entity type to use.
- $values : array<string|int, mixed> = []
-
The values to use.
Return values
EntityTypeInterface —The created entity
__construct()
Disables the constructor to use only static methods.
private
__construct() : mixed