Class FixtureFactory
Manages a set of database fixtures for DataObject records as well as
raw database table rows.
Delegates creation of objects to FixtureBlueprint, which can
implement class- and use-case specific fixture setup.
Supports referencing model relations through a specialized syntax:
$factory = new FixtureFactory();
$relatedObj = $factory->createObject(
'MyRelatedClass',
'relation1'
);
$obj = $factory->createObject(
'MyClass',
'object1'
array('MyRelationName' => '=>MyRelatedClass.relation1')
);
Relation loading is order dependant.
Methods summary
public
|
#
define( String $name, array|FixtureBlueprint $defaults = array() )
Parameters
- $name
String $name Unique name for this blueprint
- $defaults
array|FixtureBlueprint $defaults Array of default values, or a blueprint instance
|
public
DataObject
|
#
createObject( String $name, String $identifier, Array $data = null )
Writes the fixture into the database using DataObjects
Writes the fixture into the database using DataObjects
Parameters
- $name
String $name Name of the FixtureBlueprint to use, usually a DataObject
subclass.
- $identifier
String $identifier Unique identifier for this fixture type
- $data
Array $data Map of properties. Overrides default data.
Returns
|
public
Int
|
#
createRaw( String $table, String $identifier, Array $data )
Writes the fixture into the database directly using a database manipulation.
Does not use blueprints. Only supports tables with a primary key.
Writes the fixture into the database directly using a database manipulation.
Does not use blueprints. Only supports tables with a primary key.
Parameters
- $table
String $table Existing database table name
- $identifier
String $identifier Unique identifier for this fixture type
- $data
Array $data Map of properties
Returns
|
public
|
#
getId( mixed $class, mixed $identifier )
Get the ID of an object from the fixture.
Get the ID of an object from the fixture.
Parameters
- $class
mixed $className The data class, as specified in your fixture file. Parent classes
won't work
- $identifier
mixed $identifier The identifier string, as provided in your fixture file
|
public
A
|
#
getIds( mixed $class )
Return all of the IDs in the fixture of a particular class name.
Return all of the IDs in the fixture of a particular class name.
Returns
A map of fixture-identifier => object-id
|
public
|
#
setId( String $class, String $identifier, Int $databaseId )
Parameters
- $class
String
- $identifier
String $identifier
- $databaseId
Int $databaseId
|
public
|
#
get( mixed $class, mixed $identifier )
Get an object from the fixture.
Get an object from the fixture.
Parameters
- $class
mixed $class The data class, as specified in your fixture file. Parent classes won't
work
- $identifier
mixed $identifier The identifier string, as provided in your fixture file
|
public
Array
|
#
getFixtures( )
Returns
Array Map of class names, containing a map of in-memory identifiers mapped to database
identifiers.
|
public
|
#
clear( String $limitToClass = null )
|
public
Array
|
|
public
FixtureBlueprint
|
|
protected
String
|
#
parseValue( String $value )
Parse a value from a fixture file. If it starts with => it will get an ID
from the fixture dictionary
Parse a value from a fixture file. If it starts with => it will get an ID
from the fixture dictionary
Parameters
Returns
String Fixture database ID, or the original value
|
Magic methods summary
Properties summary
protected
array
|
$fixtures
|
#
Array of fixture items, keyed by class and unique identifier, with values
being the generated database ID. Does not store object instances.
Array of fixture items, keyed by class and unique identifier, with values
being the generated database ID. Does not store object instances.
|
protected
array
|
$blueprints
|
|
Comments
Use the Silverstripe Forum to ask questions.