Skip to content
PHP Ecosystem
Explore

FileFixtureTrait

API reference › yii › test › FileFixtureTrait

traityii\test\FileFixtureTrait
Since2.0.14
Sourceframework/test/FileFixtureTrait.php
Used by 2 types

FileFixtureTrait provides functionalities for loading data fixture from file.

PropertyTypeDescriptionDefined by
$dataDirectorystringThe directory path or path alias that contains the fixture data Default: null.FileFixtureTrait
$dataFilestring|bool|nullThe file path or path alias of the data file that contains the fixture data to be returned by getData(). Default: null.FileFixtureTrait
MethodDescriptionDefined by
loadData() protectedReturns the fixture data.FileFixtureTrait
public string|bool|null $dataFile = null

The file path or path alias of the data file that contains the fixture data to be returned by getData().

You can set this property to be false to prevent loading any data.

protected function loadData(string $file, bool $throwException = true): array

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 the data array that will be stored in data after inserting into the database.

Parameters

ParameterTypeDescription
$filestringThe data file path
$throwExceptionboolWhether to throw exception if fixture data file does not exist.

Returns

array: The data to be put into the database

Throws