PHPackages                             robuust/craft-fixtures - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. robuust/craft-fixtures

Abandoned → [craftcms/cms](/?search=craftcms%2Fcms)ArchivedCraft-plugin[Utility &amp; Helpers](/categories/utility)

robuust/craft-fixtures
======================

Yii2 fixtures for Craft 3

1.1.2(5y ago)1330.6k2MITPHPPHP &gt;=7.0

Since Aug 16Pushed 5y agoCompare

[ Source](https://github.com/robuust/craft-fixtures)[ Packagist](https://packagist.org/packages/robuust/craft-fixtures)[ RSS](/packages/robuust-craft-fixtures/feed)WikiDiscussions master Synced yesterday

READMEChangelog (4)Dependencies (1)Versions (22)Used By (0)

Fixtures (for Craft 3)
======================

[](#fixtures-for-craft-3)

This plugin provides all the necessary means to run Craft Elements as [Yii2 fixtures](https://www.yiiframework.com/doc/guide/2.0/en/test-fixtures). If you're not familiar with [Yii2 fixtures](https://www.yiiframework.com/doc/guide/2.0/en/test-fixtures) it is advised to read [their manual first](https://www.yiiframework.com/doc/guide/2.0/en/test-fixtures).

Installation
------------

[](#installation)

This tool can be installed [using Composer](https://getcomposer.org/doc/00-intro.md). Run the following command from the root of your project:

```
composer require robuust/craft-fixtures

```

This will add `robuust/craft-fixtures` as a requirement to your project's `composer.json` file and install the source-code into the `vendor/robuust/craft-fixtures` directory.

Fixtures is now available as an installable plugin in Craft. You can install it in the cp or use `./craft install/plugin fixtures`

Usage
-----

[](#usage)

This plugin provides abstract fixtures that you will have to extend and implement.

### Creating fixtures

[](#creating-fixtures)

Create a folder called "fixtures" in your project root. In this folder we will put our fixture classes, fixture data and the (optional) fixture migrations.

In the [Yii2 docs](https://www.yiiframework.com/doc/guide/2.0/en/test-fixtures#defining-a-fixture) you can read about fixture classes and fixture data.

This plugin provides a base for fixtures for Craft elements. The main logic is defined in `robuust\fixtures\base\ElementFixture`. Our fixture classes can contain the following methods (next to all the features [`yii\test\ActiveFixture`](https://www.yiiframework.com/doc/api/2.0/yii-test-activefixture) has to offer:

`ElementFixture::isPrimaryKey(string $key): bool` to define which model attributes can be used to identify a unique Element

`ElementFixture::getElement(array $data): Element?` to get an element which is identified by the given data. The defined primary keys are used to identify the given data.

#### All fixtures

[](#all-fixtures)

ElementFixture will define `$this->siteIds` with all site handles as keys.

#### Asset

[](#asset)

Extend `robuust\fixtures\base\AssetFixture` to add assets. Its datafile could look like this:

```
