Class UnitTestCase

Description

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

Located in /unit_tester.php (line 23)

SimpleTestCase
   |
   --UnitTestCase
Direct descendents
Class Description
 class SeleniumTestCase Provides test case wrapper to a Selenium remote control instance.
 class SeleneseTestCase SeleneseTestCase
Method Summary
 UnitTestCase __construct ([string $label = false])
 boolean assertClone (mixed $first, mixed $second, [string $message = '%s'])
 boolean assertCopy ( &$first,  &$second, [string $message = "%s"], mixed $first, mixed $second)
 boolean assertEqual (mixed $first, mixed $second, [string $message = '%s'])
 boolean assertFalse (boolean $result, [string $message = '%s'])
 boolean assertIdentical (mixed $first, mixed $second, [string $message = '%s'])
 boolean assertIsA (mixed $object, string $type, [string $message = '%s'])
 boolean assertNoPattern (string $pattern, string $subject, [string $message = '%s'])
 boolean assertNotA (mixed $object, string $type, [string $message = '%s'])
 boolean assertNotEqual (mixed $first, mixed $second, [string $message = '%s'])
 boolean assertNotIdentical (mixed $first, mixed $second, [string $message = '%s'])
 boolean assertNotNull (mixed $value, [string $message = '%s'])
 boolean assertNull (null $value, [string $message = '%s'])
 boolean assertOutsideMargin (mixed $first, mixed $second, mixed $margin, [string $message = '%s'])
 boolean assertPattern (string $pattern, string $subject, [string $message = '%s'])
 boolean assertReference ( &$first,  &$second, [string $message = '%s'], mixed $first, mixed $second)
 boolean assertSame (mixed $first, mixed $second, [string $message = '%s'])
 boolean assertTrue (boolean $result, [string $message = '%s'])
 boolean assertWithinMargin (mixed $first, mixed $second, mixed $margin, [string $message = '%s'])
 void expectError ([SimpleExpectation/string $expected = false], [string $message = '%s'])
 void expectException ([SimpleExpectation/Exception $expected = false], [string $message = '%s'])
 void ignoreException ([SimpleExpectation/Exception $ignored = false])
Variables

Inherited Variables

Inherited from SimpleTestCase

SimpleTestCase::$reporter
Methods
Constructor __construct (line 32)

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

  • access: public
UnitTestCase __construct ([string $label = false])
  • string $label: Name of test case. Will use the class name if none specified.

Redefinition of:
SimpleTestCase::__construct()
Sets up the test with no display.

Redefined in descendants as:
assertClone (line 285)

Will trigger a pass if both parameters refer to different objects. Fail otherwise. The objects have to be identical though.

  • return: True on pass
  • access: public
boolean assertClone (mixed $first, mixed $second, [string $message = '%s'])
  • mixed $first: Object reference to check.
  • mixed $second: Hopefully not the same object.
  • string $message: Message to display.
assertCopy (line 310)

Will trigger a pass if both parameters refer to different variables. Fail otherwise. The objects have to be identical references though.

This will fail under E_STRICT with objects. Use assertClone() for this.

  • return: True on pass
  • access: public
boolean assertCopy ( &$first,  &$second, [string $message = "%s"], mixed $first, mixed $second)
  • mixed $first: Object reference to check.
  • mixed $second: Hopefully not the same object.
  • string $message: Message to display.
  • &$first
  • &$second
assertEqual (line 139)

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

  • return: True on pass
  • access: public
boolean assertEqual (mixed $first, mixed $second, [string $message = '%s'])
  • mixed $first: Value to compare.
  • mixed $second: Value to compare.
  • string $message: Message to display.
assertFalse (line 62)

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 = '%s'])
  • boolean $result: Pass on false.
  • string $message: Message to display.
assertIdentical (line 205)

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

  • return: True on pass
  • access: public
boolean assertIdentical (mixed $first, mixed $second, [string $message = '%s'])
  • mixed $first: Value to compare.
  • mixed $second: Value to compare.
  • string $message: Message to display.
assertIsA (line 106)

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.

  • return: True on pass.
  • access: public
boolean assertIsA (mixed $object, string $type, [string $message = '%s'])
  • mixed $object: Object to test.
  • string $type: Type name as string.
  • string $message: Message to display.
assertNoPattern (line 349)

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

  • return: True on pass
  • access: public
boolean assertNoPattern (string $pattern, string $subject, [string $message = '%s'])
  • string $pattern: Perl regex to look for including the regex delimiters.
  • string $subject: String to search in.
  • string $message: Message to display.
assertNotA (line 123)

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

  • return: True on pass.
  • access: public
boolean assertNotA (mixed $object, string $type, [string $message = '%s'])
  • mixed $object: Object to test.
  • string $type: Type name as string.
  • string $message: Message to display.
assertNotEqual (line 155)

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

  • return: True on pass
  • access: public
boolean assertNotEqual (mixed $first, mixed $second, [string $message = '%s'])
  • mixed $first: Value to compare.
  • mixed $second: Value to compare.
  • string $message: Message to display.
