Source for file pear_test_case.php

Documentation is available at pear_test_case.php

  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 1388 2006-11-10 20:59:59Z lastcraft $
  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.          *    Adapter for PEAR PHPUnit test case to allow
  19.      *    legacy PEAR test cases to be used with SimpleTest.
  20.      *    @package      SimpleTest
  21.      *    @subpackage   Extensions
  22.      */
  23.     class PHPUnit_TestCase extends SimpleTestCase {
  24.         var $_loosely_typed;
  25.         
  26.         /**
  27.          *    Constructor. Sets the test name.
  28.          *    @param $label        Test name to display.
  29.          *    @public
  30.          */
  31.         function PHPUnit_TestCase($label false{
  32.             $this->SimpleTestCase($label);
  33.             $this->_loosely_typed = false;
  34.         }
  35.         
  36.         /**
  37.          *    Will test straight equality if set to loose
  38.          *    typing, or identity if not.
  39.          *    @param $first          First value.
  40.          *    @param $second         Comparison value.
  41.          *    @param $message        Message to display.
  42.          *    @public
  43.          */
  44.         function assertEquals($first$second$message "%s"$delta 0{
  45.             if ($this->_loosely_typed{
  46.                 $expectation &new EqualExpectation($first);
  47.             else {
  48.                 $expectation &new IdenticalExpectation($first);
  49.             }
  50.             $this->assert($expectation$second$message);
  51.         }
  52.         
  53.         /**
  54.          *    Passes if the value tested is not null.
  55.          *    @param $value          Value to test against.
  56.          *    @param $message        Message to display.
  57.          *    @public
  58.          */
  59.         function assertNotNull($value$message "%s"{
  60.             parent::assert(new TrueExpectation()isset($value)$message);
  61.         }
  62.         
  63.         /**
  64.          *    Passes if the value tested is null.
  65.          *    @param $value          Value to test against.
  66.          *    @param $message        Message to display.
  67.          *    @public
  68.          */
  69.         function assertNull($value$message "%s"{
  70.             parent::assert(new TrueExpectation()!isset($value)$message);
  71.         }
  72.         
  73.         /**
  74.          *    In PHP5 the identity test tests for the same
  75.          *    object. This is a reference test in PHP4.
  76.          *    @param $first          First object handle.
  77.          *    @param $second         Hopefully the same handle.
  78.          *    @param $message        Message to display.
  79.          *    @public
  80.          */
  81.         function assertSame(&$first&$second$message "%s"{
  82.             $dumper &new SimpleDumper();
  83.             $message sprintf(
  84.                     $message,
  85.                     "[" $dumper->describeValue($first.
  86.                             "] and [" $dumper->describeValue($second.
  87.                             "] should reference the same object");
  88.             return $this->assert(
  89.                     new TrueExpectation(),
  90.                     SimpleTestCompatibility::isReference($first$second),
  91.                     $message);
  92.         }
  93.         
  94.         /**
  95.          *    In PHP5 the identity test tests for the same
  96.          *    object. This is a reference test in PHP4.
  97.          *    @param $first          First object handle.
  98.          *    @param $second         Hopefully a different handle.
  99.          *    @param $message        Message to display.
  100.          *    @public
  101.          */
  102.         function assertNotSame(&$first&$second$message "%s"{
  103.             $dumper &new SimpleDumper();
  104.             $message sprintf(
  105.                     $message,
  106.                     "[" $dumper->describeValue($first.
  107.                             "] and [" $dumper->describeValue($second.
  108.                             "] should not be the same object");
  109.             return $this->assert(
  110.                     new falseExpectation(),
  111.                     SimpleTestCompatibility::isReference($first$second),
  112.                     $message);
  113.         }
  114.         
  115.         /**
  116.          *    Sends pass if the test condition resolves true,
  117.          *    a fail otherwise.
  118.          *    @param $condition      Condition to test true.
  119.          *    @param $message        Message to display.
  120.          *    @public
  121.          */
  122.         function assertTrue($condition$message "%s"{
  123.             parent::assert(new TrueExpectation()$condition$message);
  124.         }
  125.         
  126.         /**
  127.          *    Sends pass if the test condition resolves false,
  128.          *    a fail otherwise.
  129.          *    @param $condition      Condition to test false.
  130.          *    @param $message        Message to display.
  131.          *    @public
  132.          */
  133.         function assertFalse($condition$message "%s"{
  134.             parent::assert(new FalseExpectation()$condition$message);
  135.         }
  136.         
  137.         /**
  138.          *    Tests a regex match. Needs refactoring.
  139.          *    @param $pattern        Regex to match.
  140.          *    @param $subject        String to search in.
  141.          *    @param $message        Message to display.
  142.          *    @public
  143.          */
  144.         function assertRegExp($pattern$subject$message "%s"{
  145.             $this->assert(new PatternExpectation($pattern)$subject$message);
  146.         }
  147.         
  148.         /**
  149.          *    Tests the type of a value.
  150.          *    @param $value          Value to take type of.
  151.          *    @param $type           Hoped for type.
  152.          *    @param $message        Message to display.
  153.          *    @public
  154.          */
  155.         function assertType($value$type$message "%s"{
  156.             parent::assert(new TrueExpectation()gettype($value== strtolower($type)$message);
  157.         }
  158.         
  159.         /**
  160.          *    Sets equality operation to act as a simple equal
  161.          *    comparison only, allowing a broader range of
  162.          *    matches.
  163.          *    @param $loosely_typed     True for broader comparison.
  164.          *    @public
  165.          */
  166.         function setLooselyTyped($loosely_typed{
  167.             $this->_loosely_typed = $loosely_typed;
  168.         }
  169.  
  170.         /**
  171.          *    For progress indication during
  172.          *    a test amongst other things.
  173.          *    @return            Usually one.
  174.          *    @public
  175.          */
  176.         function countTestCases({
  177.             return $this->getSize();
  178.         }
  179.         
  180.         /**
  181.          *    Accessor for name, normally just the class
  182.          *    name.
  183.          *    @public
  184.          */
  185.         function getName({
  186.             return $this->getLabel();
  187.         }
  188.         
  189.         /**
  190.          *    Does nothing. For compatibility only.
  191.          *    @param $name        Dummy
  192.          *    @public
  193.          */
  194.         function setName($name{
  195.         }
  196.     }
  197. ?>

Documentation generated on Sun, 04 May 2008 09:21:56 -0500 by phpDocumentor 1.3.0