Properties

$connection

$connection : string

Fixture Datasource

Type

string

$table

$table : string

Full Table Name

Type

string

$fields

$fields : array

Fields / Schema for the fixture.

This array should be compatible with Cake\Database\Schema\Schema. The _constraints, _options and _indexes keys are reserved for defining constraints, options and indexes respectively.

Type

array

$import

$import : array|null

Configuration for importing fixture schema

Accepts a connection and model or table key, to define which table and which connection contain the schema to be imported.

Type

array|null

$records

$records : array

Fixture records to be inserted.

Type

array

$_constraints

$_constraints : array

Fixture constraints to be created.

Type

array

Methods

__construct()

__construct() 

Instantiate the fixture.

Throws

\Cake\Core\Exception\Exception

on invalid datasource usage.

connection()

connection() : string

Get the connection name this fixture should be inserted into.

Returns

string

sourceName()

sourceName() : string

Get the table/collection name for this fixture.

Returns

string

init()

init() : void

Initialize the fixture.

Throws

\Cake\ORM\Exception\MissingTableClassException

When importing from a table that does not exist.

create()

create(\Cake\Datasource\ConnectionInterface  $db) : boolean

Create the fixture schema/mapping/definition

Parameters

\Cake\Datasource\ConnectionInterface $db

An instance of the connection the fixture should be created on.

Returns

boolean —

True on success, false on failure.

drop()

drop(\Cake\Datasource\ConnectionInterface  $db) : boolean

Run after all tests executed, should remove the table/collection from the connection.

Parameters

\Cake\Datasource\ConnectionInterface $db

An instance of the connection the fixture should be removed from.

Returns

boolean —

True on success, false on failure.

insert()

insert(\Cake\Datasource\ConnectionInterface  $db) : \Cake\Database\StatementInterface|boolean

Run before each test is executed.

Should insert all the records into the test database.

Parameters

\Cake\Datasource\ConnectionInterface $db

An instance of the connection into which the records will be inserted.

Returns

\Cake\Database\StatementInterface|boolean —

on success or if there are no records to insert, or false on failure.

createConstraints()

createConstraints(\Cake\Datasource\ConnectionInterface  $db) : boolean

Build and execute SQL queries necessary to create the constraints for the fixture

Parameters

\Cake\Datasource\ConnectionInterface $db

An instance of the database into which the constraints will be created

Returns

boolean —

on success or if there are no constraints to create, or false on failure

dropConstraints()

dropConstraints(\Cake\Datasource\ConnectionInterface  $db) : boolean

Build and execute SQL queries necessary to drop the constraints for the fixture

Parameters

\Cake\Datasource\ConnectionInterface $db

An instance of the database into which the constraints will be dropped

Returns

boolean —

on success or if there are no constraints to drop, or false on failure

truncate()

truncate(\Cake\Datasource\ConnectionInterface  $db) : boolean

Truncates the current fixture.

Parameters

\Cake\Datasource\ConnectionInterface $db

A reference to a db instance

Returns

boolean

setTableSchema()

setTableSchema(\Cake\Database\Schema\TableSchemaInterface  $schema) : $this

Get and set the schema for this fixture.

Parameters

\Cake\Database\Schema\TableSchemaInterface $schema

The table to set.

Returns

$this

tableLocator()

tableLocator(\Cake\ORM\Locator\LocatorInterface|null  $tableLocator = null) : \Cake\ORM\Locator\LocatorInterface

Sets the table locator.

If no parameters are passed, it will return the currently used locator.

Parameters

\Cake\ORM\Locator\LocatorInterface|null $tableLocator

LocatorInterface instance.

Returns

\Cake\ORM\Locator\LocatorInterface

setTableLocator()

setTableLocator(\Cake\ORM\Locator\LocatorInterface  $tableLocator) : $this

Sets the table locator.

Parameters

\Cake\ORM\Locator\LocatorInterface $tableLocator

LocatorInterface instance.

Returns

$this

_tableFromClass()

_tableFromClass() : string

Returns the table name using the fixture class

Returns

string

_schemaFromFields()

_schemaFromFields() : void

Build the fixtures table schema from the fields property.

_schemaFromImport()

_schemaFromImport() : void

Build fixture schema from a table in another datasource.

Throws

\Cake\Core\Exception\Exception

when trying to import from an empty table.

_schemaFromReflection()

_schemaFromReflection() : void

Build fixture schema directly from the datasource

Throws

\Cake\Core\Exception\Exception

when trying to reflect a table that does not exist

_getRecords()

_getRecords() : array

Converts the internal records into data used to generate a query.

Returns

array