Download the PHP package chrispenny/silverstripe-data-object-to-fixture without Composer

On this page you can find all versions of the php package chrispenny/silverstripe-data-object-to-fixture. 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 silverstripe-data-object-to-fixture

Silverstripe DataObject To Fixture

Generate a YAML fixture from DataObjects

Installation

Purpose (early stage)

The purpose of this module (at this early stage) is not to guarantee perfect fixtures every time, but more to provide a solid guideline for what your fixture should look like.

For example: Writing unit test fixtures can be difficult, especially when you're needing to visualise the structure and relationships of many different DataObjects (and then add an extra layer if you're using, say, Fluent).

I would also like this module to work well with the Populate module. Please note though that you'll need to be running version 2.1 or greater, as versions before that did not support circular relationships.

Purpose (future development)

My dream for this module is that I would like to get to a stage where we can confidently say that generated fixtures will be perfect every time.

From there, I could see this being used (as an example) for testers to be able to export pages through the CMS on their test environments, so that those pages can then be restored at any time via (maybe) Populate. How this would work exactly, and whether or not it would use Populate, is still to be determined.

Warnings

This is still in early development stages. Please be aware that:

What won't change:

I would not recommend that you use this module (at this stage) for any application critical features, but I would recommend that you use it as a developer tool (EG: to help you write your own fixtures, either for tests, or to be used with Populate).

General usage

Dev task

A dev task can be found at /dev/tasks/generate-fixture-from-dataobject.

This task will allow you to generate a fixture (output on the screen for you to copy/paste) for any DataObject that you have defined in your project.

Code use

Excluding classes from export

There might be some classes (like Members?) that you don't want to include in your fixture. The manifest will check classes for the existence (and truth) of the config variable exclude_from_fixture_relationships.

You can set this in a yml file:

The above examples have been set in _config/model.yml. If you wish to override them, you can also do so by adding your own yml config "After" dataobjecttofixturemodel. EG:

Excluding relationships from export

Similar to excluding classes, there might be some specific relationships on specific classes that you want to exclude. Perhaps you have identified a looping relationship, and you would like to exclude one of them to make things predictable, or perhaps it's just a relationship you don't need in your fixtures.

You can exclude specific relationships by adding excluded_fixture_relationships to the desired class.

excluded_fixture_relationships accepts an array of relationship names.

EG:

Common issues

Parent Pages included in your export

When you're exporting Pages, if that Page has a Parent, then that Parent is considered a valid relationship, and so it will get exported along with the Page you've selected.

I'm still considering what to do about this, but for now, I would probably recommend that you add Parent to the list of excluded relationships for SiteTree:

Node [YourClass] has [x] left over dependencies, and so could not be sorted

This generally happens when you have a looping relationship. EG: Page has_one Link, and Link has_one back to Page. The sorter cannot determine which class should be prioritised above the other.

This doesn't necessarily mean that things will break, but it's worth reviewing. You might find that you can exclude one of the relationships in order to make thing more consistent.

A good example of this is in Elemental. Elemental provides an extension called TopPage which provides a relationship directly from each BaseElement to the Page that it belongs to (it's like a "index" so that you can loop up your Page from the BaseElement with less DB queries). This is handy for developers, but less handy for YAML fixtures. We'd actually prefer to exclude this relationship and follow the correct relationship flow from Page to ElementalArea to BaseElement.

I could exclude this relationship by adding the following configuration:

Request timeout when generating fixtures

Above are two options that you can use to attempt to reduce this.

I would recommend that you begin by exluding classes that you don't need for your export, then move to excluding specific relationships that might be causing deep levels of nested relationships.

DataObject::get() cannot query non-subclass DataObject directly

You might see this error if you have polymorphic relationships (relationships being defined as simply DataObject::class), EG:

This module needs to know what DataObject it is querying for. Modules like Userforms do this because you can technically have any Model as the parent. These modules do, however, store the class name for this relationship in a separate field so that we are able to query for the parent appropriately. For Userforms, the class name for this relationship is stored in a field called ParentClass. This module doesn't know that though.

You can tell this module where that class name information lives for any relationship by using the following configuration (this is using Userforms as the example):

field_classname_map is the config we want to populate, and it expects an array with the relationship field name as the key, and the corresponding class name field as the value.

The module uses relField() with the value, so you could be presenting this information through a data field, or a method.

Supported relationships

Fluent support

It is my intention to support Fluent and exporting Localised fields in the future, but at this time, there is no support provided.

Future features

Things that this module does not currently do


All versions of silverstripe-data-object-to-fixture with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1
silverstripe/framework Version ^5
silverstripe/cms Version ^5
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 chrispenny/silverstripe-data-object-to-fixture contains the following files

Loading the files please wait ....