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

Source for file XML.php

Documentation is available at XML.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: XML.php,v 1.1.2.1 2004/10/01 06:11:53 sebastian Exp $
  16. //
  17.  
  18. require_once 'PHPUnit2/Framework/TestFailure.php';
  19. require_once 'PHPUnit2/Framework/TestListener.php';
  20. require_once 'PHPUnit2/Framework/TestResult.php';
  21. require_once 'PHPUnit2/Util/Printer.php';
  22.  
  23. /**
  24.  * A TestListener that generates an XML-based logfile
  25.  * of the test execution.
  26.  *
  27.  * The XML markup is based upon the one used by the
  28.  * Artima SuiteRunner, see http://www.artima.com/suiterunner/
  29.  * for details.
  30.  *
  31.  * @author      Sebastian Bergmann <sb@sebastian-bergmann.de>
  32.  * @copyright   Copyright &copy; 2002-2004 Sebastian Bergmann <sb@sebastian-bergmann.de>
  33.  * @license     http://www.php.net/license/3_0.txt The PHP License, Version 3.0
  34.  * @category    Testing
  35.  * @package     PHPUnit2
  36.  * @subpackage  Extensions
  37.  * @since       2.1.0
  38.  */
  39.     // {{{ Members
  40.  
  41.     /**
  42.     * @var    boolean 
  43.     * @access private
  44.     */
  45.     private $testFailed = FALSE;
  46.  
  47.     // }}}
  48.     // {{{ public function addError(PHPUnit2_Framework_Test $test, Exception $e)
  49.  
  50.     /**
  51.     * An error occurred.
  52.     *
  53.     * @param  PHPUnit2_Framework_Test  $test 
  54.     * @param  Exception               $e 
  55.     * @access public
  56.     */
  57.     public function addError(PHPUnit2_Framework_Test $testException $e{
  58.         $this->testFailed($test$e);
  59.     }
  60.  
  61.     // }}}
  62.     // {{{ public function addFailure(PHPUnit2_Framework_Test $test, PHPUnit2_Framework_AssertionFailedError $e)
  63.  
  64.     /**
  65.     * A failure occurred.
  66.     *
  67.     * @param  PHPUnit2_Framework_Test                 $test 
  68.     * @param  PHPUnit2_Framework_AssertionFailedError $e 
  69.     * @access public
  70.     */
  71.     public function addFailure(PHPUnit2_Framework_Test $testPHPUnit2_Framework_AssertionFailedError $e{
  72.         $this->testFailed($test$e);
  73.     }
  74.  
  75.     // }}}
  76.     // {{{ public function addIncompleteTest(PHPUnit2_Framework_Test $test, Exception $e)
  77.  
  78.     /**
  79.     * Incomplete test.
  80.     *
  81.     * @param  PHPUnit2_Framework_Test $test 
  82.     * @param  Exception               $e 
  83.     * @access public
  84.     */
  85.     public function addIncompleteTest(PHPUnit2_Framework_Test $testException $e{
  86.         $this->testFailed($test$e'Incomplete');
  87.     }
  88.  
  89.     // }}}
  90.     // {{{ public function endTest(PHPUnit2_Framework_Test $test)
  91.  
  92.     /**
  93.     * A test ended.
  94.     *
  95.     * @param  PHPUnit2_Framework_Test $test 
  96.     * @access public
  97.     */
  98.     public function endTest(PHPUnit2_Framework_Test $test{
  99.         if (!$this->testFailed{
  100.             $this->write(
  101.               sprintf(
  102.                 "<testSucceeded>\n"   .
  103.                 "  <name>%s</name>\n" .
  104.                 "  <date>%s</date>\n" .
  105.                 "</testSucceeded>\n",
  106.                 $test->getName(),
  107.                 date('d-m-Y H:i:s')
  108.               )
  109.             );
  110.         }
  111.     }
  112.  
  113.     // }}}
  114.     // {{{ public function startTest(PHPUnit2_Framework_Test $test)
  115.  
  116.     /**
  117.     * A test started.
  118.     *
  119.     * @param  PHPUnit2_Framework_Test $test 
  120.     * @access public
  121.     */
  122.     public function startTest(PHPUnit2_Framework_Test $test{
  123.         $this->write(
  124.           sprintf(
  125.             "<testStarting>\n"    .
  126.             "  <name>%s</name>\n" .
  127.             "  <date>%s</date>\n" .
  128.             "</testStarting>\n",
  129.  
  130.             $test->getName(),
  131.             date('d-m-Y H:i:s')
  132.           )
  133.         );
  134.  
  135.         $this->testFailed = FALSE;
  136.     }
  137.  
  138.     // }}}
  139.     // {{{ private function testFailed(PHPUnit2_Framework_Test $test, Exception $e)
  140.  
  141.     /**
  142.     * A test failed.
  143.     *
  144.     * @param  PHPUnit2_Framework_Test $test 
  145.     * @param  Exception               $e 
  146.     * @param  String                  $type 
  147.     * @access private
  148.     */
  149.     private function testFailed(PHPUnit2_Framework_Test $testException $e$type 'Failed'{
  150.         $this->write(
  151.           sprintf(
  152.             "<test%s>\n"                .
  153.             "  <name>%s</name>\n"       .
  154.             "  <message>%s</message>\n" .
  155.             "  <date>%s</date>\n"       .
  156.             "</testFailed>\n",
  157.  
  158.             $type,
  159.             $test->getName(),
  160.             $e->getMessage(),
  161.             date('d-m-Y H:i:s')
  162.           )
  163.         );
  164.  
  165.         $this->testFailed = TRUE;
  166.     }
  167.  
  168.     // }}}
  169. }
  170.  
  171. /*
  172.  * vim600:  et sw=2 ts=2 fdm=marker
  173.  * vim<600: et sw=2 ts=2
  174.  */
  175. ?>

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