class FixtureFactory

Manages a set of database fixtures for {@link DataObject} records as well as raw database table rows.

Delegates creation of objects to {@link 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

define(String $name, array|FixtureBlueprint $defaults = array())

No description

createObject(String $name, String $identifier, Array $data = null)

Writes the fixture into the database using DataObjects

Int
createRaw(String $table, String $identifier, Array $data)

Writes the fixture into the database directly using a database manipulation.

getId($class, $identifier)

Get the ID of an object from the fixture.

A
getIds($class)

Return all of the IDs in the fixture of a particular class name.

setId(String $class, String $identifier, Int $databaseId)

No description

get($class, $identifier)

Get an object from the fixture.

Array
getFixtures()

No description

clear($limitToClass = null)

Remove all fixtures previously defined through {@link createObject()} or {@link createRaw()}, both from the internal fixture mapping and the database.

Array
getBlueprints()

No description

getBlueprint(String $name)

No description

Details

at line 44
define(String $name, array|FixtureBlueprint $defaults = array())

Parameters

String $name Unique name for this blueprint
array|FixtureBlueprint $defaults Array of default values, or a blueprint instance

at line 66
DataObject createObject(String $name, String $identifier, Array $data = null)

Writes the fixture into the database using DataObjects

Parameters

String $name Name of the {@link FixtureBlueprint} to use, usually a DataObject subclass.
String $identifier Unique identifier for this fixture type
Array $data Map of properties. Overrides default data.

Return Value

DataObject

at line 91
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.

Parameters

String $table Existing database table name
String $identifier Unique identifier for this fixture type
Array $data Map of properties

Return Value

Int Database identifier

at line 109
getId($class, $identifier)

Get the ID of an object from the fixture.

Parameters

$class
$identifier

at line 122
A getIds($class)

Return all of the IDs in the fixture of a particular class name.

Parameters

$class

Return Value

A map of fixture-identifier => object-id

at line 135
setId(String $class, String $identifier, Int $databaseId)

Parameters

String $class
String $identifier
Int $databaseId

at line 146
get($class, $identifier)

Get an object from the fixture.

Parameters

$class The data class, as specified in your fixture file. Parent classes won't work
$identifier The identifier string, as provided in your fixture file

at line 155
Array getFixtures()

Return Value

Array Map of class names, containing a map of in-memory identifiers mapped to database identifiers.

at line 166
clear($limitToClass = null)

Remove all fixtures previously defined through {@link createObject()} or {@link createRaw()}, both from the internal fixture mapping and the database.

If the $class argument is set, limit clearing to items of this class.

Parameters

$limitToClass

at line 189
Array getBlueprints()

Return Value

Array Of {@link FixtureBlueprint} instances

at line 197
FixtureBlueprint getBlueprint(String $name)

Parameters

String $name

Return Value

FixtureBlueprint