CDbTestCase
Package | system.test |
---|---|
Inheritance | abstract class CDbTestCase » CTestCase » PHPUnit_Framework_TestCase » PHPUnit_Framework_Assert |
Implements | PHPUnit_Framework_Test, Countable, PHPUnit_Framework_SelfDescribing |
Since | 1.1 |
Version | $Id: CDbTestCase.php 1678 2010-01-07 21:02:00Z qiang.xue $ |
CDbTestCase provides database fixture management with the help of CDbFixtureManager. By declaring fixtures property, one can ensure the specified tables have the expected fixture state when executing each test method. In addition, CDbTestCase provides two ways to access the fixture data.
For example, assume we declare fixtures to be:
public $fixtures=array( 'posts' => 'Post', 'comments' => 'Comment', );
We can access the original fixture data rows using
$this->posts
$this->posts['first post']
. We can also retrieve an ActiveRecord instance
corresponding to a fixture data row using $this->posts('first post')
.
Note, here 'first post' refers to a key to a row in the original fixture data.Protected Properties
Property | Type | Description | Defined By |
---|---|---|---|
backupGlobals | boolean | Enable or disable the backup and restoration of the $GLOBALS array. | PHPUnit_Framework_TestCase |
backupGlobalsBlacklist | array | PHPUnit_Framework_TestCase | |
backupStaticAttributes | boolean | Enable or disable the backup and restoration of static attributes. | PHPUnit_Framework_TestCase |
backupStaticAttributesBlacklist | array | PHPUnit_Framework_TestCase | |
data | array | PHPUnit_Framework_TestCase | |
dataName | string | PHPUnit_Framework_TestCase | |
dependencies | array | PHPUnit_Framework_TestCase | |
dependencyInput | array | PHPUnit_Framework_TestCase | |
exceptionCode | integer | PHPUnit_Framework_TestCase | |
exceptionMessage | string | PHPUnit_Framework_TestCase | |
expectedException | mixed | The name of the expected Exception. | PHPUnit_Framework_TestCase |
expectedExceptionCode | integer | The code of the expected Exception. | PHPUnit_Framework_TestCase |
expectedExceptionMessage | string | The message of the expected Exception. | PHPUnit_Framework_TestCase |
fixtures | array | a list of fixtures that should be loaded before each test method executes. | CDbTestCase |
inIsolation | boolean | Whether or not this test is running in a separate PHP process. | PHPUnit_Framework_TestCase |
iniSettings | Array | PHPUnit_Framework_TestCase | |
locale | Array | PHPUnit_Framework_TestCase | |
mockObjects | Array | PHPUnit_Framework_TestCase | |
name | string | The name of the test case. | PHPUnit_Framework_TestCase |
numAssertions | integer | PHPUnit_Framework_TestCase | |
preserveGlobalState | boolean | Whether or not this test should preserve the global state when running in a separate PHP process. | PHPUnit_Framework_TestCase |
result | PHPUnit_Framework_TestResult | PHPUnit_Framework_TestCase | |
runTestInSeparateProcess | boolean | Whether or not this test is to be run in a separate PHP process. | PHPUnit_Framework_TestCase |
sharedFixture | mixed | Fixture that is shared between the tests of a test suite. | PHPUnit_Framework_TestCase |
status | integer | PHPUnit_Framework_TestCase | |
statusMessage | string | PHPUnit_Framework_TestCase | |
testResult | mixed | PHPUnit_Framework_TestCase | |
useErrorHandler | boolean | PHPUnit_Framework_TestCase | |
useOutputBuffering | boolean | PHPUnit_Framework_TestCase |
Public Methods
Method | Description | Defined By |
---|---|---|
__call() | PHP magic method. | CDbTestCase |
__construct() | Constructs a test case with the given name. | PHPUnit_Framework_TestCase |
__get() | PHP magic method. | CDbTestCase |
addToAssertionCount() | Adds a value to the assertion counter. | PHPUnit_Framework_TestCase |
anything() | Returns a PHPUnit_Framework_Constraint_IsAnything matcher object. | PHPUnit_Framework_Assert |
arrayHasKey() | Returns a PHPUnit_Framework_Constraint_ArrayHasKey matcher object. | PHPUnit_Framework_Assert |
assertArrayHasKey() | Asserts that an array has a specified key. | PHPUnit_Framework_Assert |
assertArrayNotHasKey() | Asserts that an array does not have a specified key. | PHPUnit_Framework_Assert |
assertAttributeContains() | Asserts that a haystack that is stored in a static attribute of a class | PHPUnit_Framework_Assert |
assertAttributeContainsOnly() | Asserts that a haystack that is stored in a static attribute of a class | PHPUnit_Framework_Assert |
assertAttributeEquals() | Asserts that a variable is equal to an attribute of an object. | PHPUnit_Framework_Assert |
assertAttributeGreaterThan() | Asserts that an attribute is greater than another value. | PHPUnit_Framework_Assert |
assertAttributeGreaterThanOrEqual() | Asserts that an attribute is greater than or equal to another value. | PHPUnit_Framework_Assert |
assertAttributeLessThan() | Asserts that an attribute is smaller than another value. | PHPUnit_Framework_Assert |
assertAttributeLessThanOrEqual() | Asserts that an attribute is smaller than or equal to another value. | PHPUnit_Framework_Assert |
assertAttributeNotContains() | Asserts that a haystack that is stored in a static attribute of a class | PHPUnit_Framework_Assert |
assertAttributeNotContainsOnly() | Asserts that a haystack that is stored in a static attribute of a class | PHPUnit_Framework_Assert |
assertAttributeNotEquals() | Asserts that a variable is not equal to an attribute of an object. | PHPUnit_Framework_Assert |
assertAttributeNotSame() | Asserts that a variable and an attribute of an object do not have the | PHPUnit_Framework_Assert |
assertAttributeNotType() | Asserts that an attribute is of a given type. | PHPUnit_Framework_Assert |
assertAttributeSame() | Asserts that a variable and an attribute of an object have the same type | PHPUnit_Framework_Assert |
assertAttributeType() | Asserts that an attribute is of a given type. | PHPUnit_Framework_Assert |
assertClassHasAttribute() | Asserts that a class has a specified attribute. | PHPUnit_Framework_Assert |
assertClassHasStaticAttribute() | Asserts that a class has a specified static attribute. | PHPUnit_Framework_Assert |
assertClassNotHasAttribute() | Asserts that a class does not have a specified attribute. | PHPUnit_Framework_Assert |
assertClassNotHasStaticAttribute() | Asserts that a class does not have a specified static attribute. | PHPUnit_Framework_Assert |
assertContains() | Asserts that a haystack contains a needle. | PHPUnit_Framework_Assert |
assertContainsOnly() | Asserts that a haystack contains only values of a given type. | PHPUnit_Framework_Assert |
assertEqualXMLStructure() | Asserts that a hierarchy of DOMNodes matches. | PHPUnit_Framework_Assert |
assertEquals() | Asserts that two variables are equal. | PHPUnit_Framework_Assert |
assertFalse() | Asserts that a condition is false. | PHPUnit_Framework_Assert |
assertFileEquals() | Asserts that the contents of one file is equal to the contents of another | PHPUnit_Framework_Assert |
assertFileExists() | Asserts that a file exists. | PHPUnit_Framework_Assert |
assertFileNotEquals() | Asserts that the contents of one file is not equal to the contents of | PHPUnit_Framework_Assert |
assertFileNotExists() | Asserts that a file does not exist. | PHPUnit_Framework_Assert |
assertGreaterThan() | Asserts that a value is greater than another value. | PHPUnit_Framework_Assert |
assertGreaterThanOrEqual() | Asserts that a value is greater than or equal to another value. | PHPUnit_Framework_Assert |
assertLessThan() | Asserts that a value is smaller than another value. | PHPUnit_Framework_Assert |
assertLessThanOrEqual() | Asserts that a value is smaller than or equal to another value. | PHPUnit_Framework_Assert |
assertNotContains() | Asserts that a haystack does not contain a needle. | PHPUnit_Framework_Assert |
assertNotContainsOnly() | Asserts that a haystack does not contain only values of a given type. | PHPUnit_Framework_Assert |
assertNotEquals() | Asserts that two variables are not equal. | PHPUnit_Framework_Assert |
assertNotNull() | Asserts that a variable is not NULL. | PHPUnit_Framework_Assert |
assertNotRegExp() | Asserts that a string does not match a given regular expression. | PHPUnit_Framework_Assert |
assertNotSame() | Asserts that two variables do not have the same type and value. | PHPUnit_Framework_Assert |
assertNotTag() | This assertion is the exact opposite of assertTag(). | PHPUnit_Framework_Assert |
assertNotType() | Asserts that a variable is not of a given type. | PHPUnit_Framework_Assert |
assertNull() | Asserts that a variable is NULL. | PHPUnit_Framework_Assert |
assertObjectHasAttribute() | Asserts that an object has a specified attribute. | PHPUnit_Framework_Assert |
assertObjectNotHasAttribute() | Asserts that an object does not have a specified attribute. | PHPUnit_Framework_Assert |
assertRegExp() | Asserts that a string matches a given regular expression. | PHPUnit_Framework_Assert |
assertSame() | Asserts that two variables have the same type and value. | PHPUnit_Framework_Assert |
assertSelectCount() | Assert the presence, absence, or count of elements in a document matching | PHPUnit_Framework_Assert |
assertSelectEquals() | assertSelectEquals("#binder .name", "Chuck", true, $xml); // any? | PHPUnit_Framework_Assert |
assertSelectRegExp() | assertSelectRegExp("#binder .name", "/Mike|Derek/", true, $xml); // any? | PHPUnit_Framework_Assert |
assertStringEndsNotWith() | Asserts that a string ends not with a given prefix. | PHPUnit_Framework_Assert |
assertStringEndsWith() | Asserts that a string ends with a given prefix. | PHPUnit_Framework_Assert |
assertStringEqualsFile() | Asserts that the contents of a string is equal | PHPUnit_Framework_Assert |
assertStringNotEqualsFile() | Asserts that the contents of a string is not equal | PHPUnit_Framework_Assert |
assertStringStartsNotWith() | Asserts that a string starts not with a given prefix. | PHPUnit_Framework_Assert |
assertStringStartsWith() | Asserts that a string starts with a given prefix. | PHPUnit_Framework_Assert |
assertTag() | Evaluate an HTML or XML string and assert its structure and/or contents. | PHPUnit_Framework_Assert |
assertThat() | Evaluates a PHPUnit_Framework_Constraint matcher object. | PHPUnit_Framework_Assert |
assertTrue() | Asserts that a condition is true. | PHPUnit_Framework_Assert |
assertType() | Asserts that a variable is of a given type. | PHPUnit_Framework_Assert |
assertXmlFileEqualsXmlFile() | Asserts that two XML files are equal. | PHPUnit_Framework_Assert |
assertXmlFileNotEqualsXmlFile() | Asserts that two XML files are not equal. | PHPUnit_Framework_Assert |
assertXmlStringEqualsXmlFile() | Asserts that two XML documents are equal. | PHPUnit_Framework_Assert |
assertXmlStringEqualsXmlString() | Asserts that two XML documents are equal. | PHPUnit_Framework_Assert |
assertXmlStringNotEqualsXmlFile() | Asserts that two XML documents are not equal. | PHPUnit_Framework_Assert |
assertXmlStringNotEqualsXmlString() | Asserts that two XML documents are not equal. | PHPUnit_Framework_Assert |
attribute() | Returns a PHPUnit_Framework_Constraint_Attribute matcher object. | PHPUnit_Framework_Assert |
attributeEqualTo() | Returns a PHPUnit_Framework_Constraint_IsEqual matcher object | PHPUnit_Framework_Assert |
classHasAttribute() | Returns a PHPUnit_Framework_Constraint_ClassHasAttribute matcher object. | PHPUnit_Framework_Assert |
classHasStaticAttribute() | Returns a PHPUnit_Framework_Constraint_ClassHasStaticAttribute matcher | PHPUnit_Framework_Assert |
contains() | Returns a PHPUnit_Framework_Constraint_TraversableContains matcher | PHPUnit_Framework_Assert |
containsOnly() | Returns a PHPUnit_Framework_Constraint_TraversableContainsOnly matcher | PHPUnit_Framework_Assert |
count() | Counts the number of test cases executed by run(TestResult result). | PHPUnit_Framework_TestCase |
equalTo() | Returns a PHPUnit_Framework_Constraint_IsEqual matcher object. | PHPUnit_Framework_Assert |
fail() | Fails a test with the given message. | PHPUnit_Framework_Assert |
fileExists() | Returns a PHPUnit_Framework_Constraint_FileExists matcher object. | PHPUnit_Framework_Assert |
getAnnotations() | Returns the annotations for this test. | PHPUnit_Framework_TestCase |
getCount() | Return the current assertion count. | PHPUnit_Framework_Assert |
getExpectedException() | PHPUnit_Framework_TestCase | |
getFixtureData() | CDbTestCase | |
getFixtureManager() | CDbTestCase | |
getFixtureRecord() | CDbTestCase | |
getName() | Gets the name of a TestCase. | PHPUnit_Framework_TestCase |
getNumAssertions() | Returns the number of assertions performed by this test. | PHPUnit_Framework_TestCase |
getResult() | PHPUnit_Framework_TestCase | |
getStatus() | Returns the status of this test. | PHPUnit_Framework_TestCase |
getStatusMessage() | Returns the status message of this test. | PHPUnit_Framework_TestCase |
greaterThan() | Returns a PHPUnit_Framework_Constraint_GreaterThan matcher object. | PHPUnit_Framework_Assert |
greaterThanOrEqual() | Returns a PHPUnit_Framework_Constraint_Or matcher object that wraps | PHPUnit_Framework_Assert |
hasFailed() | Returns whether or not this test has failed. | PHPUnit_Framework_TestCase |
identicalTo() | Returns a PHPUnit_Framework_Constraint_IsIdentical matcher object. | PHPUnit_Framework_Assert |
isFalse() | Returns a PHPUnit_Framework_Constraint_IsFalse matcher object. | PHPUnit_Framework_Assert |
isInstanceOf() | Returns a PHPUnit_Framework_Constraint_IsInstanceOf matcher object. | PHPUnit_Framework_Assert |
isNull() | Returns a PHPUnit_Framework_Constraint_IsNull matcher object. | PHPUnit_Framework_Assert |
isTrue() | Returns a PHPUnit_Framework_Constraint_IsTrue matcher object. | PHPUnit_Framework_Assert |
isType() | Returns a PHPUnit_Framework_Constraint_IsType matcher object. | PHPUnit_Framework_Assert |
lessThan() | Returns a PHPUnit_Framework_Constraint_LessThan matcher object. | PHPUnit_Framework_Assert |
lessThanOrEqual() | Returns a PHPUnit_Framework_Constraint_Or matcher object that wraps | PHPUnit_Framework_Assert |
logicalAnd() | Returns a PHPUnit_Framework_Constraint_And matcher object. | PHPUnit_Framework_Assert |
logicalNot() | Returns a PHPUnit_Framework_Constraint_Not matcher object. | PHPUnit_Framework_Assert |
logicalOr() | Returns a PHPUnit_Framework_Constraint_Or matcher object. | PHPUnit_Framework_Assert |
logicalXor() | Returns a PHPUnit_Framework_Constraint_Xor matcher object. | PHPUnit_Framework_Assert |
markTestIncomplete() | Mark the test as incomplete. | PHPUnit_Framework_Assert |
markTestSkipped() | Mark the test as skipped. | PHPUnit_Framework_Assert |
matchesRegularExpression() | Returns a PHPUnit_Framework_Constraint_PCREMatch matcher object. | PHPUnit_Framework_Assert |
objectHasAttribute() | Returns a PHPUnit_Framework_Constraint_ObjectHasAttribute matcher object. | PHPUnit_Framework_Assert |
readAttribute() | Returns the value of an attribute of a class or an object. | PHPUnit_Framework_Assert |
resetCount() | Reset the assertion counter. | PHPUnit_Framework_Assert |
run() | Runs the test case and collects the results in a TestResult object. | PHPUnit_Framework_TestCase |
runBare() | Runs the bare test sequence. | PHPUnit_Framework_TestCase |
setBackupGlobals() | Calling this method in setUp() has no effect! | PHPUnit_Framework_TestCase |
setBackupStaticAttributes() | Calling this method in setUp() has no effect! | PHPUnit_Framework_TestCase |
setDependencies() | Sets the dependencies of a TestCase. | PHPUnit_Framework_TestCase |
setDependencyInput() | Sets | PHPUnit_Framework_TestCase |
setExpectedException() | PHPUnit_Framework_TestCase | |
setInIsolation() | PHPUnit_Framework_TestCase | |
setName() | Sets the name of a TestCase. | PHPUnit_Framework_TestCase |
setPreserveGlobalState() | PHPUnit_Framework_TestCase | |
setResult() | PHPUnit_Framework_TestCase | |
setRunTestInSeparateProcess() | PHPUnit_Framework_TestCase | |
setSharedFixture() | Sets the shared fixture. | PHPUnit_Framework_TestCase |
setUpBeforeClass() | This method is called before the first test of this test class is run. | PHPUnit_Framework_TestCase |
setUseErrorHandler() | PHPUnit_Framework_TestCase | |
setUseOutputBuffering() | PHPUnit_Framework_TestCase | |
stringContains() | Returns a PHPUnit_Framework_Constraint_StringContains matcher object. | PHPUnit_Framework_Assert |
stringEndsWith() | Returns a PHPUnit_Framework_Constraint_StringEndsWith matcher object. | PHPUnit_Framework_Assert |
stringStartsWith() | Returns a PHPUnit_Framework_Constraint_StringStartsWith matcher object. | PHPUnit_Framework_Assert |
tearDownAfterClass() | This method is called after the last test of this test class is run. | PHPUnit_Framework_TestCase |
toString() | Returns a string representation of the test case. | PHPUnit_Framework_TestCase |
Protected Methods
Method | Description | Defined By |
---|---|---|
any() | Returns a matcher that matches when the method it is evaluated for | PHPUnit_Framework_TestCase |
assertPostConditions() | Performs assertions shared by all tests of a test case. | PHPUnit_Framework_TestCase |
assertPreConditions() | Performs assertions shared by all tests of a test case. | PHPUnit_Framework_TestCase |
at() | Returns a matcher that matches when the method it is evaluated for | PHPUnit_Framework_TestCase |
atLeastOnce() | Returns a matcher that matches when the method it is evaluated for | PHPUnit_Framework_TestCase |
createResult() | Creates a default TestResult object. | PHPUnit_Framework_TestCase |
dataToString() | PHPUnit_Framework_TestCase | |
exactly() | Returns a matcher that matches when the method it is evaluated for | PHPUnit_Framework_TestCase |
getDataSetAsString() | Gets the data set description of a TestCase. | PHPUnit_Framework_TestCase |
getMock() | Returns a mock object for the specified class. | PHPUnit_Framework_TestCase |
getMockForAbstractClass() | Returns a mock object for the specified abstract class with all abstract | PHPUnit_Framework_TestCase |
getMockFromWsdl() | Returns a mock object based on the given WSDL file. | PHPUnit_Framework_TestCase |
iniSet() | This method is a wrapper for the ini_set() function that automatically | PHPUnit_Framework_TestCase |
never() | Returns a matcher that matches when the method it is evaluated for | PHPUnit_Framework_TestCase |
onConsecutiveCalls() | PHPUnit_Framework_TestCase | |
onNotSuccessfulTest() | This method is called when a test method did not execute successfully. | PHPUnit_Framework_TestCase |
once() | Returns a matcher that matches when the method it is evaluated for | PHPUnit_Framework_TestCase |
prepareTemplate() | Performs custom preparations on the process isolation template. | PHPUnit_Framework_TestCase |
returnArgument() | PHPUnit_Framework_TestCase | |
returnCallback() | PHPUnit_Framework_TestCase | |
returnValue() | PHPUnit_Framework_TestCase | |
runTest() | Override to run the test and assert its state. | PHPUnit_Framework_TestCase |
setExpectedExceptionFromAnnotation() | PHPUnit_Framework_TestCase | |
setLocale() | This method is a wrapper for the setlocale() function that automatically | PHPUnit_Framework_TestCase |
setUp() | Sets up the fixture before executing a test method. | CDbTestCase |
setUseErrorHandlerFromAnnotation() | PHPUnit_Framework_TestCase | |
setUseOutputBufferingFromAnnotation() | PHPUnit_Framework_TestCase | |
tearDown() | Tears down the fixture, for example, close a network connection. | PHPUnit_Framework_TestCase |
throwException() | PHPUnit_Framework_TestCase |
Property Details
a list of fixtures that should be loaded before each test method executes. 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). Defaults to false, meaning fixtures will not be used at all.
Method Details
public mixed __call(string $name, string $params)
| ||
$name | string | method name |
$params | string | method parameters |
{return} | mixed | the property value |
PHP magic method. This method is overridden so that named fixture ActiveRecord instances can be accessed in terms of a method call.
public mixed __get(string $name)
| ||
$name | string | the property name |
{return} | mixed | the property value |
PHP magic method. This method is overridden so that named fixture data can be accessed like a normal property.
public array getFixtureData(string $name)
| ||
$name | string | the fixture name (the key value in fixtures). |
{return} | array | the named fixture data |
public CDbFixtureManager getFixtureManager()
| ||
{return} | CDbFixtureManager | the database fixture manager |
public CActiveRecord getFixtureRecord(string $name, string $alias)
| ||
$name | string | the fixture name (the key value in fixtures). |
$alias | string | the alias of the fixture data row |
{return} | CActiveRecord | the ActiveRecord instance corresponding to the specified alias in the named fixture. False is returned if there is no such fixture or the record cannot be found. |
protected void setUp()
|
Sets up the fixture before executing a test method. If you override this method, make sure the parent implementation is invoked. Otherwise, the database fixtures will not be managed properly.