Class SimpleTestCase

Description

Basic test case. This is the smallest unit of a test suite. It searches for all methods that start with the the string "test" and runs them. Working test cases extend this class.

Located in /libraries/pear/simpletest/simple_test.php (line 244)


	
			
Direct descendents
Class Description
 class PHPUnit_TestCase Adapter for PEAR PHPUnit test case to allow legacy PEAR test cases to be used with SimpleTest.
 class TestCase Adapter for sourceforge PHPUnit test case to allow legacy test cases to be used with SimpleTest.
 class ShellTestCase Test case for testing of command line scripts and utilities. Usually scripts taht are external to the PHP code, but support it in some way.
 class WebTestCase Test case for testing of web pages. Allows fetching of pages, parsing of HTML and submitting forms.
 class UnitTestCase Standard unit test class for day to day testing of PHP code XP style. Adds some useful standard assertions.
Variable Summary
 mixed $_label
 mixed $_runner
Method Summary
 SimpleTestCase SimpleTestCase ([string $label = false])
 void after ()
 boolean assertExpectation (SimpleExpectation &$expectation, mixed $test_value, [string $message = '%s'])
 boolean assertFalse (boolean $result, [string $message = false])
 boolean assertTrue (boolean $result, [string $message = false])
 void before ()
 mixed dump (mixed $variable, [string $message = false])
 void error (integer $severity, string $message, string $file, integer $line, hash $globals)
 void fail ([string $message = "Fail"])
 string getAssertionLine ([string $format = '%d'], [array $stack = false])
 string getLabel ()
 integer getSize ()
 void pass ([string $message = "Pass"])
 void run (SimpleReporter &$reporter)
 void sendMessage (string $message)
 void setUp ()
 void signal (string $type, mixed &$payload)
 void swallowErrors ()
 void tearDown ()
Variables
mixed $_label (line 245)
mixed $_runner (line 246)
Methods
Constructor SimpleTestCase (line 254)

Sets up the test with no display.

  • access: public
SimpleTestCase SimpleTestCase ([string $label = false])
  • string $label: If no test name is given then the class name is used.
after (line 308)

Runs test case specific code after the user tearDown().

For extension writers not wanting to interfere with user tests.

  • access: protected
void after ()
assertExpectation (line 393)

Runs an expectation directly, for extending the tests with new expectation classes.

  • return: True on pass
  • access: public
boolean assertExpectation (SimpleExpectation &$expectation, mixed $test_value, [string $message = '%s'])
  • SimpleExpectation $expectation: Expectation subclass.
  • mixed $test_value: Value to compare.
  • string $message: Message to display.
assertFalse (line 431)

Will be true on false and vice versa. False is the PHP definition of false, so that null, empty strings, zero and an empty array all count as false.

  • return: True on pass
  • access: public
boolean assertFalse (boolean $result, [string $message = false])
  • boolean $result: Pass on false.
  • string $message: Message to display.

Redefined in descendants as:
assertTrue (line 408)

Called from within the test methods to register passes and failures.

  • return: True on pass
  • access: public
boolean assertTrue (boolean $result, [string $message = false])
  • boolean $result: Pass on true.
  • string $message: Message to display describing the test state.

Redefined in descendants as:
before (line 300)

Runs test case specific code before the user setUp().

For extension writers not wanting to interfere with setUp().

  • access: protected
void before ()

Redefined in descendants as:
dump (line 464)

Sends a formatted dump of a variable to the test suite for those emergency debugging situations.

  • return: The original variable.
  • access: public
mixed dump (mixed $variable, [string $message = false])
  • mixed $variable: Variable to display.
  • string $message: Message to display.
error (line 356)

Formats a PHP error and dispatches it to the runner.

  • access: public
void error (integer $severity, string $message, string $file, integer $line, hash $globals)
  • integer $severity: PHP error code.
  • string $message: Text of error.
  • string $file: File error occoured in.
  • integer $line: Line number of error.
  • hash $globals: PHP super global arrays.

Redefined in descendants as:
  • TestCase::error() : Sends an error which we interpret as a fail with a different message for compatibility.
fail (line 342)

Sends a fail event with a message.

  • access: public
void fail ([string $message = "Fail"])
  • string $message: Message to send.
getAssertionLine (line 448)

Uses a stack trace to find the line of an assertion.

  • return: Line number of first assert* method embedded in format string.
  • access: public
string getAssertionLine ([string $format = '%d'], [array $stack = false])
  • string $format: String formatting.
  • array $stack: Stack frames top most first. Only needed if not using the PHP backtrace function.
getLabel (line 265)

Accessor for the test name for subclasses.

  • return: Name of the test.
  • static:
  • access: public
string getLabel ()
getSize (line 489)

Accessor for the number of subtests.

  • return: Number of test cases.
  • static:
  • access: public
integer getSize ()
pass (line 333)

Sends a pass event with a message.

  • access: public
void pass ([string $message = "Pass"])
  • string $message: Message to send.
run (line 287)

Uses reflection to run every method within itself starting with the string "test".

  • access: public
void run (SimpleReporter &$reporter)
sendMessage (line 479)

Dispatches a text message straight to the test suite. Useful for status bar displays.

  • access: public
void sendMessage (string $message)
  • string $message: Message to show.
signal (line 371)

Sends a user defined event to the test runner.

This is for small scale extension where both the test case and either the runner or display are subclassed.

  • access: public
void signal (string $type, mixed &$payload)
  • string $type: Type of event.
  • mixed $payload: Object or message to deliver.
swallowErrors (line 379)

Cancels any outstanding errors.

  • access: public
void swallowErrors ()
tearDown (line 325)

Clears the data set in the setUp() method call.

To be overridden by the user in actual user test cases.

  • access: public
void tearDown ()

Redefined in descendants as:
_createRunner (line 277)

Can modify the incoming reporter so as to run the tests differently. This version simply passes it straight through.

  • access: protected
SimpleReporter &_createRunner (SimpleReporter &$reporter)

Documentation generated on Fri, 11 Feb 2005 18:14:05 +0000 by phpDocumentor 1.3.0RC3