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 / Util / Log / PEAR.php next >
Encoding:
PHP Script  |  2008-07-02  |  6.6 KB  |  221 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: PEAR.php,v 1.2.2.3 2005/12/17 16:04:58 sebastian Exp $
  45.  * @link       http://pear.php.net/package/PHPUnit2
  46.  * @since      File available since Release 2.3.0
  47.  */
  48.  
  49. require_once 'PHPUnit2/Framework/TestListener.php';
  50.  
  51. @include_once 'Log.php';
  52.  
  53. /**
  54.  * A TestListener that logs to a PEAR_Log sink.
  55.  *
  56.  * @category   Testing
  57.  * @package    PHPUnit2
  58.  * @author     Sebastian Bergmann <sb@sebastian-bergmann.de>
  59.  * @copyright  2002-2006 Sebastian Bergmann <sb@sebastian-bergmann.de>
  60.  * @license    http://www.opensource.org/licenses/bsd-license.php  BSD License
  61.  * @version    Release: 2.3.6
  62.  * @link       http://pear.php.net/package/PHPUnit2
  63.  * @since      Class available since Release 2.1.0
  64.  */
  65. class PHPUnit2_Util_Log_PEAR implements PHPUnit2_Framework_TestListener {
  66.     /**
  67.      * Log.
  68.      *
  69.      * @var    Log
  70.      * @access private
  71.      */
  72.     private $log;
  73.  
  74.     /**
  75.      * @param string $type      The type of concrete Log subclass to use.
  76.      *                          Currently, valid values are 'console',
  77.      *                          'syslog', 'sql', 'file', and 'mcal'.
  78.      * @param string $name      The name of the actually log file, table, or
  79.      *                          other specific store to use. Defaults to an
  80.      *                          empty string, with which the subclass will
  81.      *                          attempt to do something intelligent.
  82.      * @param string $ident     The identity reported to the log system.
  83.      * @param array  $conf      A hash containing any additional configuration
  84.      *                          information that a subclass might need.
  85.      * @param int $maxLevel     Maximum priority level at which to log.
  86.      * @access public
  87.      */
  88.     public function __construct($type, $name = '', $ident = '', $conf = array(), $maxLevel = PEAR_LOG_DEBUG) {
  89.         $this->log = Log::factory($type, $name, $ident, $conf, $maxLevel);
  90.     }
  91.  
  92.     /**
  93.      * An error occurred.
  94.      *
  95.      * @param  PHPUnit2_Framework_Test $test
  96.      * @param  Exception               $e
  97.      * @access public
  98.      */
  99.     public function addError(PHPUnit2_Framework_Test $test, Exception $e) {
  100.         $this->log->crit(
  101.           sprintf(
  102.             'Test "%s" failed: %s',
  103.  
  104.             $test->getName(),
  105.             $e->getMessage()
  106.           )
  107.         );
  108.     }
  109.  
  110.     /**
  111.      * A failure occurred.
  112.      *
  113.      * @param  PHPUnit2_Framework_Test                 $test
  114.      * @param  PHPUnit2_Framework_AssertionFailedError $e
  115.      * @access public
  116.      */
  117.     public function addFailure(PHPUnit2_Framework_Test $test, PHPUnit2_Framework_AssertionFailedError $e) {
  118.         $this->log->err(
  119.           sprintf(
  120.             'Test "%s" failed: %s',
  121.  
  122.             $test->getName(),
  123.             $e->getMessage()
  124.           )
  125.         );
  126.     }
  127.  
  128.     /**
  129.      * Incomplete test.
  130.      *
  131.      * @param  PHPUnit2_Framework_Test $test
  132.      * @param  Exception               $e
  133.      * @access public
  134.      */
  135.     public function addIncompleteTest(PHPUnit2_Framework_Test $test, Exception $e) {
  136.         $this->log->info(
  137.           sprintf(
  138.             'Test "%s" incomplete: %s',
  139.  
  140.             $test->getName(),
  141.             $e->getMessage()
  142.           )
  143.         );
  144.     }
  145.  
  146.     /**
  147.      * A test suite started.
  148.      *
  149.      * @param  PHPUnit2_Framework_TestSuite $suite
  150.      * @access public
  151.      * @since  Method available since Release 2.2.0
  152.      */
  153.     public function startTestSuite(PHPUnit2_Framework_TestSuite $suite) {
  154.         $this->log->info(
  155.           sprintf(
  156.             'TestSuite "%s" started.',
  157.  
  158.             $suite->getName()
  159.           )
  160.         );
  161.     }
  162.  
  163.     /**
  164.      * A test suite ended.
  165.      *
  166.      * @param  PHPUnit2_Framework_TestSuite $suite
  167.      * @access public
  168.      * @since  Method available since Release 2.2.0
  169.      */
  170.     public function endTestSuite(PHPUnit2_Framework_TestSuite $suite) {
  171.         $this->log->info(
  172.           sprintf(
  173.             'TestSuite "%s" ended.',
  174.  
  175.             $suite->getName()
  176.           )
  177.         );
  178.     }
  179.  
  180.     /**
  181.      * A test started.
  182.      *
  183.      * @param  PHPUnit2_Framework_Test $test
  184.      * @access public
  185.      */
  186.     public function startTest(PHPUnit2_Framework_Test $test) {
  187.         $this->log->info(
  188.           sprintf(
  189.             'Test "%s" started.',
  190.  
  191.             $test->getName()
  192.           )
  193.         );
  194.     }
  195.  
  196.     /**
  197.      * A test ended.
  198.      *
  199.      * @param  PHPUnit2_Framework_Test $test
  200.      * @access public
  201.      */
  202.     public function endTest(PHPUnit2_Framework_Test $test) {
  203.         $this->log->info(
  204.           sprintf(
  205.             'Test "%s" ended.',
  206.  
  207.             $test->getName()
  208.           )
  209.         );
  210.     }
  211. }
  212.  
  213. /*
  214.  * Local variables:
  215.  * tab-width: 4
  216.  * c-basic-offset: 4
  217.  * c-hanging-comment-ender-p: nil
  218.  * End:
  219.  */
  220. ?>
  221.