[ Index ]

PHP Cross Reference of Limb3

title

Body

[close]

/tests_runner/lib/simpletest/extensions/ -> pear_test_case.php (source)

   1  <?php
   2      /**

   3       *    adapter for SimpleTest to use PEAR PHPUnit test cases

   4       *    @package    SimpleTest

   5       *    @subpackage Extensions

   6       *    @version    $Id: pear_test_case.php 5999 2007-06-18 13:13:08Z pachanga $

   7       */
   8      
   9      /**#@+

  10       * include SimpleTest files

  11       */
  12      require_once(dirname(__FILE__) . '/../dumper.php');
  13      require_once(dirname(__FILE__) . '/../compatibility.php');
  14      require_once(dirname(__FILE__) . '/../test_case.php');
  15      require_once(dirname(__FILE__) . '/../expectation.php');
  16      /**#@-*/

  17     
  18      /**

  19       *    Adapter for PEAR PHPUnit test case to allow

  20       *    legacy PEAR test cases to be used with SimpleTest.

  21       *    @package      SimpleTest

  22       *    @subpackage   Extensions

  23       */
  24      class PHPUnit_TestCase extends SimpleTestCase {
  25          var $_loosely_typed;
  26          
  27          /**

  28           *    Constructor. Sets the test name.

  29           *    @param $label        Test name to display.

  30           *    @public

  31           */
  32          function PHPUnit_TestCase($label = false) {
  33              $this->SimpleTestCase($label);
  34              $this->_loosely_typed = false;
  35          }
  36          
  37          /**

  38           *    Will test straight equality if set to loose

  39           *    typing, or identity if not.

  40           *    @param $first          First value.

  41           *    @param $second         Comparison value.

  42           *    @param $message        Message to display.

  43           *    @public

  44           */
  45          function assertEquals($first, $second, $message = "%s", $delta = 0) {
  46              if ($this->_loosely_typed) {
  47                  $expectation = &new EqualExpectation($first);
  48              } else {
  49                  $expectation = &new IdenticalExpectation($first);
  50              }
  51              $this->assert($expectation, $second, $message);
  52          }
  53          
  54          /**

  55           *    Passes if the value tested is not null.

  56           *    @param $value          Value to test against.

  57           *    @param $message        Message to display.

  58           *    @public

  59           */
  60          function assertNotNull($value, $message = "%s") {
  61              parent::assert(new TrueExpectation(), isset($value), $message);
  62          }
  63          
  64          /**

  65           *    Passes if the value tested is null.

  66           *    @param $value          Value to test against.

  67           *    @param $message        Message to display.

  68           *    @public

  69           */
  70          function assertNull($value, $message = "%s") {
  71              parent::assert(new TrueExpectation(), !isset($value), $message);
  72          }
  73          
  74          /**

  75           *    In PHP5 the identity test tests for the same

  76           *    object. This is a reference test in PHP4.

  77           *    @param $first          First object handle.

  78           *    @param $second         Hopefully the same handle.

  79           *    @param $message        Message to display.

  80           *    @public

  81           */
  82          function assertSame(&$first, &$second, $message = "%s") {
  83              $dumper = &new SimpleDumper();
  84              $message = sprintf(
  85                      $message,
  86                      "[" . $dumper->describeValue($first) .
  87                              "] and [" . $dumper->describeValue($second) .
  88                              "] should reference the same object");
  89              return $this->assert(
  90                      new TrueExpectation(),
  91                      SimpleTestCompatibility::isReference($first, $second),
  92                      $message);
  93          }
  94          
  95          /**

  96           *    In PHP5 the identity test tests for the same

  97           *    object. This is a reference test in PHP4.

  98           *    @param $first          First object handle.

  99           *    @param $second         Hopefully a different handle.

 100           *    @param $message        Message to display.

 101           *    @public

 102           */
 103          function assertNotSame(&$first, &$second, $message = "%s") {
 104              $dumper = &new SimpleDumper();
 105              $message = sprintf(
 106                      $message,
 107                      "[" . $dumper->describeValue($first) .
 108                              "] and [" . $dumper->describeValue($second) .
 109                              "] should not be the same object");
 110              return $this->assert(
 111                      new falseExpectation(),
 112                      SimpleTestCompatibility::isReference($first, $second),
 113                      $message);
 114          }
 115          
 116          /**

 117           *    Sends pass if the test condition resolves true,

 118           *    a fail otherwise.

 119           *    @param $condition      Condition to test true.

 120           *    @param $message        Message to display.

 121           *    @public

 122           */
 123          function assertTrue($condition, $message = "%s") {
 124              parent::assert(new TrueExpectation(), $condition, $message);
 125          }
 126          
 127          /**

 128           *    Sends pass if the test condition resolves false,

 129           *    a fail otherwise.

 130           *    @param $condition      Condition to test false.

 131           *    @param $message        Message to display.

 132           *    @public

 133           */
 134          function assertFalse($condition, $message = "%s") {
 135              parent::assert(new FalseExpectation(), $condition, $message);
 136          }
 137          
 138          /**

 139           *    Tests a regex match. Needs refactoring.

 140           *    @param $pattern        Regex to match.

 141           *    @param $subject        String to search in.

 142           *    @param $message        Message to display.

 143           *    @public

 144           */
 145          function assertRegExp($pattern, $subject, $message = "%s") {
 146              $this->assert(new PatternExpectation($pattern), $subject, $message);
 147          }
 148          
 149          /**

 150           *    Tests the type of a value.

 151           *    @param $value          Value to take type of.

 152           *    @param $type           Hoped for type.

 153           *    @param $message        Message to display.

 154           *    @public

 155           */
 156          function assertType($value, $type, $message = "%s") {
 157              parent::assert(new TrueExpectation(), gettype($value) == strtolower($type), $message);
 158          }
 159          
 160          /**

 161           *    Sets equality operation to act as a simple equal

 162           *    comparison only, allowing a broader range of

 163           *    matches.

 164           *    @param $loosely_typed     True for broader comparison.

 165           *    @public

 166           */
 167          function setLooselyTyped($loosely_typed) {
 168              $this->_loosely_typed = $loosely_typed;
 169          }
 170  
 171          /**

 172           *    For progress indication during

 173           *    a test amongst other things.

 174           *    @return            Usually one.

 175           *    @public

 176           */
 177          function countTestCases() {
 178              return $this->getSize();
 179          }
 180          
 181          /**

 182           *    Accessor for name, normally just the class

 183           *    name.

 184           *    @public

 185           */
 186          function getName() {
 187              return $this->getLabel();
 188          }
 189          
 190          /**

 191           *    Does nothing. For compatibility only.

 192           *    @param $name        Dummy

 193           *    @public

 194           */
 195          function setName($name) {
 196          }
 197      }
 198  ?>


Generated: Sat Nov 22 03:48:54 2008 Cross-referenced by PHPXref 0.7