home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / Servidores / xampp-win32-1.6.7-installer.exe / php / PEAR / PHPUnit2 / Framework / TestFailure.php < prev    next >
Encoding:
PHP Script  |  2008-07-02  |  4.6 KB  |  155 lines

  1. <?php
  2. /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
  3.  
  4. /**
  5.  * PHP Version 5
  6.  *
  7.  * Copyright (c) 2002-2006, Sebastian Bergmann <sb@sebastian-bergmann.de>.
  8.  * All rights reserved.
  9.  *
  10.  * Redistribution and use in source and binary forms, with or without
  11.  * modification, are permitted provided that the following conditions
  12.  * are met:
  13.  *
  14.  *   * Redistributions of source code must retain the above copyright
  15.  *     notice, this list of conditions and the following disclaimer.
  16.  * 
  17.  *   * Redistributions in binary form must reproduce the above copyright
  18.  *     notice, this list of conditions and the following disclaimer in
  19.  *     the documentation and/or other materials provided with the
  20.  *     distribution.
  21.  *
  22.  *   * Neither the name of Sebastian Bergmann nor the names of his
  23.  *     contributors may be used to endorse or promote products derived
  24.  *     from this software without specific prior written permission.
  25.  *
  26.  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  27.  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  28.  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  29.  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  30.  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  31.  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  32.  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  33.  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  34.  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRIC
  35.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  36.  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  37.  * POSSIBILITY OF SUCH DAMAGE.
  38.  *
  39.  * @category   Testing
  40.  * @package    PHPUnit2
  41.  * @author     Sebastian Bergmann <sb@sebastian-bergmann.de>
  42.  * @copyright  2002-2006 Sebastian Bergmann <sb@sebastian-bergmann.de>
  43.  * @license    http://www.opensource.org/licenses/bsd-license.php  BSD License
  44.  * @version    CVS: $Id: TestFailure.php,v 1.10.2.3 2005/12/17 16:04:56 sebastian Exp $
  45.  * @link       http://pear.php.net/package/PHPUnit2
  46.  * @since      File available since Release 2.0.0
  47.  */
  48.  
  49. require_once 'PHPUnit2/Framework/AssertionFailedError.php';
  50. require_once 'PHPUnit2/Framework/Test.php';
  51.  
  52. /**
  53.  * A TestFailure collects a failed test together with the caught exception.
  54.  *
  55.  * @category   Testing
  56.  * @package    PHPUnit2
  57.  * @author     Sebastian Bergmann <sb@sebastian-bergmann.de>
  58.  * @copyright  2002-2006 Sebastian Bergmann <sb@sebastian-bergmann.de>
  59.  * @license    http://www.opensource.org/licenses/bsd-license.php  BSD License
  60.  * @version    Release: 2.3.6
  61.  * @link       http://pear.php.net/package/PHPUnit2
  62.  * @since      Class available since Release 2.0.0
  63.  */
  64. class PHPUnit2_Framework_TestFailure {
  65.     /**
  66.      * @var    PHPUnit2_Framework_Test
  67.      * @access protected
  68.      */
  69.     protected $failedTest;
  70.  
  71.     /**
  72.      * @var    Exception
  73.      * @access protected
  74.      */
  75.     protected $thrownException;
  76.  
  77.     /**
  78.      * Constructs a TestFailure with the given test and exception.
  79.      *
  80.      * @param  PHPUnit2_Framework_Test $failedTest
  81.      * @param  Exception               $thrownException
  82.      * @access public
  83.      */
  84.     public function __construct(PHPUnit2_Framework_Test $failedTest, Exception $thrownException) {
  85.         $this->failedTest      = $failedTest;
  86.         $this->thrownException = $thrownException;
  87.     }
  88.  
  89.     /**
  90.      * Returns a short description of the failure.
  91.      *
  92.      * @return string
  93.      * @access public
  94.      */
  95.     public function toString() {
  96.         return sprintf(
  97.           '%s: %s',
  98.  
  99.           $this->failedTest,
  100.           $this->thrownException->getMessage()
  101.         );
  102.     }
  103.  
  104.     /**
  105.      * Gets the failed test.
  106.      *
  107.      * @return Test
  108.      * @access public
  109.      */
  110.     public function failedTest() {
  111.         return $this->failedTest;
  112.     }
  113.  
  114.     /**
  115.      * Gets the thrown exception.
  116.      *
  117.      * @return Exception
  118.      * @access public
  119.      */
  120.     public function thrownException() {
  121.         return $this->thrownException;
  122.     }
  123.  
  124.     /**
  125.      * Returns the exception's message.
  126.      *
  127.      * @return string
  128.      * @access public
  129.      */
  130.     public function exceptionMessage() {
  131.         return $this->thrownException()->getMessage();
  132.     }
  133.  
  134.     /**
  135.      * Returns TRUE if the thrown exception
  136.      * is of type AssertionFailedError.
  137.      *
  138.      * @return boolean
  139.      * @access public
  140.      */
  141.     public function isFailure() {
  142.         return ($this->thrownException() instanceof PHPUnit2_Framework_AssertionFailedError);
  143.     }
  144. }
  145.  
  146.  
  147. /*
  148.  * Local variables:
  149.  * tab-width: 4
  150.  * c-basic-offset: 4
  151.  * c-hanging-comment-ender-p: nil
  152.  * End:
  153.  */
  154. ?>
  155.