Download the PHP package adrhumphreys/silverstripe-fixtures without Composer

On this page you can find all versions of the php package adrhumphreys/silverstripe-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 silverstripe-fixtures

Fixtures for Silverstripe

Fixtures for all mixtures 👋

Requirements

Dev requirements

Installation

Installing as a dev only module:

When running dev/build Silverstripe framework will try to load all classes into it's ClassManifest to cache them and allow for functionality such as dependency injection. During that process it will try to load your Fixture class which will then try to load AdrHumphreys\Fixtures\AbstractFixture which doesn't exist. This will throw and exception and stop the dev/build process.

You have some options to remedy this, ranked from best to worst:

Option 1: Place your fixtures in the tests directory for your project: These are designed to be run on a test/dev environment only and the code is more reference than implementation specific. It therefore makes sense to move these files into this directory. Why? It's explicitly ignored when finding files via ManifestFileFinder

Option 2: Add _manifest_exclude to the fixture directory: This will ensure that ManifestFileFinder will ignore files in the directory. This is option 2 because it makes it easier for code that is test only to end up being relied upon by production code which should never be the case

Option 3: Add implements TestOnly to all fixtures If you are installing this as a dev dependency then all your fixtures will need to implement \SilverStripe\Dev\TestOnly this is specifically excluded from Silverstripes class manifest loader

How to use

The default setup is to run this as a task like so:

You'll need to create your fixtures in the directory specified. Or you can implement your own task, look at the task LoadFixtures as an example. You can change ->loadFromDirectory to multiple calls of ->loadFixture($fixtureClassName)

A basic fixture looks like the following:

load is called when creating the fixture and then getClassesToClear is called when purging the fixture. You can also implement unload which is function in which you can choose what to do and getTablesToClear which is a function similar to getClassesToClear but just tables.

Load order is first dependencies with no order requirement and no dependencies. Then ordered fixtures followed lastly by fixtures with dependencies.

Dependant fixtures

If a fixture depends on another fixture you can implement DependentFixtureInterface and the function getDependencies returns an array of classes that the fixture depends on.

An example from would be:

Ordered fixtures

You can also specify the order fixtures are loaded in by implementing the interface OrderedFixtureInterface the method getOrder returns an number which represents the order.

Referencing other fixtures

During the load you can store a reference to a fixture by adding it to the internal reference storage with $this->addReference(string $identifier, object $reference);. An example is:

You'd then use it by calling $this->getByReference(string $identifier). Example:

Only running creation/purging

Run the task without purging:

Purge the data:

Do literally nothing:

Quality of life functionality:

Filtering

You can selectively run fixtures using the filter param:

This will run any fixture matching the filter pattern and any ordered fixtures and these won't be automatically resolved like dependencies.

The filter pattern must be a valid pattern for preg_match including a delimiter. The pattern is matched against the fully qualified class name (eg App\My\Fixture).

Creating assets

You can create assets really easily like so:

This will create the image, and store it with a reference of my-asset-id. You can also pass through as a third argument an array of params e.g. ['Title' => 'my asset title'] this will be translated to $image->Title = 'my asset title' so is case-sensitive. The function will also return the stored image. The fourth argument allows you to specify another Asset type eg SilverStripe\Assets\File.

You can then access the asset through $this->getByReference('my-asset-id')

Creating other DataObject's can be done like so (these are only written through ->write):

Maintainers

Development and contribution

Smash that pull request button 🥰


All versions of silverstripe-fixtures with dependencies

PHP Build Version
Package Version
Requires php Version ^7.4 || ^8.0
silverstripe/framework Version ^4.0 || ^5.0
silverstripe/admin Version ^1.0 || ^2.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 adrhumphreys/silverstripe-fixtures contains the following files

Loading the files please wait ....