assertNotIdentical (line 221)

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

  • return: True on pass
  • access: public
boolean assertNotIdentical (mixed $first, mixed $second, [string $message = '%s'])
  • mixed $first: Value to compare.
  • mixed $second: Value to compare.
  • string $message: Message to display.
assertNotNull (line 88)

Will be true if the value is set.

  • return: True on pass.
  • access: public
boolean assertNotNull (mixed $value, [string $message = '%s'])
  • mixed $value: Supposedly set value.
  • string $message: Message to display.
assertNull (line 73)

Will be true if the value is null.

  • return: True on pass
  • access: public
boolean assertNull (null $value, [string $message = '%s'])
  • null $value: Supposedly null value.
  • string $message: Message to display.
assertOutsideMargin (line 189)

Will trigger a pass if the two parameters differ by more than the margin.

  • return: True on pass
  • access: public
boolean assertOutsideMargin (mixed $first, mixed $second, mixed $margin, [string $message = '%s'])
  • mixed $first: Value to compare.
  • mixed $second: Value to compare.
  • mixed $margin: Fuzziness of match.
  • string $message: Message to display.
assertPattern (line 332)

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

  • return: True on pass
  • access: public
boolean assertPattern (string $pattern, string $subject, [string $message = '%s'])
  • string $pattern: Perl regex to look for including the regex delimiters.
  • string $subject: String to search in.
  • string $message: Message to display.
assertReference (line 240)

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

This will cause problems testing objects under E_STRICT. TODO: Replace with expectation.

  • return: True on pass
  • access: public
boolean assertReference ( &$first,  &$second, [string $message = '%s'], mixed $first, mixed $second)
  • mixed $first: Reference to check.
  • mixed $second: Hopefully the same variable.
  • string $message: Message to display.
  • &$first
  • &$second
assertSame (line 265)

Will trigger a pass if both parameters refer to the same object. Fail otherwise. This has the same semantics at the PHPUnit assertSame.

That is, if values are passed in it has roughly the same affect as assertIdentical. TODO: Replace with expectation.

  • return: True on pass
  • access: public
boolean assertSame (mixed $first, mixed $second, [string $message = '%s'])
  • mixed $first: Object reference to check.
  • mixed $second: Hopefully the same object.
  • string $message: Message to display.
assertTrue (line 48)

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

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

Will trigger a pass if the if the first parameter is near enough to the second by the margin.

  • return: True on pass
  • access: public
boolean assertWithinMargin (mixed $first, mixed $second, mixed $margin, [string $message = '%s'])
  • mixed $first: Value to compare.
  • mixed $second: Value to compare.
  • mixed $margin: Fuzziness of match.
  • string $message: Message to display.
coerceExpectation (line 402)

Creates an equality expectation if the object/value is not already some type of expectation.

  • return: Expectation object.
  • access: protected
SimpleExpectation coerceExpectation (mixed $expected)
  • mixed $expected: Expected value.
expectError (line 364)

Prepares for an error. If the error mismatches it passes through, otherwise it is swallowed. Any left over errors trigger failures.

  • access: public
void expectError ([SimpleExpectation/string $expected = false], [string $message = '%s'])
  • SimpleExpectation/string $expected: The error to match.
  • string $message: Message on failure.
expectException (line 377)

Prepares for an exception. If the error mismatches it passes through, otherwise it is swallowed. Any left over errors trigger failures.

  • access: public
void expectException ([SimpleExpectation/Exception $expected = false], [string $message = '%s'])
  • SimpleExpectation/Exception $expected: The error to match.
  • string $message: Message on failure.
ignoreException (line 390)

Tells SimpleTest to ignore an upcoming exception as not relevant to the current test. It doesn't affect the test, whether thrown or not.

  • access: public
void ignoreException ([SimpleExpectation/Exception $ignored = false])
  • SimpleExpectation/Exception $ignored: The error to ignore.

Inherited Methods

Inherited From SimpleTestCase

 SimpleTestCase::__construct()
 SimpleTestCase::after()
 SimpleTestCase::assert()
 SimpleTestCase::before()
 SimpleTestCase::createInvoker()
 SimpleTestCase::dump()
 SimpleTestCase::error()
 SimpleTestCase::exception()
 SimpleTestCase::fail()
 SimpleTestCase::getAssertionLine()
 SimpleTestCase::getLabel()
 SimpleTestCase::getSize()
 SimpleTestCase::getTests()
 SimpleTestCase::isTest()
 SimpleTestCase::pass()
 SimpleTestCase::run()
 SimpleTestCase::setUp()
 SimpleTestCase::shouldSkip()
 SimpleTestCase::signal()
 SimpleTestCase::skip()
 SimpleTestCase::skipIf()
 SimpleTestCase::skipUnless()
 SimpleTestCase::tearDown()
 SimpleTestCase::tell()

Documentation generated on Sun, 31 Oct 2010 16:32:51 -0500 by phpDocumentor 1.4.3