Overview

Packages

  • application
    • commands
    • components
      • actions
      • filters
      • leftWidget
      • permissions
      • sortableWidget
      • util
      • webupdater
      • x2flow
        • actions
        • triggers
      • X2GridView
      • X2Settings
    • controllers
    • models
      • embedded
    • modules
      • accounts
        • controllers
        • models
      • actions
        • controllers
        • models
      • calendar
        • controllers
        • models
      • charts
        • models
      • contacts
        • controllers
        • models
      • docs
        • components
        • controllers
        • models
      • groups
        • controllers
        • models
      • marketing
        • components
        • controllers
        • models
      • media
        • controllers
        • models
      • mobile
        • components
      • opportunities
        • controllers
        • models
      • products
        • controllers
        • models
      • quotes
        • controllers
        • models
      • services
        • controllers
        • models
      • template
        • models
      • users
        • controllers
        • models
      • workflow
        • controllers
        • models
      • x2Leads
        • controllers
        • models
  • Net
  • None
  • PHP
  • system
    • base
    • caching
      • dependencies
    • collections
    • console
    • db
      • ar
      • schema
        • cubrid
        • mssql
        • mysql
        • oci
        • pgsql
        • sqlite
    • i18n
      • gettext
    • logging
    • test
    • utils
    • validators
    • web
      • actions
      • auth
      • filters
      • form
      • helpers
      • renderers
      • services
      • widgets
        • captcha
        • pagers
  • Text
    • Highlighter
  • zii
    • behaviors
    • widgets
      • grid
      • jui

Classes

  • CDbFixtureManager
  • CDbTestCase
  • CTestCase
  • CWebTestCase
  • Overview
  • Package
  • Class
  • Tree

Class CDbFixtureManager

CDbFixtureManager manages database fixtures during tests.

A fixture represents a list of rows for a specific table. For a test method, using a fixture means that at the beginning of the method, the table has and only has the rows that are given in the fixture. Therefore, the table's state is predictable.

A fixture is represented as a PHP script whose name (without suffix) is the same as the table name (if schema name is needed, it should be prefixed to the table name). The PHP script returns an array representing a list of table rows. Each row is an associative array of column values indexed by column names.

A fixture can be associated with an init script which sits under the same fixture directory and is named as "TableName.init.php". The init script is used to initialize the table before populating the fixture data into the table. If the init script does not exist, the table will be emptied.

Fixtures must be stored under the CDbFixtureManager::$basePath directory. The directory may contain a file named "init.php" which will be executed once to initialize the database. If this file is not found, all available fixtures will be loaded into the database.

CComponent
Extended by CApplicationComponent implements IApplicationComponent
Extended by CDbFixtureManager

Direct known subclasses

X2FixtureManager
Package: system\test
Copyright: 2008-2013 Yii Software LLC
License: http://www.yiiframework.com/license/
Author: Qiang Xue <qiang.xue@gmail.com>
Since: 1.1
Located at x2engine/framework/test/CDbFixtureManager.php
Methods summary
public
# init( )

Initializes this application component.

Initializes this application component.

Overrides

CApplicationComponent::init()
public CDbConnection
# getDbConnection( )

Returns the database connection used to load fixtures.

Returns the database connection used to load fixtures.

Returns

CDbConnection
the database connection

Throws

CException
if CDbFixtureManager::$connectionID application component is invalid
public
# prepare( )

Prepares the fixtures for the whole test. This method is invoked in CDbFixtureManager::init(). It executes the database init script if it exists. Otherwise, it will load all available fixtures.

Prepares the fixtures for the whole test. This method is invoked in CDbFixtureManager::init(). It executes the database init script if it exists. Otherwise, it will load all available fixtures.

public
# resetTable( string $tableName )

Resets the table to the state that it contains no fixture data. If there is an init script named "tests/fixtures/TableName.init.php", the script will be executed. Otherwise, CDbFixtureManager::truncateTable() will be invoked to delete all rows in the table and reset primary key sequence, if any.

Resets the table to the state that it contains no fixture data. If there is an init script named "tests/fixtures/TableName.init.php", the script will be executed. Otherwise, CDbFixtureManager::truncateTable() will be invoked to delete all rows in the table and reset primary key sequence, if any.

Parameters

$tableName
string
$tableName the table name
public array
# loadFixture( string $tableName )

Loads the fixture for the specified table. This method will insert rows given in the fixture into the corresponding table. The loaded rows will be returned by this method. If the table has auto-incremental primary key, each row will contain updated primary key value. If the fixture does not exist, this method will return false. Note, you may want to call CDbFixtureManager::resetTable() before calling this method so that the table is emptied first.

Loads the fixture for the specified table. This method will insert rows given in the fixture into the corresponding table. The loaded rows will be returned by this method. If the table has auto-incremental primary key, each row will contain updated primary key value. If the fixture does not exist, this method will return false. Note, you may want to call CDbFixtureManager::resetTable() before calling this method so that the table is emptied first.

Parameters

$tableName
string
$tableName table name

Returns

array
the loaded fixture rows indexed by row aliases (if any). False is returned if the table does not have a fixture.
public array
# getFixtures( )

Returns the information of the available fixtures. This method will search for all PHP files under CDbFixtureManager::$basePath. If a file's name is the same as a table name, it is considered to be the fixture data for that table.

Returns the information of the available fixtures. This method will search for all PHP files under CDbFixtureManager::$basePath. If a file's name is the same as a table name, it is considered to be the fixture data for that table.

Returns

