Class CakeTestFixture

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

Package: Cake\TestSuite\Fixture
Copyright: Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
License: MIT License
Location: Cake/TestSuite/Fixture/CakeTestFixture.php

Properties summary

  • $canUseMemory public
    boolean

    Fixture data can be stored in memory by default. When table is created for a fixture the MEMORY engine is used where possible. Set $canUseMemory to false if you don't want this.

  • $created public
    array
    List of datasources where this fixture has been created
  • $db public
    object
    CakePHP's DBO driver (e.g: DboMysql).
  • $fields public
    array

    Fields / Schema for the fixture. This array should match the output of Model::schema()

  • $name public
    string
    Name of the object
  • $primaryKey public
    string
    The primary key for the table this fixture represents.
  • $records public
    array
    Fixture records to be inserted.
  • $table public
    string
    Full Table Name
  • $useDbConfig public
    string
    Fixture Datasource

Method Summary

  • __construct() public
    Instantiate the fixture.
  • create() public
    Run before all tests execute, should return SQL statement to create table for this fixture could be executed successfully.
  • drop() public
    Run after all tests executed, should return SQL statement to drop table for this fixture.
  • init() public
    Initialize the fixture.
  • insert() public

    Run before each tests is executed, should return a set of SQL statements to insert records for the table of this fixture could be executed successfully.

  • truncate() public

    Truncates the current fixture. Can be overwritten by classes extending CakeFixture to trigger other events before / after truncate.

Method Detail

__construct()source public

__construct( )

Instantiate the fixture.

Throws

CakeException
on invalid datasource usage.

create()source public

create( DboSource $db )

Run before all tests execute, should return SQL statement to create table for this fixture could be executed successfully.

Parameters

DboSource $db
An instance of the database object used to create the fixture table

Returns

boolean
True on success, false on failure

drop()source public

drop( DboSource $db )

Run after all tests executed, should return SQL statement to drop table for this fixture.

Parameters

DboSource $db
An instance of the database object used to create the fixture table

Returns

boolean
True on success, false on failure

init()source public

init( )

Initialize the fixture.

Throws

MissingModelException
Whe importing from a model that does not exist.

insert()source public

insert( DboSource $db )

Run before each tests is executed, should return a set of SQL statements to insert records for the table of this fixture could be executed successfully.

Parameters

DboSource $db
An instance of the database into which the records will be inserted

Returns

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

Throws

CakeException
if counts of values and fields do not match.

truncate()source public

truncate( DboSource $db )

Truncates the current fixture. Can be overwritten by classes extending CakeFixture to trigger other events before / after truncate.

Parameters

DboSource $db
A reference to a db instance

Returns

boolean

Properties detail

$canUseMemorysource

public boolean

Fixture data can be stored in memory by default. When table is created for a fixture the MEMORY engine is used where possible. Set $canUseMemory to false if you don't want this.

true

$createdsource

public array

List of datasources where this fixture has been created

array()

$dbsource

public object

CakePHP's DBO driver (e.g: DboMysql).

null

$fieldssource

public array

Fields / Schema for the fixture. This array should match the output of Model::schema()

array()

$namesource

public string

Name of the object

null

$primaryKeysource

public string

The primary key for the table this fixture represents.

null

$recordssource

public array

Fixture records to be inserted.

array()

$tablesource

public string

Full Table Name

null

$useDbConfigsource

public string

Fixture Datasource

'test'

© 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/2.10/class-CakeTestFixture.html