Abstract Class CriticalI_DBTestCase

Description

The DBTestCase class exists as a convenience for writing test cases

that require a database. Creating and/or resetting a database for each test involves significant overhead, so confining that behavior to this class allows that to be skipped for test cases that don't require it (test cases that inherit directly from CriticalI_TestCase).

This class includes a number of special behaviors. By default it connects to or creates a SQLite database named .db in the current directory. A different database can be used by overriding the connection() method.

Once the database connection has been established, the class looks for a directory named schema. Any files ending in .sql in the schema directory are assumed to contain table creation statements and to be named for the table they created. Any table with the same is dropped, and the contents of the .sql file are sent to the database.

For each test that is run, the class looks for a directory named fixtures. Any files ending in .ini in the fixtures directory are assumed to also be named for their corresponding tables. The table for each file is truncated, the data in the fixture file is loaded into the database, and the data becomes available by calling the fixture method with the fixture name and key.

  • abstract:

Located in /Core/lib/CriticalI/DBTestCase.php (line 31)

PHPUnit_Framework_TestCase
   |
   --CriticalI_TestCase
      |
      --CriticalI_DBTestCase
Variable Summary
 static mixed $allConnections
 mixed $connection
 mixed $fixtures
 mixed $testDir
Method Summary
 string build_fixture_sql (PDO $conn, string $tableName, array $data)
 PDO connection ()
 array fixture (string $name, string $key)
 void init_schema (PDO $conn)
 void load_fixtures (PDO $conn)
 void runBare ()
 string working_directory ()
Variables
static mixed $allConnections = null (line 32)
  • access: protected
mixed $connection = null (line 36)
  • access: protected
mixed $fixtures = null (line 38)
  • access: protected
mixed $fixturesCached = false (line 37)
  • access: protected
mixed $schemaLoaded = false (line 34)
  • access: protected
mixed $testDir = null (line 35)
  • access: protected
Methods
build_fixture_sql (line 160)

Builds the INSERT SQL statement for a set of fixture data

  • access: protected
string build_fixture_sql (PDO $conn, string $tableName, array $data)
  • PDO $conn: The database connection
  • string $tableName: The name of the table to insert data into
  • array $data: The fixture data
connection (line 54)

Return the database connection

  • access: protected
PDO connection ()
fixture (line 179)

Return the data for a named fixture

  • access: protected
array fixture (string $name, string $key)
  • string $name: The name of the fixture
  • string $key: The fixture key
init_schema (line 89)

Set up the schema, if needed

  • access: protected
void init_schema (PDO $conn)
  • PDO $conn: The database connection
load_fixtures (line 103)

Set up the fixtures

  • access: protected
void load_fixtures (PDO $conn)
  • PDO $conn: The database connection
load_fixture_files (line 132)

Does the work of loading data from the fixture files

  • access: protected
void load_fixture_files ()
runBare (line 64)

Override the run method to allow additional prep

  • access: public
void runBare ()
working_directory (line 44)

Return the path to the test directory.

  • access: protected
string working_directory ()

Inherited Methods

Inherited From CriticalI_TestCase

 CriticalI_TestCase::__construct()

Documentation generated on Wed, 25 Apr 2012 09:46:42 -0700 by phpDocumentor 1.4.3