Class yii\mongodb\ActiveFixture

Inheritanceyii\mongodb\ActiveFixture » yii\test\BaseActiveFixture
Available since version2.0

ActiveFixture represents a fixture backed up by a modelClass or a MongoDB collection.

Either modelClass or $collectionName 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 resetCollection() to remove any existing data in the collection. It will then populate the collection with the data returned by getData().

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

Public Properties

Hide inherited properties

PropertyTypeDescriptionDefined By
$collectionName string|array The collection name that this fixture is about. yii\mongodb\ActiveFixture
$db yii\mongodb\Connection|string The DB connection object or the application component ID of the DB connection. yii\mongodb\ActiveFixture

Public Methods

Hide inherited methods

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

Protected Methods

Hide inherited methods

MethodDescriptionDefined By
getCollection() Returns collection used by this fixture. yii\mongodb\ActiveFixture
getCollectionName() Returns collection name used by this fixture. yii\mongodb\ActiveFixture
getData() Returns the fixture data. yii\mongodb\ActiveFixture
resetCollection() Removes all existing data from the specified collection and resets sequence number if any. yii\mongodb\ActiveFixture

Property Details

$collectionName public property

The collection name that this fixture is about. If this property is not set, the collection name will be determined via modelClass.

See also yii\mongodb\Connection::getCollection().

$db public property

The DB connection object or the application component ID of the DB connection.

public yii\mongodb\Connection|string $db 'mongodb'

Method Details

getCollection() protected method

Returns collection used by this fixture.

protected yii\mongodb\Collection getCollection ( )
return yii\mongodb\Collection

Related collection.

getCollectionName() protected method

Returns collection name used by this fixture.

protected array|string getCollectionName ( )
return array|string

Related collection name

getData() protected method

Returns the fixture data.

This method is called by loadData() to get the needed 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 collection.

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 collection.

init() public method

public void init ( )
load() public method

Loads the fixture data.

The default implementation will first reset the MongoDB collection and then populate it with the data returned by getData().

public void load ( )
resetCollection() protected method

Removes all existing data from the specified collection and resets sequence number if any.

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

protected void resetCollection ( )