SimpleTest


SimpleTest\UnitTestCase
unit_tester.php at line 24

Class UnitTestCase

SimpleTestCase
└─UnitTestCase

public class UnitTestCase
extends SimpleTestCase

Standard unit test class for day to day testing of PHP code XP style. Adds some useful standard assertions.

Package SimpleTest.
Subpackage UnitTester.
Package SimpleTest.

Constructor Summary

UnitTestCase(string label)

Creates an empty test case.

Method Summary
boolean

assertCopy(mixed first, mixed second, string message)

Will trigger a pass if both parameters refer to different objects.

boolean

assertEqual(mixed first, mixed second, string message)

Will trigger a pass if the two parameters have the same value only.

boolean

assertError(string expected, string message)

Confirms that an error has occoured and optionally that the error text matches exactly.

boolean

assertErrorPattern(string pattern, string message)

Confirms that an error has occoured and that the error text matches a Perl regular expression.

boolean

assertIdentical(mixed first, mixed second, string message)

Will trigger a pass if the two parameters have the same value and same type.

boolean

assertIsA(mixed object, string type, string message)

Type and class test.

boolean

assertNoErrors(string message)

Confirms that no errors have occoured so far in the test method.

boolean

assertNoUnwantedPattern(string pattern, string subject, string message)

Will trigger a pass if the perl regex pattern is not present in subject.

boolean

assertNotA(mixed object, string type, string message)

Type and class mismatch test.

boolean

assertNotEqual(mixed first, mixed second, string message)

Will trigger a pass if the two parameters have a different value.

boolean

assertNotIdentical(mixed first, mixed second, string message)

Will trigger a pass if the two parameters have the different value or different type.

boolean

assertNotNull(mixed value, string message)

Will be true if the value is set.

boolean

assertNull(null value, string message)

Will be true if the value is null.

boolean

assertReference(mixed first, mixed second, string message)

Will trigger a pass if both parameters refer to the same object.

boolean

assertWantedPattern(string pattern, string subject, string message)

Will trigger a pass if the Perl regex pattern is found in the subject.

Methods inherited from SimpleTest\SimpleTestCase
assertExpectation, assertFalse, assertTrue, createInvoker, dump, error, fail, getAssertionLine, getLabel, getSize, pass, run, sendMessage, setUp, signal, swallowErrors, tearDown

Constructor Detail

unit_tester.php at line 33

UnitTestCase

public UnitTestCase(string label)

Creates an empty test case. Should be subclassed with test methods for a functional test case.

Parameters:
label - Name of test case. Will use the class name if none specified.

Method Detail

unit_tester.php at line 198

assertCopy

public boolean assertCopy(mixed first, mixed second, string message)

Will trigger a pass if both parameters refer to different objects. Fail otherwise.

Parameters:
first - Object reference to check.
second - Hopefully not the same object.
message - Message to display.
Returns:
True on pass

unit_tester.php at line 113

assertEqual

public boolean assertEqual(mixed first, mixed second, string message)

Will trigger a pass if the two parameters have the same value only. Otherwise a fail.

Parameters:
first - Value to compare.
second - Value to compare.
message - Message to display.
Returns:
True on pass

unit_tester.php at line 267

assertError

public boolean assertError(string expected, string message)

Confirms that an error has occoured and optionally that the error text matches exactly.

Parameters:
expected - Expected error text or false for no check.
message - Message to display.
Returns:
True on pass

unit_tester.php at line 290

assertErrorPattern

public boolean assertErrorPattern(string pattern, string message)

Confirms that an error has occoured and that the error text matches a Perl regular expression.

Parameters:
pattern - Perl regular expresion to match against.
message - Message to display.
Returns:
True on pass

unit_tester.php at line 145

assertIdentical

public boolean assertIdentical(mixed first, mixed second, string message)

Will trigger a pass if the two parameters have the same value and same type. Otherwise a fail.

Parameters:
first - Value to compare.
second - Value to compare.
message - Message to display.
Returns:
True on pass

unit_tester.php at line 80

assertIsA

public boolean assertIsA(mixed object, string type, string message)

Type and class test. Will pass if class matches the type name or is a subclass or if not an object, but the type is correct.

Parameters:
object - Object to test.
type - Type name as string.
message - Message to display.
Returns:
True on pass.

unit_tester.php at line 251

assertNoErrors

public boolean assertNoErrors(string message)

Confirms that no errors have occoured so far in the test method.

Parameters:
message - Message to display.
Returns:
True on pass

unit_tester.php at line 237

assertNoUnwantedPattern

public boolean assertNoUnwantedPattern(string pattern, string subject, string message)

Will trigger a pass if the perl regex pattern is not present in subject. Fail if found.

Parameters:
pattern - Perl regex to look for including the regex delimiters.
subject - String to search in.
message - Message to display.
Returns:
True on pass

unit_tester.php at line 97

assertNotA

public boolean assertNotA(mixed object, string type, string message)

Type and class mismatch test. Will pass if class name or underling type does not match the one specified.

Parameters:
object - Object to test.
type - Type name as string.
message - Message to display.
Returns:
True on pass.

unit_tester.php at line 129

assertNotEqual

public boolean assertNotEqual(mixed first, mixed second, string message)

Will trigger a pass if the two parameters have a different value. Otherwise a fail.

Parameters:
first - Value to compare.
second - Value to compare.
message - Message to display.
Returns:
True on pass

unit_tester.php at line 161

assertNotIdentical

public boolean assertNotIdentical(mixed first, mixed second, string message)

Will trigger a pass if the two parameters have the different value or different type.

Parameters:
first - Value to compare.
second - Value to compare.
message - Message to display.
Returns:
True on pass

unit_tester.php at line 62

assertNotNull

public boolean assertNotNull(mixed value, string message)

Will be true if the value is set.

Parameters:
value - Supposedly set value.
message - Message to display.
Returns:
True on pass.

unit_tester.php at line 47

assertNull

public boolean assertNull(null value, string message)

Will be true if the value is null.

Parameters:
value - Supposedly null value.
message - Message to display.
Returns:
True on pass

unit_tester.php at line 177

assertReference

public boolean assertReference(mixed first, mixed second, string message)

Will trigger a pass if both parameters refer to the same object. Fail otherwise.

Parameters:
first - Object reference to check.
second - Hopefully the same object.
message - Message to display.
Returns:
True on pass

unit_tester.php at line 220

assertWantedPattern

public boolean assertWantedPattern(string pattern, string subject, string message)

Will trigger a pass if the Perl regex pattern is found in the subject. Fail otherwise.

Parameters:
pattern - Perl regex to look for including the regex delimiters.
subject - String to search in.
message - Message to display.
Returns:
True on pass

SimpleTest