W3cubDocs

/CakePHP 3.4

Class TestFixture

Cake TestFixture is responsible for building and destroying tables to be used during testing.

Cake\TestSuite\Fixture\TestFixture implements Cake\Datasource\FixtureInterface, Cake\Datasource\TableSchemaInterface

Properties summary

Method Summary

  • __construct() public
    Instantiate the fixture.
  • _getRecords() protected
    Converts the internal records into data used to generate a query.
  • Build the fixtures table schema from the fields property.
  • Build fixture schema from a table in another datasource.
  • Build fixture schema directly from the datasource
  • _tableFromClass() protected
    Returns the table name using the fixture class
  • connection() public
    Get the connection name this fixture should be inserted into.
  • create() public
    Create the fixture schema/mapping/definition
  • Build and execute SQL queries necessary to create the constraints for the fixture

  • drop() public
    Run after all tests executed, should remove the table/collection from the connection.
  • Build and execute SQL queries necessary to drop the constraints for the fixture

  • init() public
    Initialize the fixture.
  • insert() public
    Run before each test is executed.
  • schema() public
    Gets/Sets the TableSchema instance used by this fixture.
  • sourceName() public
    Get the table/collection name for this fixture.
  • truncate() public
    Truncates the current fixture.

Method Detail

__construct()source public

__construct( )

Instantiate the fixture.

Throws

Cake\Core\Exception\Exception
on invalid datasource usage.

_getRecords()source protected

_getRecords( )

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

Returns

array

_schemaFromFields()source protected

_schemaFromFields( )

Build the fixtures table schema from the fields property.

_schemaFromImport()source protected

_schemaFromImport( )

Build fixture schema from a table in another datasource.

Throws

Cake\Core\Exception\Exception
when trying to import from an empty table.

_schemaFromReflection()source protected

_schemaFromReflection( )

Build fixture schema directly from the datasource

Throws

Cake\Core\Exception\Exception
when trying to reflect a table that does not exist

_tableFromClass()source protected

_tableFromClass( )

Returns the table name using the fixture class

Returns

string

connection()source public

connection( )

Get the connection name this fixture should be inserted into.

Returns

string

Implementation of

Cake\Datasource\FixtureInterface::connection()

create()source public

create( Cake\Datasource\ConnectionInterface $db )

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.

Implementation of

Cake\Datasource\FixtureInterface::create()

createConstraints()source public

createConstraints( Cake\Datasource\ConnectionInterface $db )

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

Implementation of

Cake\Datasource\FixtureInterface::createConstraints()

drop()source public

drop( Cake\Datasource\ConnectionInterface $db )

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.

Implementation of

Cake\Datasource\FixtureInterface::drop()

dropConstraints()source public

dropConstraints( Cake\Datasource\ConnectionInterface $db )

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

Implementation of

Cake\Datasource\FixtureInterface::dropConstraints()

init()source public

init( )

Initialize the fixture.

Throws

Cake\ORM\Exception\MissingTableClassException
When importing from a table that does not exist.

insert()source public

insert( Cake\Datasource\ConnectionInterface $db )

Run before each test is executed.

Parameters

Cake\Datasource\ConnectionInterface $db
An instance of the connection into which the records will be inserted.

Returns

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

Implementation of

Cake\Datasource\FixtureInterface::insert()

schema()source public

schema( Cake\Database\Schema\TableSchema $schema null )

Gets/Sets the TableSchema instance used by this fixture.

Parameters

Cake\Database\Schema\TableSchema $schema optional null
The table to set.

Returns

Cake\Database\Schema\TableSchema|null

Implementation of

Cake\Datasource\TableSchemaInterface::schema()

sourceName()source public

sourceName( )

Get the table/collection name for this fixture.

Returns

string

Implementation of

Cake\Datasource\FixtureInterface::sourceName()

truncate()source public

truncate( Cake\Datasource\ConnectionInterface $db )

Truncates the current fixture.

Parameters

Cake\Datasource\ConnectionInterface $db
A reference to a db instance

Returns

boolean

Implementation of

Cake\Datasource\FixtureInterface::truncate()

Properties detail

$_constraintssource

protected array

Fixture constraints to be created.

[]

$_schemasource

protected Cake\Database\Schema\TableSchema

The schema for this fixture.

$connectionsource

public string

Fixture Datasource

'test'

$fieldssource

public 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.

[]

$importsource

public 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.

null

$recordssource

public array

Fixture records to be inserted.

[]

$tablesource

public string

Full Table Name

null

© 2005–2017 The Cake Software Foundation, Inc.
Licensed under the MIT License.
CakePHP is a registered trademark of Cake Software Foundation, Inc.
We are not endorsed by or affiliated with CakePHP.
https://api.cakephp.org/3.4/class-Cake.TestSuite.Fixture.TestFixture.html