# FileFixtureTrait

> FileFixtureTrait provides functionalities for loading data fixture from file.

[API reference](/docs/api/index.md) › [yii](/docs/api/yii/index.md) › [test](/docs/api/yii/test/index.md) › FileFixtureTrait

| trait | `yii\test\FileFixtureTrait` |
| --- | --- |
| Since | 2.0.14 |
| Source | [`framework/test/FileFixtureTrait.php`](https://github.com/yiisoft/yii2/blob/22.0/framework/test/FileFixtureTrait.php#L20) |

Used by 2 types:

- [`ArrayFixture`](/docs/api/yii/test/arrayfixture/index.md)
- [`BaseActiveFixture`](/docs/api/yii/test/baseactivefixture/index.md)

FileFixtureTrait provides functionalities for loading data fixture from file.

## Properties

| Property | Type | Description | Defined by |
| --- | --- | --- | --- |
| <span id="property-dataDirectory"></span>`$dataDirectory` | `string` | The directory path or [path alias](/docs/guide/concept-aliases/index.md) that contains the fixture data Default: `null`. | `FileFixtureTrait` |
| [`$dataFile`](#property-dataFile) | `string\|bool\|null` | The file path or [path alias](/docs/guide/concept-aliases/index.md) of the data file that contains the fixture data to be returned by `getData()`. Default: `null`. | `FileFixtureTrait` |

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| [`loadData()`](#method-loadData) protected | Returns the fixture data. | `FileFixtureTrait` |

## Property details

### $dataFile <span id="property-dataFile"></span>

```php
public string|bool|null $dataFile = null
```

The file path or [path alias](/docs/guide/concept-aliases/index.md) 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

### loadData() <span id="method-loadData"></span>

```php
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`](/docs/api/yii/test/filefixturetrait/index.md#property-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`](/docs/api/yii/base/invalidconfigexception/index.md): if the specified data file does not exist.