Versions
Look up a class, method, property or event

CTestCase

Package system.test
Inheritance abstract class CTestCase » PHPUnit_Framework_TestCase » PHPUnit_Framework_Assert
Implements PHPUnit_Framework_SelfDescribing, Countable, PHPUnit_Framework_Test
Subclasses CDbTestCase
Since 1.1
Source Code framework/test/CTestCase.php
CTestCase is the base class for all test case classes.

Protected Properties

Hide inherited properties

PropertyTypeDescriptionDefined 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
preserveGlobalState boolean Whether or not this test should preserve the global state when PHPUnit_Framework_TestCase
runTestInSeparateProcess boolean Whether or not this test is to be run in a separate PHP process. PHPUnit_Framework_TestCase

Public Methods

Hide inherited methods

MethodDescriptionDefined By
__construct() Constructs a test case with the given name. PHPUnit_Framework_TestCase
addToAssertionCount() Adds a value to the assertion counter. PHPUnit_Framework_TestCase
any() Returns a matcher that matches when the method it is evaluated for 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
assertAttributeCount() Asserts the number of elements of an array, Countable or Iterator PHPUnit_Framework_Assert
assertAttributeEmpty() Asserts that a static attribute of a class or an attribute of an object 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
assertAttributeInstanceOf() Asserts that an attribute is of a given type. PHPUnit_Framework_Assert
assertAttributeInternalType() Asserts that an attribute is of a given type. 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
assertAttributeNotCount() Asserts the number of elements of an array, Countable or Iterator PHPUnit_Framework_Assert
assertAttributeNotEmpty() Asserts that a static attribute of a class or an attribute of an object PHPUnit_Framework_Assert
assertAttributeNotEquals() Asserts that a variable is not equal to an attribute of an object. PHPUnit_Framework_Assert
assertAttributeNotInstanceOf() Asserts that an attribute is of a given type. PHPUnit_Framework_Assert
assertAttributeNotInternalType() Asserts that an attribute is of a given type. PHPUnit_Framework_Assert
assertAttributeNotSame() Asserts that a variable and an attribute of an object do not have the PHPUnit_Framework_Assert
assertAttributeSame() Asserts that a variable and an attribute of an object have the same 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
assertContainsOnlyInstancesOf() Asserts that a haystack contains only instances of a given classname PHPUnit_Framework_Assert
assertCount() Asserts the number of elements of an array, Countable or Iterator. PHPUnit_Framework_Assert
assertEmpty() Asserts that a variable is empty. PHPUnit_Framework_Assert
assertEqualXMLStructure() Asserts that a hierarchy of DOMElements 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
assertInstanceOf() Asserts that a variable is of a given type. PHPUnit_Framework_Assert
assertInternalType() Asserts that a variable is of a given type. PHPUnit_Framework_Assert
assertJson() Asserts that a string is a valid JSON string. PHPUnit_Framework_Assert
assertJsonFileEqualsJsonFile() Asserts that two JSON files are equal. PHPUnit_Framework_Assert
assertJsonFileNotEqualsJsonFile() Asserts that two JSON files are not equal. PHPUnit_Framework_Assert
assertJsonStringEqualsJsonFile() Asserts that the generated JSON encoded object and the content of the given file are equal. PHPUnit_Framework_Assert
assertJsonStringEqualsJsonString() Asserts that two given JSON encoded objects or arrays are equal. PHPUnit_Framework_Assert
assertJsonStringNotEqualsJsonFile() Asserts that the generated JSON encoded object and the content of the given file are not equal. PHPUnit_Framework_Assert
assertJsonStringNotEqualsJsonString() Asserts that two given JSON encoded objects or arrays are not equal. 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
assertNotCount() Asserts the number of elements of an array, Countable or Iterator. PHPUnit_Framework_Assert
assertNotEmpty() Asserts that a variable is not empty. PHPUnit_Framework_Assert
assertNotEquals() Asserts that two variables are not equal. PHPUnit_Framework_Assert
assertNotInstanceOf() Asserts that a variable is not of a given type. PHPUnit_Framework_Assert
assertNotInternalType() Asserts that a variable is not of a given type. 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
assertNotSameSize() Assert that the size of two arrays (or `Countable` or `Iterator` objects) PHPUnit_Framework_Assert
assertNotTag() This assertion is the exact opposite of assertTag(). 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
assertSameSize() Assert that the size of two arrays (or `Countable` or `Iterator` objects) 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 suffix. PHPUnit_Framework_Assert
assertStringEndsWith() Asserts that a string ends with a given suffix. PHPUnit_Framework_Assert
assertStringEqualsFile() Asserts that the contents of a string is equal PHPUnit_Framework_Assert
assertStringMatchesFormat() Asserts that a string matches a given format string. PHPUnit_Framework_Assert
assertStringMatchesFormatFile() Asserts that a string matches a given format file. PHPUnit_Framework_Assert
assertStringNotEqualsFile() Asserts that the contents of a string is not equal PHPUnit_Framework_Assert
assertStringNotMatchesFormat() Asserts that a string does not match a given format string. PHPUnit_Framework_Assert
assertStringNotMatchesFormatFile() Asserts that a string does not match a given format string. 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
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
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
attribute() Returns a PHPUnit_Framework_Constraint_Attribute matcher object. PHPUnit_Framework_Assert
attributeEqualTo() Returns a PHPUnit_Framework_Constraint_IsEqual matcher object PHPUnit_Framework_Assert
callback() Returns a PHPUnit_Framework_Constraint_Callback 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
containsOnlyInstancesOf() 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
exactly() Returns a matcher that matches when the method it is evaluated for PHPUnit_Framework_TestCase
expectOutputRegex() PHPUnit_Framework_TestCase
expectOutputString() PHPUnit_Framework_TestCase
fail() Fails a test with the given message. PHPUnit_Framework_Assert
fileExists() Returns a PHPUnit_Framework_Constraint_FileExists matcher object. PHPUnit_Framework_Assert
getActualOutput() PHPUnit_Framework_TestCase
getAnnotations() Returns the annotations for this test. PHPUnit_Framework_TestCase
getCount() Return the current assertion count. PHPUnit_Framework_Assert
getExpectedException() PHPUnit_Framework_TestCase
getMock() Returns a mock object for the specified class. PHPUnit_Framework_TestCase
getMockBuilder() Returns a builder object to create mock objects using a fluent interface. PHPUnit_Framework_TestCase
getMockForAbstractClass() Returns a mock object for the specified abstract class with all abstract PHPUnit_Framework_TestCase
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
getSize() Returns the size of the test. PHPUnit_Framework_TestCase
getStatus() Returns the status of this test. PHPUnit_Framework_TestCase
getStatusMessage() Returns the status message of this test. PHPUnit_Framework_TestCase
getTestResultObject() 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
hasOutput() PHPUnit_Framework_TestCase
hasPerformedExpectationsOnOutput() PHPUnit_Framework_TestCase
identicalTo() Returns a PHPUnit_Framework_Constraint_IsIdentical matcher object. PHPUnit_Framework_Assert
isEmpty() Returns a PHPUnit_Framework_Constraint_IsEmpty 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
isJson() Returns a PHPUnit_Framework_Constraint_IsJson 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
matches() Returns a PHPUnit_Framework_Constraint_StringMatches matcher object. PHPUnit_Framework_Assert
matchesRegularExpression() Returns a PHPUnit_Framework_Constraint_PCREMatch matcher object. PHPUnit_Framework_Assert
never() Returns a matcher that matches when the method it is evaluated for PHPUnit_Framework_TestCase
objectHasAttribute() Returns a PHPUnit_Framework_Constraint_ObjectHasAttribute matcher object. PHPUnit_Framework_Assert
onConsecutiveCalls() PHPUnit_Framework_TestCase
once() Returns a matcher that matches when the method it is evaluated for PHPUnit_Framework_TestCase
readAttribute() Returns the value of an attribute of a class or an object. PHPUnit_Framework_Assert
resetCount() Reset the assertion counter. PHPUnit_Framework_Assert
returnArgument() PHPUnit_Framework_TestCase
returnCallback() PHPUnit_Framework_TestCase
returnSelf() Returns the current object. PHPUnit_Framework_TestCase
returnValue() PHPUnit_Framework_TestCase
returnValueMap() PHPUnit_Framework_TestCase
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() Sets PHPUnit_Framework_TestCase
setInIsolation() Sets PHPUnit_Framework_TestCase
setName() Sets the name of a TestCase. PHPUnit_Framework_TestCase
setOutputCallback() Sets PHPUnit_Framework_TestCase
setPreserveGlobalState() Sets PHPUnit_Framework_TestCase
setResult() Sets PHPUnit_Framework_TestCase
setRunTestInSeparateProcess() Sets PHPUnit_Framework_TestCase
setTestResultObject() Sets PHPUnit_Framework_TestCase
setUpBeforeClass() This method is called before the first test of this test class is run. PHPUnit_Framework_TestCase
setUseErrorHandler() Sets PHPUnit_Framework_TestCase
setUseOutputBuffering() Sets 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
throwException() PHPUnit_Framework_TestCase
toString() Returns a string representation of the test case. PHPUnit_Framework_TestCase

