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 73)

RunnableTest
   |
   --SimpleTestCase
Direct descendents
Class Description
 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 TestCase Adapter for sourceforge PHPUnit test case to allow legacy test cases to be used with SimpleTest.
 class PHPUnit_TestCase Adapter for PEAR PHPUnit test case to allow legacy PEAR test cases to be used with SimpleTest.
 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 $_reporter
Method Summary
 SimpleTestCase SimpleTestCase ([string $label = false])
 void assertExpectation (SimpleExpectation &$expectation, mixed $test_value, [string $message = '%s'])
 void assertFalse (boolean $result, [string $message = false])
 void assertTrue (boolean $result, [string $message = false])
 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])
 void invoke (string $method)
 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 ()
 boolean _isConstructor (string $method)
 boolean _isTest (string $method)
Variables
mixed $_reporter (line 74)

Inherited Variables

Inherited from RunnableTest

RunnableTest::$_label
Methods
Constructor SimpleTestCase (line 82)

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.
assertExpectation (line 250)

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

  • access: public
void 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 284)

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.

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

Redefined in descendants as:
assertTrue (line 264)

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

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

Redefined in descendants as:
dump (line 317)

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 214)

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 200)

Sends a fail event with a message.

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

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.
invoke (line 157)

Invokes a test method and dispatches any untrapped errors. Called back from the visiting runner.

  • access: public
void invoke (string $method)
  • string $method: Test method to call.

Redefined in descendants as:
pass (line 191)

Sends a pass event with a message.

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

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

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

Redefinition of:
RunnableTest::run()
Runs the top level test for this class.
sendMessage (line 332)

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 229)

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 237)

Cancels any outstanding errors.

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

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 98)

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)
_isConstructor (line 134)

Tests to see if the method is the constructor and so should be ignored.

  • return: True if constructor.
  • access: protected
boolean _isConstructor (string $method)
  • string $method: Method name to try.
_isTest (line 146)

Tests to see if the method is a test that should be run. Currently any method that starts with 'test' is a candidate.

  • return: True if test method.
  • access: protected
boolean _isTest (string $method)
  • string $method: Method name to try.

Inherited Methods

Inherited From RunnableTest

 RunnableTest::RunnableTest()
 RunnableTest::getLabel()
 RunnableTest::getSize()
 RunnableTest::run()

Documentation generated on Thu, 20 Jan 2005 17:10:55 +0000 by phpDocumentor 1.3.0RC3