PHP Class SimpleTestCase, simpletest

@package SimpleTest
ファイルを表示 Open project: simpletest/simpletest Class Usage Examples

Protected Properties

Property Type Description
$reporter

Public Methods

Method Description
__construct ( string $label = false ) Sets up the test with no display.
after ( string $method ) Announces the end of the test. Includes private clean up.
assert ( SimpleExpectation $expectation, mixed $compare, string $message = '%s' ) : boolean Runs an expectation directly, for extending the tests with new expectation classes.
before ( string $method ) Announces the start of the test.
createInvoker ( ) : SimpleInvoker Used to invoke the single tests.
dump ( mixed $variable, string $message = false ) : mixed Sends a formatted dump of a variable to the test suite for those emergency debugging situations.
error ( integer $severity, string $message, string $file, integer $line ) Formats a PHP error and dispatches it to the reporter.
exception ( Exception $exception ) Formats an exception and dispatches it to the reporter.
fail ( string $message = 'Fail' ) Sends a fail event with a message.
getAssertionLine ( ) : string Uses a stack trace to find the line of an assertion.
getLabel ( ) : string Accessor for the test name for subclasses.
getSize ( ) : integer Accessor for the number of subtests including myelf.
getTests ( ) : array 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.
pass ( $message = 'Pass' )
run ( SimpleReporter $reporter ) : boolean Uses reflection to run every method within itself starting with the string "test" unless a method is specified.
setUp ( ) Sets up unit test wide variables at the start of each test method.
shouldSkip ( ) Accessor for the private variable $_shoud_skip
signal ( string $type, mixed $payload ) For user defined expansion of the available messages.
skip ( ) This is a placeholder for skipping tests.
skipIf ( string $should_skip, string $message = '%s' ) Will issue a message to the reporter and tell the test case to skip if the incoming flag is true.
skipUnless ( string $shouldnt_skip, string $message = false ) Will issue a message to the reporter and tell the test case to skip if the incoming flag is false.
tearDown ( ) Clears the data set in the setUp() method call.
tell ( object $observer ) Sets up an observer for the test end.

Protected Methods

Method Description
escapePercentageSignsExceptFirst ( string $string ) : string Escapes all percentage signs, except the first.
isTest ( string $method ) : boolean Tests to see if the method is a test that should be run.

Method Details

__construct() public method

Sets up the test with no display.
public __construct ( string $label = false )
$label string If no test name is given then the class name is used.

after() public method

Announces the end of the test. Includes private clean up.
public after ( string $method )
$method string Test method just finished.

assert() public method

Runs an expectation directly, for extending the tests with new expectation classes.
public assert ( SimpleExpectation $expectation, mixed $compare, string $message = '%s' ) : boolean
$expectation SimpleExpectation Expectation subclass.
$compare mixed Value to compare.
$message string Message to display.
return boolean True on pass

before() public method

Announces the start of the test.
public before ( string $method )
$method string Test method just started.

createInvoker() public method

Used to invoke the single tests.
public createInvoker ( ) : SimpleInvoker
return SimpleInvoker Individual test runner.

dump() public method

Sends a formatted dump of a variable to the test suite for those emergency debugging situations.
public dump ( mixed $variable, string $message = false ) : mixed
$variable mixed Variable to display.
$message string Message to display. *
return mixed The original variable.

error() public method

Formats a PHP error and dispatches it to the reporter.
public error ( integer $severity, string $message, string $file, integer $line )
$severity integer PHP error code.
$message string Text of error.
$file string File error occoured in.
$line integer Line number of error.

escapePercentageSignsExceptFirst() protected method

Get the position of the first percentage sign. Skip over escaping, if none is found. Else escape part of string after first percentage sign. Then concat unescaped first part and escaped part.
protected escapePercentageSignsExceptFirst ( string $string ) : string
$string string
return string

exception() public method

Formats an exception and dispatches it to the reporter.
public exception ( Exception $exception )
$exception Exception Object thrown.

fail() public method

Sends a fail event with a message.
public fail ( string $message = 'Fail' )
$message string Message to send.

getAssertionLine() public method

Uses a stack trace to find the line of an assertion.
public getAssertionLine ( ) : string
return string Line number of first assert method embedded in format string.

getLabel() public method

Accessor for the test name for subclasses.
public getLabel ( ) : string
return string Name of the test.

getSize() public method

Accessor for the number of subtests including myelf.
public getSize ( ) : integer
return integer Number of test cases.

getTests() public method

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.
public getTests ( ) : array
return array List of test names.

isTest() protected method

Currently any method that starts with 'test' is a candidate unless it is the constructor.
protected isTest ( string $method ) : boolean
$method string Method name to try.
return boolean True if test method.

pass() public method

Deprecation:
public pass ( $message = 'Pass' )

run() public method

Uses reflection to run every method within itself starting with the string "test" unless a method is specified.
public run ( SimpleReporter $reporter ) : boolean
$reporter SimpleReporter Current test reporter.
return boolean True if all tests passed.

setUp() public method

To be overridden in actual user test cases.
public setUp ( )

shouldSkip() public method

Accessor for the private variable $_shoud_skip
public shouldSkip ( )

signal() public method

For user defined expansion of the available messages.
public signal ( string $type, mixed $payload )
$type string Tag for sorting the signals.
$payload mixed Extra user specific information.

skip() public method

In this method you place skipIf() and skipUnless() calls to set the skipping state.
public skip ( )

skipIf() public method

Will issue a message to the reporter and tell the test case to skip if the incoming flag is true.
public skipIf ( string $should_skip, string $message = '%s' )
$should_skip string Condition causing the tests to be skipped.
$message string Text of skip condition.

skipUnless() public method

Will issue a message to the reporter and tell the test case to skip if the incoming flag is false.
public skipUnless ( string $shouldnt_skip, string $message = false )
$shouldnt_skip string Condition causing the tests to be run.
$message string Text of skip condition.

tearDown() public method

To be overridden by the user in actual user test cases.
public tearDown ( )

tell() public method

Sets up an observer for the test end.
public tell ( object $observer )
$observer object Must have atTestEnd() method.

Property Details

$reporter protected_oe property

protected $reporter