Source for file expectation.php

Documentation is available at expectation.php

  1. <?php
  2. /**
  3.  *    base include file for SimpleTest
  4.  *    @package    SimpleTest
  5.  *    @subpackage    UnitTester
  6.  *    @version    $Id: expectation.php 1723 2008-04-08 00:34:10Z lastcraft $
  7.  */
  8.  
  9. /**#@+
  10.  *    include other SimpleTest class files
  11.  */
  12. require_once(dirname(__FILE__'/dumper.php');
  13. require_once(dirname(__FILE__'/compatibility.php');
  14. /**#@-*/
  15.  
  16.  *    Assertion that can display failure information.
  17.  *    Also includes various helper methods.
  18.  *    @package SimpleTest
  19.  *    @subpackage UnitTester
  20.  *    @abstract
  21.  */
  22.     var $_dumper = false;
  23.     var $_message;
  24.  
  25.     /**
  26.      *    Creates a dumper for displaying values and sets
  27.      *    the test message.
  28.      *    @param string $message    Customised message on failure.
  29.      */
  30.     function SimpleExpectation($message '%s'{
  31.         $this->_message = $message;
  32.     }
  33.  
  34.     /**
  35.      *    Tests the expectation. True if correct.
  36.      *    @param mixed $compare        Comparison value.
  37.      *    @return boolean              True if correct.
  38.      *    @access public
  39.      *    @abstract
  40.      */
  41.     function test($compare{
  42.     }
  43.  
  44.     /**
  45.      *    Returns a human readable test message.
  46.      *    @param mixed $compare      Comparison value.
  47.      *    @return string             Description of success
  48.      *                                or failure.
  49.      *    @access public
  50.      *    @abstract
  51.      */
  52.     function testMessage($compare{
  53.     }
  54.  
  55.     /**
  56.      *    Overlays the generated message onto the stored user
  57.      *    message. An additional message can be interjected.
  58.      *    @param mixed $compare        Comparison value.
  59.      *    @param SimpleDumper $dumper  For formatting the results.
  60.      *    @return string               Description of success
  61.      *                                  or failure.
  62.      *    @access public
  63.      */
  64.     function overlayMessage($compare$dumper{
  65.         $this->_dumper = $dumper;
  66.         return sprintf($this->_message$this->testMessage($compare));
  67.     }
  68.  
  69.     /**
  70.      *    Accessor for the dumper.
  71.      *    @return SimpleDumper    Current value dumper.
  72.      *    @access protected
  73.      */
  74.     function &_getDumper({
  75.         if ($this->_dumper{
  76.             $dumper &new SimpleDumper();
  77.             return $dumper;
  78.         }
  79.         return $this->_dumper;
  80.     }
  81.  
  82.     /**
  83.      *    Test to see if a value is an expectation object.
  84.      *    A useful utility method.
  85.      *    @param mixed $expectation    Hopefully an Epectation
  86.      *                                  class.
  87.      *    @return boolean              True if descended from
  88.      *                                  this class.
  89.      *    @access public
  90.      *    @static
  91.      */
  92.     function isExpectation($expectation{
  93.         return is_object($expectation&&
  94.                 SimpleTestCompatibility::isA($expectation'SimpleExpectation');
  95.     }
  96. }
  97.  
  98. /**
  99.  *    A wildcard expectation always matches.
  100.  *    @package SimpleTest
  101.  *    @subpackage MockObjects
  102.  */
  103.  
  104.     /**
  105.      *    Tests the expectation. Always true.
  106.      *    @param mixed $compare  Ignored.
  107.      *    @return boolean        True.
  108.      *    @access public
  109.      */
  110.     function test($compare{
  111.         return true;
  112.     }
  113.  
  114.     /**
  115.      *    Returns a human readable test message.
  116.      *    @param mixed $compare      Comparison value.
  117.      *    @return string             Description of success
  118.      *                                or failure.
  119.      *    @access public
  120.      */
  121.     function testMessage($compare{
  122.         $dumper &$this->_getDumper();
  123.         return 'Anything always matches [' $dumper->describeValue($compare']';
  124.     }
  125. }
  126.  
  127. /**
  128.  *    An expectation that never matches.
  129.  *    @package SimpleTest
  130.  *    @subpackage MockObjects
  131.  */
  132.  
  133.     /**
  134.      *    Tests the expectation. Always false.
  135.      *    @param mixed $compare  Ignored.
  136.      *    @return boolean        True.
  137.      *    @access public
  138.      */
  139.     function test($compare{
  140.         return false;
  141.     }
  142.  
  143.     /**
  144.      *    Returns a human readable test message.
  145.      *    @param mixed $compare      Comparison value.
  146.      *    @return string             Description of failure.
  147.      *    @access public
  148.      */
  149.     function testMessage($compare{
  150.         $dumper &$this->_getDumper();
  151.         return 'Failed expectation never matches [' $dumper->describeValue($compare']';
  152.     }
  153. }
  154.  
  155. /**
  156.  *    An expectation that passes on boolean true.
  157.  *    @package SimpleTest
  158.  *    @subpackage MockObjects
  159.  */
  160.  
  161.     /**
  162.      *    Tests the expectation.
  163.      *    @param mixed $compare  Should be true.
  164.      *    @return boolean        True on match.
  165.      *    @access public
  166.      */
  167.     function test($compare{
  168.         return (boolean)$compare;
  169.     }
  170.  
  171.     /**
  172.      *    Returns a human readable test message.
  173.      *    @param mixed $compare      Comparison value.
  174.      *    @return string             Description of success
  175.      *                                or failure.
  176.      *    @access public
  177.      */
  178.     function testMessage($compare{
  179.         $dumper &$this->_getDumper();
  180.         return 'Expected true, got [' $dumper->describeValue($compare']';
  181.     }
  182. }
  183.  
  184. /**
  185.  *    An expectation that passes on boolean false.
  186.  *    @package SimpleTest
  187.  *    @subpackage MockObjects
  188.  */
  189.  
  190.     /**
  191.      *    Tests the expectation.
  192.      *    @param mixed $compare  Should be false.
  193.      *    @return boolean        True on match.
  194.      *    @access public
  195.      */
  196.     function test($compare{
  197.         return (boolean)$compare;
  198.     }
  199.  
  200.     /**
  201.      *    Returns a human readable test message.
  202.      *    @param mixed $compare      Comparison value.
  203.      *    @return string             Description of success
  204.      *                                or failure.
  205.      *    @access public
  206.      */
  207.     function testMessage($compare{
  208.         $dumper &$this->_getDumper();
  209.         return 'Expected false, got [' $dumper->describeValue($compare']';
  210.     }
  211. }
  212.  
  213. /**
  214.  *    Test for equality.
  215.  *    @package SimpleTest
  216.  *    @subpackage UnitTester
  217.  */
  218.     var $_value;
  219.  
  220.     /**
  221.      *    Sets the value to compare against.
  222.      *    @param mixed $value        Test value to match.
  223.      *    @param string $message     Customised message on failure.
  224.      *    @access public
  225.      */
  226.     function EqualExpectation($value$message '%s'{
  227.         $this->SimpleExpectation($message);
  228.         $this->_value = $value;
  229.     }
  230.  
  231.     /**
  232.      *    Tests the expectation. True if it matches the
  233.      *    held value.
  234.      *    @param mixed $compare        Comparison value.
  235.      *    @return boolean              True if correct.
  236.      *    @access public
  237.      */
  238.     function test($compare{
  239.         return (($this->_value == $compare&& ($compare == $this->_value));
  240.     }
  241.  
  242.     /**
  243.      *    Returns a human readable test message.
  244.      *    @param mixed $compare      Comparison value.
  245.      *    @return string             Description of success
  246.      *                                or failure.
  247.      *    @access public
  248.      */
  249.     function testMessage($compare{
  250.         if ($this->test($compare)) {
  251.             return "Equal expectation [" $this->_dumper->describeValue($this->_value"]";
  252.         else {
  253.             return "Equal expectation fails " .
  254.                     $this->_dumper->describeDifference($this->_value$compare);
  255.         }
  256.     }
  257.  
  258.     /**
  259.      *    Accessor for comparison value.
  260.      *    @return mixed       Held value to compare with.
  261.      *    @access protected
  262.      */
  263.     function _getValue({
  264.         return $this->_value;
  265.     }
  266. }
  267.  
  268. /**
  269.  *    Test for inequality.
  270.  *    @package SimpleTest
  271.  *    @subpackage UnitTester
  272.  */
  273.  
  274.     /**
  275.      *    Sets the value to compare against.
  276.      *    @param mixed $value       Test value to match.
  277.      *    @param string $message    Customised message on failure.
  278.      *    @access public
  279.      */
  280.     function NotEqualExpectation($value$message '%s'{
  281.         $this->EqualExpectation($value$message);
  282.     }
  283.  
  284.     /**
  285.      *    Tests the expectation. True if it differs from the
  286.      *    held value.
  287.      *    @param mixed $compare        Comparison value.
  288.      *    @return boolean              True if correct.
  289.      *    @access public
  290.      */
  291.     function test($compare{
  292.         return parent::test($compare);
  293.     }
  294.  
  295.     /**
  296.      *    Returns a human readable test message.
  297.      *    @param mixed $compare      Comparison value.
  298.      *    @return string             Description of success
  299.      *                                or failure.
  300.      *    @access public
  301.      */
  302.     function testMessage($compare{
  303.         $dumper &$this->_getDumper();
  304.         if ($this->test($compare)) {
  305.             return "Not equal expectation passes " .
  306.                     $dumper->describeDifference($this->_getValue()$compare);
  307.         else {
  308.             return "Not equal expectation fails [" .
  309.                     $dumper->describeValue($this->_getValue()) .
  310.                     "] matches";
  311.         }
  312.     }
  313. }
  314.  
  315. /**
  316.  *    Test for being within a range.
  317.  *    @package SimpleTest
  318.  *    @subpackage UnitTester
  319.  */
  320.     var $_upper;
  321.     var $_lower;
  322.  
  323.     /**
  324.      *    Sets the value to compare against and the fuzziness of
  325.      *    the match. Used for comparing floating point values.
  326.      *    @param mixed $value        Test value to match.
  327.      *    @param mixed $margin       Fuzziness of match.
  328.      *    @param string $message     Customised message on failure.
  329.      *    @access public
  330.      */
  331.     function WithinMarginExpectation($value$margin$message '%s'{
  332.         $this->SimpleExpectation($message);
  333.         $this->_upper = $value $margin;
  334.         $this->_lower = $value $margin;
  335.     }
  336.  
  337.     /**
  338.      *    Tests the expectation. True if it matches the
  339.      *    held value.
  340.      *    @param mixed $compare        Comparison value.
  341.      *    @return boolean              True if correct.
  342.      *    @access public
  343.      */
  344.     function test($compare{
  345.         return (($compare <= $this->_upper&& ($compare >= $this->_lower));
  346.     }
  347.  
  348.     /**
  349.      *    Returns a human readable test message.
  350.      *    @param mixed $compare      Comparison value.
  351.      *    @return string             Description of success
  352.      *                                or failure.
  353.      *    @access public
  354.      */
  355.     function testMessage($compare{
  356.         if ($this->test($compare)) {
  357.             return $this->_withinMessage($compare);
  358.         else {
  359.             return $this->_outsideMessage($compare);
  360.         }
  361.     }
  362.  
  363.     /**
  364.      *    Creates a the message for being within the range.
  365.      *    @param mixed $compare        Value being tested.
  366.      *    @access private
  367.      */
  368.     function _withinMessage($compare{
  369.         return "Within expectation [" $this->_dumper->describeValue($this->_lower"] and [" .
  370.                 $this->_dumper->describeValue($this->_upper"]";
  371.     }
  372.  
  373.     /**
  374.      *    Creates a the message for being within the range.
  375.      *    @param mixed $compare        Value being tested.
  376.      *    @access private
  377.      */
  378.     function _outsideMessage($compare{
  379.         if ($compare $this->_upper{
  380.             return "Outside expectation " .
  381.                     $this->_dumper->describeDifference($compare$this->_upper);
  382.         else {
  383.             return "Outside expectation " .
  384.                     $this->_dumper->describeDifference($compare$this->_lower);
  385.         }
  386.     }
  387. }
  388.  
  389. /**
  390.  *    Test for being outside of a range.
  391.  *    @package SimpleTest
  392.  *    @subpackage UnitTester
  393.  */
  394.  
  395.     /**
  396.      *    Sets the value to compare against and the fuzziness of
  397.      *    the match. Used for comparing floating point values.
  398.      *    @param mixed $value        Test value to not match.
  399.      *    @param mixed $margin       Fuzziness of match.
  400.      *    @param string $message     Customised message on failure.
  401.      *    @access public
  402.      */
  403.     function OutsideMarginExpectation($value$margin$message '%s'{
  404.         $this->WithinMarginExpectation($value$margin$message);
  405.     }
  406.  
  407.     /**
  408.      *    Tests the expectation. True if it matches the
  409.      *    held value.
  410.      *    @param mixed $compare        Comparison value.
  411.      *    @return boolean              True if correct.
  412.      *    @access public
  413.      */
  414.     function test($compare{
  415.         return parent::test($compare);
  416.     }
  417.  
  418.     /**
  419.      *    Returns a human readable test message.
  420.      *    @param mixed $compare      Comparison value.
  421.      *    @return string             Description of success
  422.      *                                or failure.
  423.      *    @access public
  424.      */
  425.     function testMessage($compare{
  426.         if ($this->test($compare)) {
  427.             return $this->_withinMessage($compare);
  428.         else {
  429.             return $this->_outsideMessage($compare);
  430.         }
  431.     }
  432. }
  433.  
  434. /**
  435.  *    Test for reference.
  436.  *    @package SimpleTest
  437.  *    @subpackage UnitTester
  438.  */
  439.     var $_value;
  440.  
  441.     /**
  442.      *    Sets the reference value to compare against.
  443.      *    @param mixed $value       Test reference to match.
  444.      *    @param string $message    Customised message on failure.
  445.      *    @access public
  446.      */
  447.     function ReferenceExpectation(&$value$message '%s'{
  448.         $this->SimpleExpectation($message);
  449.         $this->_value =$value;
  450.     }
  451.  
  452.     /**
  453.      *    Tests the expectation. True if it exactly
  454.      *    references the held value.
  455.      *    @param mixed $compare        Comparison reference.
  456.      *    @return boolean              True if correct.
  457.      *    @access public
  458.      */
  459.     function test(&$compare{
  460.         return SimpleTestCompatibility::isReference($this->_value$compare);
  461.     }
  462.  
  463.     /**
  464.      *    Returns a human readable test message.
  465.      *    @param mixed $compare      Comparison value.
  466.      *    @return string             Description of success
  467.      *                                or failure.
  468.      *    @access public
  469.      */
  470.     function testMessage($compare{
  471.         if ($this->test($compare)) {
  472.             return "Reference expectation [" $this->_dumper->describeValue($this->_value"]";
  473.         else {
  474.             return "Reference expectation fails " .
  475.                     $this->_dumper->describeDifference($this->_value$compare);
  476.         }
  477.     }
  478.  
  479.     function _getValue({
  480.         return $this->_value;
  481.     }
  482. }
  483.  
  484. /**
  485.  *    Test for identity.
  486.  *    @package SimpleTest
  487.  *    @subpackage UnitTester
  488.  */
  489.  
  490.     /**
  491.      *    Sets the value to compare against.
  492.      *    @param mixed $value       Test value to match.
  493.      *    @param string $message    Customised message on failure.
  494.      *    @access public
  495.      */
  496.     function IdenticalExpectation($value$message '%s'{
  497.         $this->EqualExpectation($value$message);
  498.     }
  499.  
  500.     /**
  501.      *    Tests the expectation. True if it exactly
  502.      *    matches the held value.
  503.      *    @param mixed $compare        Comparison value.
  504.      *    @return boolean              True if correct.
  505.      *    @access public
  506.      */
  507.     function test($compare{
  508.         return SimpleTestCompatibility::isIdentical($this->_getValue()$compare);
  509.     }
  510.  
  511.     /**
  512.      *    Returns a human readable test message.
  513.      *    @param mixed $compare      Comparison value.
  514.      *    @return string             Description of success
  515.      *                                or failure.
  516.      *    @access public
  517.      */
  518.     function testMessage($compare{
  519.         $dumper &$this->_getDumper();
  520.         if ($this->test($compare)) {
  521.             return "Identical expectation [" $dumper->describeValue($this->_getValue()) "]";
  522.         else {
  523.             return "Identical expectation [" $dumper->describeValue($this->_getValue()) .
  524.                     "] fails with [" .
  525.                     $dumper->describeValue($compare"] " .
  526.                     $dumper->describeDifference($this->_getValue()$compareTYPE_MATTERS);
  527.         }
  528.     }
  529. }
  530.  
  531. /**
  532.  *    Test for non-identity.
  533.  *    @package SimpleTest
  534.  *    @subpackage UnitTester
  535.  */
  536.  
  537.     /**
  538.      *    Sets the value to compare against.
  539.      *    @param mixed $value        Test value to match.
  540.      *    @param string $message     Customised message on failure.
  541.      *    @access public
  542.      */
  543.     function NotIdenticalExpectation($value$message '%s'{
  544.         $this->IdenticalExpectation($value$message);
  545.     }
  546.  
  547.     /**
  548.      *    Tests the expectation. True if it differs from the
  549.      *    held value.
  550.      *    @param mixed $compare        Comparison value.
  551.      *    @return boolean              True if correct.
  552.      *    @access public
  553.      */
  554.     function test($compare{
  555.         return parent::test($compare);
  556.     }
  557.  
  558.     /**
  559.      *    Returns a human readable test message.
  560.      *    @param mixed $compare      Comparison value.
  561.      *    @return string             Description of success
  562.      *                                or failure.
  563.      *    @access public
  564.      */
  565.     function testMessage($compare{
  566.         $dumper &$this->_getDumper();
  567.         if ($this->test($compare)) {
  568.             return "Not identical expectation passes " .
  569.                     $dumper->describeDifference($this->_getValue()$compareTYPE_MATTERS);
  570.         else {
  571.             return "Not identical expectation [" $dumper->describeValue($this->_getValue()) "] matches";
  572.         }
  573.     }
  574. }
  575.  
  576. /**
  577.  *    Test for a pattern using Perl regex rules.
  578.  *    @package SimpleTest
  579.  *    @subpackage UnitTester
  580.  */
  581.     var $_pattern;
  582.  
  583.     /**
  584.      *    Sets the value to compare against.
  585.      *    @param string $pattern    Pattern to search for.
  586.      *    @param string $message    Customised message on failure.
  587.      *    @access public
  588.      */
  589.     function PatternExpectation($pattern$message '%s'{
  590.         $this->SimpleExpectation($message);
  591.         $this->_pattern = $pattern;
  592.     }
  593.  
  594.     /**
  595.      *    Accessor for the pattern.
  596.      *    @return string       Perl regex as string.
  597.      *    @access protected
  598.      */
  599.     function _getPattern({
  600.         return $this->_pattern;
  601.     }
  602.  
  603.     /**
  604.      *    Tests the expectation. True if the Perl regex
  605.      *    matches the comparison value.
  606.      *    @param string $compare        Comparison value.
  607.      *    @return boolean               True if correct.
  608.      *    @access public
  609.      */
  610.     function test($compare{
  611.         return (boolean)preg_match($this->_getPattern()$compare);
  612.     }
  613.  
  614.     /**
  615.      *    Returns a human readable test message.
  616.      *    @param mixed $compare      Comparison value.
  617.      *    @return string             Description of success
  618.      *                                or failure.
  619.      *    @access public
  620.      */
  621.     function testMessage($compare{
  622.         if ($this->test($compare)) {
  623.             return $this->_describePatternMatch($this->_getPattern()$compare);
  624.         else {
  625.             $dumper &$this->_getDumper();
  626.             return "Pattern [" $this->_getPattern(.
  627.                     "] not detected in [" .
  628.                     $dumper->describeValue($compare"]";
  629.         }
  630.     }
  631.  
  632.     /**
  633.      *    Describes a pattern match including the string
  634.      *    found and it's position.
  635.      *    @param string $pattern        Regex to match against.
  636.      *    @param string $subject        Subject to search.
  637.      *    @access protected
  638.      */
  639.     function _describePatternMatch($pattern$subject{
  640.         preg_match($pattern$subject$matches);
  641.         $position strpos($subject$matches[0]);
  642.         $dumper $this->_getDumper();
  643.         return "Pattern [$pattern] detected at character [$position] in [.
  644.                 $dumper->describeValue($subject"] as [" .
  645.                 $matches[0"] in region [" .
  646.                 $dumper->clipString($subject100$position"]";
  647.     }
  648. }
  649.  
  650. /**
  651.  *    @package SimpleTest
  652.  *    @subpackage UnitTester
  653.  *    @deprecated
  654.  */
  655. }
  656.  
  657. /**
  658.  *    Fail if a pattern is detected within the
  659.  *    comparison.
  660.  *    @package SimpleTest
  661.  *    @subpackage UnitTester
  662.  */
  663.  
  664.     /**
  665.      *    Sets the reject pattern
  666.      *    @param string $pattern    Pattern to search for.
  667.      *    @param string $message    Customised message on failure.
  668.      *    @access public
  669.      */
  670.     function NoPatternExpectation($pattern$message '%s'{
  671.         $this->PatternExpectation($pattern$message);
  672.     }
  673.  
  674.     /**
  675.      *    Tests the expectation. False if the Perl regex
  676.      *    matches the comparison value.
  677.      *    @param string $compare        Comparison value.
  678.      *    @return boolean               True if correct.
  679.      *    @access public
  680.      */
  681.     function test($compare{
  682.         return parent::test($compare);
  683.     }
  684.  
  685.     /**
  686.      *    Returns a human readable test message.
  687.      *    @param string $compare      Comparison value.
  688.      *    @return string              Description of success
  689.      *                                 or failure.
  690.      *    @access public
  691.      */
  692.     function testMessage($compare{
  693.         if ($this->test($compare)) {
  694.             $dumper &$this->_getDumper();
  695.             return "Pattern [" $this->_getPattern(.
  696.                     "] not detected in [" .
  697.                     $dumper->describeValue($compare"]";
  698.         else {
  699.             return $this->_describePatternMatch($this->_getPattern()$compare);
  700.         }
  701.     }
  702. }
  703.  
  704. /**
  705.  *    @package SimpleTest
  706.  *    @subpackage UnitTester
  707.  *      @deprecated
  708.  */
  709. }
  710.  
  711. /**
  712.  *    Tests either type or class name if it's an object.
  713.  *      @package SimpleTest
  714.  *      @subpackage UnitTester
  715.  */
  716. class IsAExpectation extends SimpleExpectation {
  717.     var $_type;
  718.  
  719.     /**
  720.      *    Sets the type to compare with.
  721.      *    @param string $type       Type or class name.
  722.      *    @param string $message    Customised message on failure.
  723.      *    @access public
  724.      */
  725.     function IsAExpectation($type$message '%s'{
  726.         $this->SimpleExpectation($message);
  727.         $this->_type = $type;
  728.     }
  729.  
  730.     /**
  731.      *    Accessor for type to check against.
  732.      *    @return string    Type or class name.
  733.      *    @access protected
  734.      */
  735.     function _getType({
  736.         return $this->_type;
  737.     }
  738.  
  739.     /**
  740.      *    Tests the expectation. True if the type or
  741.      *    class matches the string value.
  742.      *    @param string $compare        Comparison value.
  743.      *    @return boolean               True if correct.
  744.      *    @access public
  745.      */
  746.     function test($compare{
  747.         if (is_object($compare)) {
  748.             return SimpleTestCompatibility::isA($compare$this->_type);
  749.         else {
  750.             return (strtolower(gettype($compare)) == $this->_canonicalType($this->_type));
  751.         }
  752.     }
  753.  
  754.     /**
  755.      *    Coerces type name into a gettype() match.
  756.      *    @param string $type        User type.
  757.      *    @return string             Simpler type.
  758.      *    @access private
  759.      */
  760.     function _canonicalType($type{
  761.         $type strtolower($type);
  762.         $map array(
  763.                 'bool' => 'boolean',
  764.                 'float' => 'double',
  765.                 'real' => 'double',
  766.                 'int' => 'integer');
  767.         if (isset($map[$type])) {
  768.             $type $map[$type];
  769.         }
  770.         return $type;
  771.     }
  772.  
  773.     /**
  774.      *    Returns a human readable test message.
  775.      *    @param mixed $compare      Comparison value.
  776.      *    @return string             Description of success
  777.      *                                or failure.
  778.      *    @access public
  779.      */
  780.     function testMessage($compare{
  781.         $dumper &$this->_getDumper();
  782.         return "Value [" $dumper->describeValue($compare.
  783.                 "] should be type [" $this->_type . "]";
  784.     }
  785. }
  786.  
  787. /**
  788.  *    Tests either type or class name if it's an object.
  789.  *    Will succeed if the type does not match.
  790.  *      @package SimpleTest
  791.  *      @subpackage UnitTester
  792.  */
  793. class NotAExpectation extends IsAExpectation {
  794.     var $_type;
  795.  
  796.     /**
  797.      *    Sets the type to compare with.
  798.      *    @param string $type       Type or class name.
  799.      *    @param string $message    Customised message on failure.
  800.      *    @access public
  801.      */
  802.     function NotAExpectation($type$message '%s'{
  803.         $this->IsAExpectation($type$message);
  804.     }
  805.  
  806.     /**
  807.      *    Tests the expectation. False if the type or
  808.      *    class matches the string value.
  809.      *    @param string $compare        Comparison value.
  810.      *    @return boolean               True if different.
  811.      *    @access public
  812.      */
  813.     function test($compare{
  814.         return parent::test($compare);
  815.     }
  816.  
  817.     /**
  818.      *    Returns a human readable test message.
  819.      *    @param mixed $compare      Comparison value.
  820.      *    @return string             Description of success
  821.      *                                or failure.
  822.      *    @access public
  823.      */
  824.     function testMessage($compare{
  825.         $dumper &$this->_getDumper();
  826.         return "Value [" $dumper->describeValue($compare.
  827.                 "] should not be type [" $this->_getType("]";
  828.     }
  829. }
  830.  
  831. /**
  832.  *    Tests for existance of a method in an object
  833.  *      @package SimpleTest
  834.  *      @subpackage UnitTester
  835.  */
  836.     var $_method;
  837.  
  838.     /**
  839.      *    Sets the value to compare against.
  840.      *    @param string $method     Method to check.
  841.      *    @param string $message    Customised message on failure.
  842.      *    @access public
  843.      *    @return void 
  844.      */
  845.     function MethodExistsExpectation($method$message '%s'{
  846.         $this->SimpleExpectation($message);
  847.         $this->_method = &$method;
  848.     }
  849.  
  850.     /**
  851.      *    Tests the expectation. True if the method exists in the test object.
  852.      *    @param string $compare        Comparison method name.
  853.      *    @return boolean               True if correct.
  854.      *    @access public
  855.      */
  856.     function test($compare{
  857.         return (boolean)(is_object($compare&& method_exists($compare$this->_method));
  858.     }
  859.  
  860.     /**
  861.      *    Returns a human readable test message.
  862.      *    @param mixed $compare      Comparison value.
  863.      *    @return string             Description of success
  864.      *                                or failure.
  865.      *    @access public
  866.      */
  867.     function testMessage($compare{
  868.         $dumper &$this->_getDumper();
  869.         if (is_object($compare)) {
  870.             return 'No method on non-object [' $dumper->describeValue($compare']';
  871.         }
  872.         $method $this->_method;
  873.         return "Object [" $dumper->describeValue($compare.
  874.                 "] should contain method [$method]";
  875.     }
  876. }
  877. ?>

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