Download the PHP package robuust/craft-fixtures without Composer

On this page you can find all versions of the php package robuust/craft-fixtures. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package craft-fixtures

Fixtures (for Craft 3)

This plugin provides all the necessary means to run Craft Elements as Yii2 fixtures. If you're not familiar with Yii2 fixtures it is advised to read their manual first.

Installation

This tool can be installed using Composer. Run the following command from the root of your project:

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

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

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

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

Asset

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

This will upload and link product.jpg as an asset.

AssetFixture will define $this->volumeIds and $this->folderIds with their handles as key.

Its primary keys are: volumeId, folderId, filename and title.

Category

Extend robuust\fixtures\base\CategoryFixture to add categories. Its datafile could look like this:

CategoryFixture will define $this->groupIds with all category group handles as key.

Its primary keys are: siteId, groupId and title.

Entry

Extend robuust\fixtures\base\EntryFixture to add entries. Its datafile could look like this:

EntryFixture will define $this->sectionIds with all section handles as key. It will also define $this->typeIds with all section handles as the first key and the entry type handles as the second key.

Its primary keys are: siteId, sectionId, typeId and title.

GlobalSet

Extend robuust\fixtures\base\GlobalSetFixture to update (!) globals (they must already exist). Its datafile could look like this:

Its primary keys are: siteId and handle, the handle being the one of the (already existing) global set.

Tag

Extend robuust\fixtures\base\TagFixture to add tags. Its datafile could look like this:

TagFixture will define $this->groupIds with all tag group handles as key.

Its primary keys are: siteId, groupId and title.

User

Extend robuust\fixtures\base\UserFixture to add users. Its datafile could look like this:

Its primary keys are: siteId, username and email.

Product

Extend robuust\fixtures\base\Product to add products. Its datafile could look like this:

ProductFixture will define $this->productTypeIds with all product type handles as key.

Its primary keys are: siteId, typeId and title.

Running fixtures

Once you install the Plugin in Craft, you can run some command line actions. When you run ./craft in the command line, you will now see these actions:

The fixtures/fixture actions are extended from Yii2 and will take the same arguments. Run all your fixtures with ./craft fixtures/fixture/load "*"

Running fixture migrations

Next to the fixtures/fixture actions in the command line, you will also find:

The fixtures/migrate actions are extended from Craft and will take the same arguments. Run all your migrations with ./craft fixtures/migrate/up

Using fixtures in tests

To use these fixtures in Codeception tests with Craft 3 you can use the robuust\fixtures\test\Craft module in stead of using Codeception's Yii2 module.

You can load fixtures in tests the way the Yii2 docs describe it.

Example

This is an example of a fixture for a fictional "Contact Page"

fixtures/ContactPageEntryFixture.php

fixtures/data/contact-page-entry.php

License

This project has been licensed under the MIT License (MIT). Please see License File for more information.

Changelog

CHANGELOG.md


All versions of craft-fixtures with dependencies

PHP Build Version
Package Version
Requires php Version >=7.0
craftcms/cms Version ^3.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package robuust/craft-fixtures contains the following files

Loading the files please wait ....