Download the PHP package unionofrad/li3_fixtures without Composer
On this page you can find all versions of the php package unionofrad/li3_fixtures. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download unionofrad/li3_fixtures
More information about unionofrad/li3_fixtures
Files in unionofrad/li3_fixtures
Package li3_fixtures
Short Description The fixtures library for the li3 PHP framework
License BSD-3-Clause
Homepage http://li3.me
Informations about the package li3_fixtures
Fixtures Management for the li₃ framework.
This plugin provide fixtures managment. Should work with any kind of Source
adapters. The fixture class support the following datasource's hints:
-
If
Source::enabled('schema')
returnstrue
, theFixture
manage schema (i.e create/drop) viaSource::createSchema()
&Source::dropSchema()
. - If
Source::enabled('sources')
returnstrue
, theFixture
allow soft drop (i.e safe options).
Installation
The preferred installation method is via composer. You can add the library as a dependency via:
li₃ plugins must be registered within your application bootstrap phase as they use a different (faster) autoloader.
The official manual has more information on how to register the plugin with the app or use alternative installation methods (i.e. via GIT).
API
The Fixture class
Methods:
- Fixture::create($safe); //Create the source only
- Fixture::save($safe); //Create the source + save the fixture's records in.
- Fixture::drop($safe); //Drop the source.
- Fixture::populate($records); //Insert a record in the database
- Fixture::alter($mode, $fieldname, $value); //Altering the schema before
::create()/::save()
.
Simple example of unit test:
The Fixtures class
Fixture
is a kind of Schema
which contain records and a source name or a reference to a model.
So let save the above fixture in a class.
If you have numbers of fixtures, it will be interesting to use the Fixtures
class.
Example of use case:
Ok so why it's better to set the Fixture::_model
instead of Fixture::_source
? Long story short,
models had their own meta 'connection'
value. If a fixture is "linked" with a model, it will
automagically configure its meta 'connection'
to the fixture's connection when is created or saved.
Example:
Advanced use case
For interoperability, sometimes it's usefull to adjust fixtures according a datasources.
You can alter Fixture
's instance before creating it like the following use case:
Note :
You can recover a specific fixture's instance from Fixtures
using: