Advertisement
jlb

XmlTimeReporter

jlb
Dec 2nd, 2011
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.95 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Extend default XmlReporter to record & report time to run each test method
  4.  */
  5. class XmlTimeReporter extends XmlReporter
  6. {
  7.     var $pre;
  8.  
  9.     /**
  10.      * (non-PHPdoc)
  11.      *
  12.      * @see XmlReporter::paintMethodStart()
  13.      *
  14.      * @param string $test_name the test name
  15.      * @return void
  16.      */
  17.     function paintMethodStart($test_name)
  18.     {
  19.         $this->pre = microtime(TRUE);
  20.         parent::paintMethodStart($test_name);
  21.     }
  22.  
  23.     /**
  24.      * (non-PHPdoc)
  25.      *
  26.      * @see XmlReporter::paintMethodEnd()
  27.      *
  28.      * @param string $test_name the test name
  29.      * @return void
  30.      */
  31.     function paintMethodEnd($test_name)
  32.     {
  33.         $post = microtime(TRUE);
  34.         if ($this->pre != null) {
  35.             $duration = $post - $this->pre;
  36.             // how can post time be less than pre?  assuming zero if this happens..
  37.             if ($post < $this->pre) $duration = 0;
  38.             print $this->_getIndent(1);
  39.             print "<time>$duration</time>\n";
  40.         }
  41.         parent::paintMethodEnd($test_name);
  42.         $this->pre = null;
  43.     }
  44.  
  45. }
  46.  
  47.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement