PHPUnit2
[ class tree: PHPUnit2 ] [ index: PHPUnit2 ] [ all elements ]

Source for file ComparisonFailure.php

Documentation is available at ComparisonFailure.php

  1. <?php
  2. //
  3. // +------------------------------------------------------------------------+
  4. // | PEAR :: PHPUnit2                                                       |
  5. // +------------------------------------------------------------------------+
  6. // | Copyright (c) 2002-2005 Sebastian Bergmann <sb@sebastian-bergmann.de>. |
  7. // +------------------------------------------------------------------------+
  8. // | This source file is subject to version 3.00 of the PHP License,        |
  9. // | that is available at http://www.php.net/license/3_0.txt.               |
  10. // | If you did not receive a copy of the PHP license and are unable to     |
  11. // | obtain it through the world-wide-web, please send a note to            |
  12. // | license@php.net so we can mail you a copy immediately.                 |
  13. // +------------------------------------------------------------------------+
  14. //
  15. // $Id: ComparisonFailure.php,v 1.8.2.2 2005/02/04 10:01:55 sebastian Exp $
  16. //
  17.  
  18. require_once 'PHPUnit2/Framework/Assert.php';
  19. require_once 'PHPUnit2/Framework/AssertionFailedError.php';
  20.  
  21. /**
  22.  * Thrown when an assertion for string equality failed.
  23.  *
  24.  * @author      Sebastian Bergmann <sb@sebastian-bergmann.de>
  25.  * @copyright   Copyright &copy; 2002-2005 Sebastian Bergmann <sb@sebastian-bergmann.de>
  26.  * @license     http://www.php.net/license/3_0.txt The PHP License, Version 3.0
  27.  * @category    Testing
  28.  * @package     PHPUnit2
  29.  * @subpackage  Framework
  30.  */
  31.     // {{{ Instance Variables
  32.  
  33.     /**
  34.     * @var    string 
  35.     * @access private
  36.     */
  37.     private $expected '';
  38.  
  39.     /**
  40.     * @var    string 
  41.     * @access private
  42.     */
  43.     private $actual '';
  44.  
  45.     // }}}
  46.     // {{{ public function __construct($expected, $actual, $message = '')
  47.  
  48.     /**
  49.     * Constructs a comparison failure.
  50.     *
  51.     * @param  string $expected 
  52.     * @param  string $actual 
  53.     * @param  string $message 
  54.     * @access public
  55.     */
  56.     public function __construct($expected$actual$message ''{
  57.         parent::__construct($message);
  58.  
  59.         $this->expected ($expected === NULL'NULL' $expected;
  60.         $this->actual   ($actual   === NULL'NULL' $actual;
  61.     }
  62.  
  63.     // }}}
  64.     // {{{ public function toString()
  65.  
  66.     /**
  67.     * Returns "..." in place of common prefix and "..." in
  68.     * place of common suffix between expected and actual.
  69.     *
  70.     * @return string 
  71.     * @access public
  72.     */
  73.     public function toString({
  74.         $end min(strlen($this->expected)strlen($this->actual));
  75.         $i   = 0;
  76.         $j   strlen($this->expected- 1;
  77.         $k   strlen($this->actual)   - 1;
  78.  
  79.         for ($i $end$i++{
  80.             if ($this->expected[$i!= $this->actual[$i]{
  81.                 break;
  82.             }
  83.         }
  84.  
  85.         for ($k >= $i && $j >= $i$k--,$j--{
  86.             if ($this->expected[$j!= $this->actual[$k]{
  87.                 break;
  88.             }
  89.         }
  90.  
  91.         if ($j $i && $k $i{
  92.             $expected $this->expected;
  93.             $actual   $this->actual;
  94.         else {
  95.             $expected substr($this->expected$i($j + 1 - $i));
  96.             $actual   substr($this->actual,   $i($k + 1 - $i));;
  97.  
  98.             if ($i <= $end && $i > 0{
  99.                 $expected '...' $expected;
  100.                 $actual   '...' $actual;
  101.             }
  102.       
  103.             if ($j strlen($this->expected- 1{
  104.                 $expected .= '...';
  105.             }
  106.  
  107.             if ($k strlen($this->actual- 1{
  108.                 $actual .= '...';
  109.             }
  110.         }
  111.  
  112.         return PHPUnit2_Framework_Assert::format(
  113.             $expected,
  114.             $actual,
  115.             parent::getMessage()
  116.         );
  117.     }
  118.  
  119.     // }}}
  120. }
  121.  
  122. /*
  123.  * vim600:  et sw=2 ts=2 fdm=marker
  124.  * vim<600: et sw=2 ts=2
  125.  */
  126. ?>

Documentation generated on Mon, 11 Mar 2019 14:19:18 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.