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-2004 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.5 2004/07/10 08:03:41 sebastian Exp $
  16. //
  17.  
  18. require_once 'PHPUnit2/Framework/AssertionFailedError.php';
  19.  
  20. /**
  21.  * Thrown when an assertion for string equality failed.
  22.  *
  23.  * @author      Sebastian Bergmann <sb@sebastian-bergmann.de>
  24.  * @copyright   Copyright &copy; 2002-2004 Sebastian Bergmann <sb@sebastian-bergmann.de>
  25.  * @license     http://www.php.net/license/3_0.txt The PHP License, Version 3.0
  26.  * @category    PHP
  27.  * @package     PHPUnit2
  28.  * @subpackage  Framework
  29.  */
  30.     // {{{ Members
  31.  
  32.     /**
  33.     * @var    string 
  34.     * @access private
  35.     */
  36.     private $expected '';
  37.  
  38.     /**
  39.     * @var    string 
  40.     * @access private
  41.     */
  42.     private $actual '';
  43.  
  44.     // }}}
  45.     // {{{ public function __construct($expected, $actual, $message = '')
  46.  
  47.     /**
  48.     * Constructs a comparison failure.
  49.     *
  50.     * @param  string $expected 
  51.     * @param  string $actual 
  52.     * @param  string $message 
  53.     * @access public
  54.     */
  55.     public function __construct($expected$actual$message ''{
  56.         parent::__construct($message);
  57.  
  58.         $this->expected ($expected === null'null' $expected;
  59.         $this->actual   ($actual   === null'null' $actual;
  60.     }
  61.  
  62.     // }}}
  63.     // {{{ public function toString()
  64.  
  65.     /**
  66.     * Returns "..." in place of common prefix and "..." in
  67.     * place of common suffix between expected and actual.
  68.     *
  69.     * @return string 
  70.     * @access public
  71.     */
  72.     public function toString({
  73.         $end min(strlen($this->expected)strlen($this->actual));
  74.         $i   = 0;
  75.         $j   strlen($this->expected- 1;
  76.         $k   strlen($this->actual)   - 1;
  77.  
  78.         for ($i $end$i++{
  79.             if ($this->expected[$i!= $this->actual[$i]{
  80.                 break;
  81.             }
  82.         }
  83.  
  84.         for ($k >= $i && $j >= $i$k--,$j--{
  85.             if ($this->expected[$j!= $this->actual[$k]{
  86.                 break;
  87.             }
  88.         }
  89.  
  90.         if ($j $i && $k $i{
  91.             $expected $this->expected;
  92.             $actual   $this->actual;
  93.         else {
  94.             $expected substr($this->expected$i($j + 1 - $i));
  95.             $actual   substr($this->actual,   $i($k + 1 - $i));;
  96.  
  97.             if ($i <= $end && $i > 0{
  98.                 $expected '...' $expected;
  99.                 $actual   '...' $actual;
  100.             }
  101.       
  102.             if ($j strlen($this->expected- 1{
  103.                 $expected .= '...';
  104.             }
  105.  
  106.             if ($k strlen($this->actual- 1{
  107.                 $actual .= '...';
  108.             }
  109.         }
  110.  
  111.         return PHPUnit2_Framework_Assert::format(
  112.             $expected,
  113.             $actual,
  114.             parent::getMessage()
  115.         );
  116.     }
  117.  
  118.     // }}}
  119. }
  120.  
  121. /*
  122.  * vim600:  et sw=2 ts=2 fdm=marker
  123.  * vim<600: et sw=2 ts=2
  124.  */
  125. ?>

Documentation generated on Mon, 11 Mar 2019 13:55:58 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.