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 /test_case.php (line 42)


	
			
Direct descendents
Class Description
 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 ShellTestCase Test case for testing of command line scripts and utilities. Usually scripts that 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 $_observers
 mixed $_reporter
Method Summary
 static integer getSize ()
 SimpleTestCase SimpleTestCase ([string $label = false])
 void after (string $method)
 boolean assert ( &$expectation, mixed $compare, [string $message = '%s'], SimpleExpectation $expectation)
 void assertExpectation ( &$expectation,  $compare, [ $message = '%s'])
 void before (string $method)
 mixed dump (mixed $variable, [string $message = false])
 void error (integer $severity, string $message, string $file, integer $line)
 void exception (Exception $exception)
 void fail ([string $message = "Fail"])
 string getAssertionLine ()
 string getLabel ()
 array getTests ()
 void pass ([ $message = "Pass"])
 boolean run ( &$reporter, SimpleReporter $reporter)
 void sendMessage ( $message)
 void setUp ()
 void signal ( $type,  &$payload)
 void skip ()
 void skipIf (string $should_skip, [string $message = '%s'])
 void skipUnless (string $shouldnt_skip, [string $message = false])
 void tearDown ()
 void tell ( &$observer, object $observer)
 boolean _isTest (string $method)
Variables
mixed $_label = false (line 43)
mixed $_observers (line 45)
mixed $_reporter (line 44)
mixed $_should_skip = false (line 46)
Methods
static getSize (line 370)

Accessor for the number of subtests including myelf.

  • return: Number of test cases.
  • access: public
static integer getSize ()
Constructor SimpleTestCase (line 54)

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

Announces the end of the test. Includes private clean up.

  • access: public
void after (string $method)
  • string $method: Test method just finished.

Redefined in descendants as:
assert (line 308)

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

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

Redefined in descendants as:
assertExpectation (line 323)
  • deprecated:
void assertExpectation ( &$expectation,  $compare, [ $message = '%s'])
  • &$expectation
  • $compare
  • $message
before (line 192)

Announces the start of the test.

  • access: public
void before (string $method)
  • string $method: Test method just started.

Redefined in descendants as:
createInvoker (line 109)

Used to invoke the single tests.

  • return: Individual test runner.
  • access: public
SimpleInvoker &createInvoker ()
dump (line 347)

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

Formats a PHP error and dispatches it to the reporter.

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

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

Formats an exception and dispatches it to the reporter.

  • access: public
void exception (Exception $exception)
  • Exception $exception: Object thrown.
fail (line 253)

Sends a fail event with a message.

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

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

Redefined in descendants as:
getLabel (line 65)

Accessor for the test name for subclasses.

  • return: Name of the test.
  • access: public
string getLabel ()
getTests (line 162)

Gets a list of test names. Normally that will be all internal methods that start with the name "test". This method should be overridden if you want a different rule.

  • return: List of test names.
  • access: public
array getTests ()
pass (line 239)
  • deprecated:
void pass ([ $message = "Pass"])
  • $message
run (line 125)

Uses reflection to run every method within itself starting with the string "test" unless a method is specified.

  • return: True if all tests passed.
  • access: public
boolean run ( &$reporter, SimpleReporter $reporter)
sendMessage (line 360)
  • deprecated:
void sendMessage ( $message)
  • $message
setUp (line 203)

Sets up unit test wide variables at the start of each test method. To be overridden in actual user test cases.

  • access: public
void setUp ()

Redefined in descendants as:
signal (line 292)
  • deprecated:
void signal ( $type,  &$payload)
  • $type
  • &$payload
skip (line 75)

This is a placeholder for skipping tests. In this method you place skipIf() and skipUnless() calls to set the skipping state.

  • access: public
void skip ()
skipIf (line 85)

Will issue a message to the reporter and tell the test case to skip if the incoming flag is true.

  • access: public
void skipIf (string $should_skip, [string $message = '%s'])
  • string $should_skip: Condition causing the tests to be skipped.
  • string $message: Text of skip condition.
skipUnless (line 100)

Will issue a message to the reporter and tell the test case to skip if the incoming flag is false.

  • access: public
void skipUnless (string $shouldnt_skip, [string $message = false])
  • string $shouldnt_skip: Condition causing the tests to be run.
  • string $message: Text of skip condition.
tearDown (line 211)

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:
tell (line 232)

Sets up an observer for the test end.

  • access: public
void tell ( &$observer, object $observer)
  • object $observer: Must have atTestEnd() method.
  • &$observer
_isTest (line 180)

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

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

Documentation generated on Sun, 04 May 2008 09:22:18 -0500 by phpDocumentor 1.3.0