FileFixtureTrait
API reference › yii › test › FileFixtureTrait
Used by 2 types
FileFixtureTrait provides functionalities for loading data fixture from file.
Properties
Section titled “Properties”| Property | Type | Description | Defined by |
|---|---|---|---|
$dataDirectory | string | The directory path or path alias that contains the fixture data Default: null. | FileFixtureTrait |
$dataFile | string| | The file path or path alias of the data file that contains the fixture data to be returned by getData(). Default: null. | FileFixtureTrait |
Methods
Section titled “Methods”| Method | Description | Defined by |
|---|---|---|
loadData() protected | Returns the fixture data. | FileFixtureTrait |
Property details
Section titled “Property details”$dataFile
Section titled “$dataFile ”public string|bool|null $dataFile = nullThe 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.
Method details
Section titled “Method details”loadData()
Section titled “loadData() ”protected function loadData(string $file, bool $throwException = true): arrayReturns 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
| Parameter | Type | Description |
|---|---|---|
$file | string | The data file path |
$throwException | bool | Whether to throw exception if fixture data file does not exist. |
Returns
array: The data to be put into the database
Throws
yii\base\InvalidConfigException: if the specified data file does not exist.