EntityStubFactory
in package
A factory for creating stubs of entities.
Table of Contents
Methods
- create() : EntityStubInterface|EntityInterface|MockObject
- Creates an entity stub with field values.
- __construct() : mixed
- Disables the constructor to use only static methods.
- getFieldPlainValue() : mixed
- Gets the plain value of the field.
Methods
create()
Creates an entity stub with field values.
public
static create(string $entityTypeNameOrClass[, array<string|int, mixed> $values = NULL ][, array<string|int, mixed> $translations = NULL ][, array<string|int, mixed> $options = NULL ][, array<string|int, mixed> $storageOptions = NULL ]) : EntityStubInterface|EntityInterface|MockObject
Parameters
- $entityTypeNameOrClass : string
-
A full path to an entity type class, or an entity type id for Drupal Core entities like
node
,taxonomy_term
, etc. - $values : array<string|int, mixed> = NULL
-
A list of values to set in the created entity.
- $translations : array<string|int, mixed> = NULL
-
A list of translations to add to the created entity.
- $options : array<string|int, mixed> = NULL
-
A list of options to entity stub creation:
- mockMethods: list of methods to make mockable.
- addMethods: list of additional methods.
- skipEntityConstructor: a flag to skip calling the entity constructor.
- fields: a list of custom field options by field name.
Applies only on the first initialization of this field.
Supportable formats:
- A string, indicating field type, like 'integer', 'string', 'entity_reference', only core field types are supported.
- An array with field configuration: type, settings, etc, like this: [ 'type' => 'entity_reference', 'settings' => ['target_type' => 'node'] 'translatable' => TRUE, 'required' => FALSE, 'cardinality' => 3, ].
- A field definition object, that will be applied to the field.
- $storageOptions : array<string|int, mixed> = NULL
-
A list of options to pass to the storage initialization. Acts only once if the storage is not initialized yet.
- 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.
- constructorArguments: additional arguments to the constructor.
Return values
EntityStubInterface|EntityInterface|MockObject —The stub object for the entity.
__construct()
Disables the constructor to use only static methods.
private
__construct() : mixed
getFieldPlainValue()
Gets the plain value of the field.
private
static getFieldPlainValue(mixed $value) : mixed
Looking though array of deltas, array of values.
Parameters
- $value : mixed
-
The complex field value.
Return values
mixed —The plain field value.