Ticket #152: phing230_ext-phpunit-formatter.patch

File phing230_ext-phpunit-formatter.patch, 6.2 kB (added by dirk.thomas@4wdmedia.de, 1 year ago)

patch for PHPUnit3 formatter

  • PHPUnit3ResultFormatter.php

    old new  
    3737         
    3838        protected $project = NULL; 
    3939         
    40         private $timer = NULL; 
    41  
    42         private $runCount = 0; 
     40        private $timers = false; 
    4341         
    44         private $failureCount = 0
     42        private $runCounts = false
    4543         
    46         private $errorCount = 0;        
     44        private $failureCounts = false; 
    4745         
     46        private $errorCounts = false; 
     47         
     48        private $incompleteCounts = false; 
     49         
     50        private $skipCounts = false; 
     51         
    4852        /** 
    4953         * Sets the writer the formatter is supposed to write its results to. 
    5054         */ 
     
    8084         
    8185        function startTestRun() 
    8286        { 
     87                $this->timers = array($this->getMicrotime()); 
     88                $this->runCounts = array(0); 
     89                $this->failureCounts = array(0); 
     90                $this->errorCounts = array(0); 
     91                $this->incompleteCounts = array(0); 
     92                $this->skipCounts = array(0); 
    8393        } 
    8494         
    8595        function endTestRun() 
     
    8898         
    8999        function startTestSuite(PHPUnit_Framework_TestSuite $suite) 
    90100        { 
    91                 $this->runCount = 0
    92                 $this->failureCount = 0; 
    93                 $this->errorCount = 0; 
    94                  
    95                 $this->timer = new Timer()
    96                 $this->timer->start()
     101                $this->timers[] = $this->getMicrotime()
     102                $this->runCounts[] = 0; 
     103                $this->failureCounts[] = 0; 
     104                $this->errorCounts[] = 0; 
     105                $this->incompleteCounts[] = 0
     106                $this->skipCounts[] = 0
    97107        } 
    98108         
    99109        function endTestSuite(PHPUnit_Framework_TestSuite $suite) 
    100110        { 
    101                 $this->timer->stop(); 
     111                $lastRunCount = array_pop($this->runCounts); 
     112                $this->runCounts[count($this->runCounts) - 1] += $lastRunCount; 
     113                 
     114                $lastFailureCount = array_pop($this->failureCounts); 
     115                $this->failureCounts[count($this->failureCounts) - 1] += $lastFailureCount; 
     116                 
     117                $lastErrorCount = array_pop($this->errorCounts); 
     118                $this->errorCounts[count($this->errorCounts) - 1] += $lastErrorCount; 
     119                 
     120                $lastIncompleteCount = array_pop($this->incompleteCounts); 
     121                $this->incompleteCounts[count($this->incompleteCounts) - 1] += $lastIncompleteCount; 
     122                 
     123                $lastSkipCount = array_pop($this->skipCounts); 
     124                $this->skipCounts[count($this->skipCounts) - 1] += $lastSkipCount; 
     125                 
     126                array_pop($this->timers); 
    102127        } 
    103128 
    104129        function startTest(PHPUnit_Framework_Test $test) 
    105130        { 
    106                 $this->runCount++; 
     131                $this->runCounts[count($this->runCounts) - 1]++; 
    107132        } 
    108133 
    109134        function endTest(PHPUnit_Framework_Test $test, $time) 
     
    112137 
    113138        function addError(PHPUnit_Framework_Test $test, Exception $e, $time) 
    114139        { 
    115                 $this->errorCount++; 
     140                $this->errorCounts[count($this->errorCounts) - 1]++; 
    116141        } 
    117142 
    118143        function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time) 
    119144        { 
    120                 $this->failureCount++; 
     145                $this->failureCounts[count($this->failureCounts) - 1]++; 
    121146        } 
    122147 
    123148        function addIncompleteTest(PHPUnit_Framework_Test $test, Exception $e, $time) 
    124149        { 
     150                $this->incompleteCounts[count($this->incompleteCounts) - 1]++; 
    125151        } 
    126152 
    127153        function addSkippedTest(PHPUnit_Framework_Test $test, Exception $e, $time) 
    128154        { 
     155                $this->skipCounts[count($this->skipCounts) - 1]++; 
    129156        } 
    130157         
    131158        function getRunCount() 
    132159        { 
    133                 return $this->runCount
     160                return end($this->runCounts)
    134161        } 
    135162         
    136163        function getFailureCount() 
    137164        { 
    138                 return $this->failureCount
     165                return end($this->failureCounts)
    139166        } 
    140167         
    141168        function getErrorCount() 
    142169        { 
    143                 return $this->errorCount
     170                return end($this->errorCounts)
    144171        } 
    145172         
     173        function getIncompleteCount() 
     174        { 
     175                return end($this->incompleteCounts); 
     176        } 
     177         
     178        function getSkippedCount() 
     179        { 
     180                return end($this->skipCounts); 
     181        } 
     182         
    146183        function getElapsedTime() 
    147184        { 
    148                 if ($this->timer
     185                if (end($this->timers)
    149186                { 
    150                         return $this->timer->getElapsedTime(); 
     187                        return $this->getMicrotime() - end($this->timers); 
    151188                } 
    152189                else 
    153190                { 
    154191                        return 0; 
    155192                } 
    156193        } 
     194 
     195        private  function getMicrotime() { 
     196                list($usec, $sec) = explode(' ', microtime()); 
     197                return (float)$usec + (float)$sec; 
     198        } 
    157199} 
    158200?> 
  • PlainPHPUnit3ResultFormatter.php

    old new  
    5252         
    5353        function endTestSuite(PHPUnit_Framework_TestSuite $suite) 
    5454        { 
    55                 parent::endTestSuite($suite); 
    56                  
    5755                $sb = "Testsuite: " . $suite->getName() . "\n"; 
    5856                $sb.= "Tests run: " . $this->getRunCount(); 
    5957                $sb.= ", Failures: " . $this->getFailureCount(); 
    6058                $sb.= ", Errors: " . $this->getErrorCount(); 
    61                 $sb.= ", Time elapsed: " . $this->getElapsedTime(); 
    62                 $sb.= " sec\n"; 
     59                $sb.= ", Incomplete: " . $this->getIncompleteCount(); 
     60                $sb.= ", Skipped: " . $this->getSkippedCount(); 
     61                $sb.= ", Time elapsed: " . sprintf('%0.5f', $this->getElapsedTime()) . " s\n"; 
    6362 
     63                parent::endTestSuite($suite); 
     64                 
    6465                if ($this->out != NULL) 
    6566                { 
    6667                        $this->out->write($sb); 
     
    8586        { 
    8687                parent::addIncompleteTest($test, $e, $time); 
    8788                 
    88                 $this->formatError("INCOMPLETE", $test, $e); 
     89                $this->formatError("INCOMPLETE", $test); 
    8990        } 
    9091 
    91         private function formatError($type, PHPUnit_Framework_Test $test, Exception $e) 
     92        function addSkippedTest(PHPUnit_Framework_Test $test, Exception $e, $time) 
    9293        { 
     94                parent::addSkippedTest($test, $e, $time); 
     95                $this->formatError("SKIPPED", $test); 
     96        } 
     97 
     98        private function formatError($type, PHPUnit_Framework_Test $test, Exception $e = null) 
     99        { 
    93100                if ($test != null) 
    94101                { 
    95102                        $this->endTest($test, time()); 
  • SummaryPHPUnit3ResultFormatter.php

    old new  
    3131 */      
    3232class SummaryPHPUnit3ResultFormatter extends PHPUnit3ResultFormatter 
    3333{ 
    34         function endTestSuite(PHPUnit_Framework_TestSuite $suite
     34        function endTestRun(
    3535        { 
    36                 parent::endTestSuite($suite); 
    37                  
    3836                $sb = "Tests run: " . $this->getRunCount(); 
    3937                $sb.= ", Failures: " . $this->getFailureCount(); 
    4038                $sb.= ", Errors: " . $this->getErrorCount(); 
    41                 $sb.= ", Time elapsed: " . $this->getElapsedTime(); 
    42                 $sb.= " sec\n"; 
     39                $sb.= ", Incomplete: " . $this->getIncompleteCount(); 
     40                $sb.= ", Skipped: " . $this->getSkippedCount(); 
     41                $sb.= ", Time elapsed: " . sprintf('%0.5f', $this->getElapsedTime()) . " s\n"; 
    4342                 
     43                parent::endTestRun($suite); 
     44                 
    4445                if ($this->out != NULL) 
    4546                { 
    4647                        $this->out->write($sb);