Class yii\elasticsearch\ActiveFixture

Inheritanceyii\elasticsearch\ActiveFixture » yii\test\BaseActiveFixture
Available since version2.0.2

ActiveFixture represents a fixture for testing backed up by an \yii\elasticsearch\modelClass or an elastic search index.

Either \yii\elasticsearch\modelClass or $index and $type must be set. You should also provide fixture data in the file specified by $dataFile or overriding getData() if you want to use code to generate the fixture data.

When the fixture is being loaded, it will first call resetIndex() to remove any existing data in the index for the $type. It will then populate the index with the data returned by getData().

After the fixture is loaded, you can access the loaded data via the \yii\elasticsearch\data property. If you set \yii\elasticsearch\modelClass, you will also be able to retrieve an instance of \yii\elasticsearch\modelClass with the populated data via \yii\elasticsearch\getModel().

Public Properties

Hide inherited properties

PropertyTypeDescriptionDefined By
$dataFile string|boolean The file path or path alias of the data file that contains the fixture data to be returned by getData(). yii\elasticsearch\ActiveFixture
$db yii\elasticsearch\Connection|string The DB connection object or the application component ID of the DB connection. yii\elasticsearch\ActiveFixture
$index string The name of the index that this fixture is about. yii\elasticsearch\ActiveFixture
$type string The name of the type that this fixture is about. yii\elasticsearch\ActiveFixture

Public Methods

Hide inherited methods

MethodDescriptionDefined By
init() yii\elasticsearch\ActiveFixture
load() Loads the fixture. yii\elasticsearch\ActiveFixture

Protected Methods

Hide inherited methods

MethodDescriptionDefined By
getData() Returns the fixture data. yii\elasticsearch\ActiveFixture
resetIndex() Removes all existing data from the specified index and type. yii\elasticsearch\ActiveFixture

Property Details

$dataFile public property

The file path or path alias of the data file that contains the fixture data to be returned by getData(). If this is not set, it will default to FixturePath/data/Index/Type.php, where FixturePath stands for the directory containing this fixture class, Index stands for the elasticsearch $index name and Type stands for the $type associated with this fixture. You can set this property to be false to prevent loading any data.

public string|boolean $dataFile null
$db public property

The DB connection object or the application component ID of the DB connection. After the DbFixture object is created, if you want to change this property, you should only assign it with a DB connection object.

public yii\elasticsearch\Connection|string $db 'elasticsearch'
$index public property

The name of the index that this fixture is about. If this property is not set, the name will be determined via \yii\elasticsearch\modelClass.

See also \yii\elasticsearch\modelClass.

public string $index null
$type public property

The name of the type that this fixture is about. If this property is not set, the name will be determined via \yii\elasticsearch\modelClass.

See also \yii\elasticsearch\modelClass.

public string $type null

Method Details

getData() protected method

Returns the fixture data.

The default implementation will try to return the fixture data by including the external file specified by $dataFile. The file should return an array of data rows (column name => column value), each corresponding to a row in the index.

If the data file does not exist, an empty array will be returned.

protected array getData ( )
return array

The data rows to be inserted into the database index.

init() public method

public void init ( )
load() public method

Loads the fixture.

The default implementation will first clean up the index by calling resetIndex(). It will then populate the index with the data returned by getData().

If you override this method, you should consider calling the parent implementation so that the data returned by getData() can be populated into the index.

public void load ( )
resetIndex() protected method

Removes all existing data from the specified index and type.

This method is called before populating fixture data into the index associated with this fixture.

protected void resetIndex ( )