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
- CApplicationComponent implements IApplicationComponent
- CDbFixtureManager
Direct known subclasses
X2FixtureManagerCopyright: 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
public
|
|
public
|
|
public
|
#
prepare( )
Prepares the fixtures for the whole test. This method is invoked in |
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, |
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 |
public
array
|
#
getFixtures( )
Returns the information of the available fixtures. This method will search
for all PHP files under |
public
|
#
checkIntegrity( boolean $check )
Enables or disables database integrity check. This method may be used to temporarily turn off foreign constraints 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 |
public
|
#
truncateTables( string $schema = '' )
Truncates all tables in the specified schema. You may need to call |
public
|
#
load( array $fixtures )
Loads the specified fixtures. For each fixture, the corresponding table will
be reset first by calling |
public
array
|
|
public
|
getIsInitialized()
|
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. |
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. |
public
string
|
$basePath |
|
#
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. |
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. |
protected
mixed
|
$_rows |
|
|
protected
mixed
|
$_records |
|
$behaviors
|
public
|
$dbConnection |
#
The database connection. |
public
array
|
$fixtures |
#
The information of the available fixtures (table name => fixture file). |
$isInitialized
|