array
the information of the available fixtures (table name => fixture file)
public
# checkIntegrity( boolean $check )

Enables or disables database integrity check. This method may be used to temporarily turn off foreign constraints check.

Enables or disables database integrity check. This method may be used to temporarily turn off foreign constraints check.

Parameters

$check
boolean
$check whether to enable database integrity check
public
# truncateTable( string $tableName )

Removes all rows from the specified table and resets its primary key sequence, if any. You may need to call CDbFixtureManager::checkIntegrity() to turn off integrity check temporarily before you call this method.

Removes all rows from the specified table and resets its primary key sequence, if any. You may need to call CDbFixtureManager::checkIntegrity() to turn off integrity check temporarily before you call this method.

Parameters

$tableName
string
$tableName the table name

Throws

CException
if given table does not exist
public
# truncateTables( string $schema = '' )

Truncates all tables in the specified schema. You may need to call CDbFixtureManager::checkIntegrity() to turn off integrity check temporarily before you call this method.

Truncates all tables in the specified schema. You may need to call CDbFixtureManager::checkIntegrity() to turn off integrity check temporarily before you call this method.

Parameters

$schema
string
$schema the schema name. Defaults to empty string, meaning the default database schema.

See

CDbFixtureManager::truncateTable()
public
# load( array $fixtures )

Loads the specified fixtures. For each fixture, the corresponding table will be reset first by calling CDbFixtureManager::resetTable() and then be populated with the fixture data. The loaded fixture data may be later retrieved using CDbFixtureManager::getRows() and CDbFixtureManager::getRecord(). Note, if a table does not have fixture data, CDbFixtureManager::resetTable() will still be called to reset the table.

Loads the specified fixtures. For each fixture, the corresponding table will be reset first by calling CDbFixtureManager::resetTable() and then be populated with the fixture data. The loaded fixture data may be later retrieved using CDbFixtureManager::getRows() and CDbFixtureManager::getRecord(). Note, if a table does not have fixture data, CDbFixtureManager::resetTable() will still be called to reset the table.

Parameters

$fixtures
array
$fixtures fixtures to be loaded. The array keys are fixture names, and the array values are either AR class names or table names. If table names, they must begin with a colon character (e.g. 'Post' means an AR class, while ':Post' means a table name).
public array
# getRows( string $name )

Returns the fixture data rows. The rows will have updated primary key values if the primary key is auto-incremental.

Returns the fixture data rows. The rows will have updated primary key values if the primary key is auto-incremental.

Parameters

$name
string
$name the fixture name

Returns

array
the fixture data rows. False is returned if there is no such fixture data.
public CActiveRecord
# getRecord( string $name, string $alias )

Returns the specified ActiveRecord instance in the fixture data.

Returns the specified ActiveRecord instance in the fixture data.

Parameters

$name
string
$name the fixture name
$alias
string
$alias the alias for the fixture data row

Returns

CActiveRecord
the ActiveRecord instance. False is returned if there is no such fixture row.
Methods inherited from CApplicationComponent
getIsInitialized()
Methods inherited from CComponent
__call(), __get(), __isset(), __set(), __unset(), asa(), attachBehavior(), attachBehaviors(), attachEventHandler(), canGetProperty(), canSetProperty(), detachBehavior(), detachBehaviors(), detachEventHandler(), disableBehavior(), disableBehaviors(), enableBehavior(), enableBehaviors(), evaluateExpression(), getEventHandlers(), hasEvent(), hasEventHandler(), hasProperty(), raiseEvent()
Properties summary
public string $initScript 'init.php'
#

the name of the initialization script that would be executed before the whole test set runs. Defaults to 'init.php'. If the script does not exist, every table with a fixture file will be reset.

the name of the initialization script that would be executed before the whole test set runs. Defaults to 'init.php'. If the script does not exist, every table with a fixture file will be reset.

public string $initScriptSuffix '.init.php'
#

the suffix for fixture initialization scripts. If a table is associated with such a script whose name is TableName suffixed this property value, then the script will be executed each time before the table is reset.

the suffix for fixture initialization scripts. If a table is associated with such a script whose name is TableName suffixed this property value, then the script will be executed each time before the table is reset.

public string $basePath
#

the base path containing all fixtures. Defaults to null, meaning the path 'protected/tests/fixtures'.

the base path containing all fixtures. Defaults to null, meaning the path 'protected/tests/fixtures'.

public string $connectionID 'db'
#

the ID of the database connection. Defaults to 'db'. Note, data in this database may be deleted or modified during testing. Make sure you have a backup database.

the ID of the database connection. Defaults to 'db'. Note, data in this database may be deleted or modified during testing. Make sure you have a backup database.

public array $schemas array('')
#

list of database schemas that the test tables may reside in. Defaults to array(''), meaning using the default schema (an empty string refers to the default schema). This property is mainly used when turning on and off integrity checks so that fixture data can be populated into the database without causing problem.

list of database schemas that the test tables may reside in. Defaults to array(''), meaning using the default schema (an empty string refers to the default schema). This property is mainly used when turning on and off integrity checks so that fixture data can be populated into the database without causing problem.

protected mixed $_rows
#
protected mixed $_records
#
Properties inherited from CApplicationComponent
$behaviors
Magic properties summary
public CDbConnection $dbConnection
#

The database connection.

The database connection.

public array $fixtures
#

The information of the available fixtures (table name => fixture file).

The information of the available fixtures (table name => fixture file).

Magic properties inherited from CApplicationComponent
$isInitialized
API documentation generated by ApiGen 2.8.0