Protected Methods

Hide inherited methods

MethodDescriptionDefined By
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
checkRequirements() PHPUnit_Framework_TestCase
createResult() Creates a default TestResult object. PHPUnit_Framework_TestCase
dataToString() PHPUnit_Framework_TestCase
getDataSetAsString() Gets the data set description of a TestCase. PHPUnit_Framework_TestCase
getMockClass() Mocks the specified class and returns the name of the mocked class. PHPUnit_Framework_TestCase
getMockFromWsdl() Returns a mock object based on the given WSDL file. PHPUnit_Framework_TestCase
getObjectForTrait() Returns an object for the specified trait. PHPUnit_Framework_TestCase
handleDependencies() PHPUnit_Framework_TestCase
iniSet() This method is a wrapper for the ini_set() function that automatically PHPUnit_Framework_TestCase
onNotSuccessfulTest() This method is called when a test method did not execute successfully. PHPUnit_Framework_TestCase
prepareTemplate() Performs custom preparations on the process isolation template. 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
setRequirementsFromAnnotation() PHPUnit_Framework_TestCase
setUp() Sets up the fixture, for example, open a network connection. PHPUnit_Framework_TestCase
setUseErrorHandlerFromAnnotation() PHPUnit_Framework_TestCase
setUseOutputBufferingFromAnnotation() PHPUnit_Framework_TestCase
tearDown() Tears down the fixture, for example, close a network connection. PHPUnit_Framework_TestCase
verifyMockObjects() Verifies the mock object expectations. PHPUnit_Framework_TestCase

Total 1 comment

#5802 report it
pligor at 2011/11/14 03:44pm
unit tests related

Since you are probably already writing simple tests for class methods here is a small snippet of code to use in your tests. The convetion is that you name your simple tests after the method that you are testing. So you have function methodName() { ... } and the corresponding test is named testMethodName() { .. } The second convetion is that the test class is named with test appended to original class name. so class ClassName { ..... } and the test class is named class ClassNameTest extends CDbTestCase { .... }

So..

$func = lcfirst( substr(__FUNCTION__, strlen('test')) );
$class = substr(__CLASS__, 0, -strlen('test'));
$model = new $class();
$function = array($model, $func);

and for seemingly for static methods:

$func = lcfirst( substr(__FUNCTION__, strlen('test')) );
$class = substr(__CLASS__, 0, -strlen('test'));
$function = array($class, $func);

Afterwards you simply use the php function:

$returnVal = call_user_func($function,$param1,$param2,..);

Leave a comment

Please to leave your comment.