class FixtureFactory (View source)

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.

Properties

protected array $fixtures
protected array $blueprints

Methods

public
define(string $name, array|FixtureBlueprint $defaults = array())

No description

public
createObject(string $name, string $identifier, array $data = null)

Writes the fixture into the database using DataObjects

public
int
createRaw(string $table, string $identifier, array $data)

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

public
getId($class, $identifier)

Get the ID of an object from the fixture.

public
A
getIds($class)

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

public
setId($class, string $identifier, int $databaseId)

No description

public
get($class, $identifier)

Get an object from the fixture.

public
array
getFixtures()

No description

public
clear($limitToClass = null)

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

public
array
getBlueprints()

No description

public
getBlueprint(string $name)

No description

protected
string
parseValue($value)

Parse a value from a fixture file. If it starts with => it will get an ID from the fixture dictionary

Details

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

No description

Parameters

string $name

Unique name for this blueprint

array|FixtureBlueprint $defaults

Array of default values, or a blueprint instance

DataObject createObject(string $name, string $identifier, array $data = null)

Writes the fixture into the database using DataObjects

Parameters

string $name

Name of the 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

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

getId($class, $identifier)

Get the ID of an object from the fixture.

Parameters

$class
$identifier

The identifier string, as provided in your fixture file

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

setId($class, string $identifier, int $databaseId)

No description

Parameters

$class
string $identifier
int $databaseId

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

array getFixtures()

No description

Return Value

array

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

clear($limitToClass = null)

Remove all fixtures previously defined through createObject() or 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

array getBlueprints()

No description

Return Value

array

Of FixtureBlueprint instances

FixtureBlueprint getBlueprint(string $name)

No description

Parameters

string $name

Return Value

FixtureBlueprint

protected string parseValue($value)

Parse a value from a fixture file. If it starts with => it will get an ID from the fixture dictionary

Parameters

$value

Return Value

string

Fixture database ID, or the original value