Changeset 276

Show
Ignore:
Timestamp:
10/31/07 08:37:18 (9 months ago)
Author:
mrook
Message:

#152 - Fix result counting for child tests (patch by Dirk Thomas)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/2.3/classes/phing/tasks/ext/phpunit/PHPUnitTestRunner.php

    r275 r276  
    118118                } 
    119119 
    120                 else if ($res->failureCount() != 0 || $res->notImplementedCount() != 0
     120                else if ($res->failureCount() != 0 || $res->notImplementedCount() != 0 || $res->skippedCount() != 0
    121121                { 
    122122                        $this->retCode = self::FAILURES; 
  • branches/2.3/classes/phing/tasks/ext/phpunit/phpunit3/PHPUnit3ResultFormatter.php

    r148 r276  
    3838        protected $project = NULL; 
    3939         
    40         private $timer = NULL; 
    41  
    42         private $runCount = 0; 
    43          
    44         private $failureCount = 0; 
    45          
    46         private $errorCount = 0;         
     40        private $timers = false; 
     41         
     42        private $runCounts = false; 
     43         
     44        private $failureCounts = false; 
     45         
     46        private $errorCounts = false; 
     47         
     48        private $incompleteCounts = false; 
     49         
     50        private $skipCounts = false; 
    4751         
    4852        /** 
     
    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         
     
    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 
     
    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); 
     171        } 
     172         
     173        function getIncompleteCount() 
     174        { 
     175                return end($this->incompleteCounts); 
     176        } 
     177         
     178        function getSkippedCount() 
     179        { 
     180                return end($this->skipCounts); 
    144181        } 
    145182         
    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 
     
    155192                } 
    156193        } 
     194 
     195        private  function getMicrotime() { 
     196                list($usec, $sec) = explode(' ', microtime()); 
     197                return (float)$usec + (float)$sec; 
     198        } 
    157199} 
    158200?> 
  • branches/2.3/classes/phing/tasks/ext/phpunit/phpunit3/PlainPHPUnit3ResultFormatter.php

    r177 r276  
    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                { 
     
    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) 
     93        { 
     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) 
    9299        { 
    93100                if ($test != null) 
  • branches/2.3/classes/phing/tasks/ext/phpunit/phpunit3/SummaryPHPUnit3ResultFormatter.php

    r148 r276  
    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"; 
     42                 
     43                parent::endTestRun($suite); 
    4344                 
    4445                if ($this->out != NULL) 
  • trunk/classes/phing/tasks/ext/phpunit/PHPUnitTestRunner.php

    r275 r276  
    118118                } 
    119119 
    120                 else if ($res->failureCount() != 0 || $res->notImplementedCount() != 0
     120                else if ($res->failureCount() != 0 || $res->notImplementedCount() != 0 || $res->skippedCount() != 0
    121121                { 
    122122                        $this->retCode = self::FAILURES; 
  • trunk/classes/phing/tasks/ext/phpunit/phpunit3/PHPUnit3ResultFormatter.php

    r148 r276  
    3838        protected $project = NULL; 
    3939         
    40         private $timer = NULL; 
    41  
    42         private $runCount = 0; 
    43          
    44         private $failureCount = 0; 
    45          
    46         private $errorCount = 0;         
     40        private $timers = false; 
     41         
     42        private $runCounts = false; 
     43         
     44        private $failureCounts = false; 
     45         
     46        private $errorCounts = false; 
     47         
     48        private $incompleteCounts = false; 
     49         
     50        private $skipCounts = false; 
    4751         
    4852        /** 
     
    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         
     
    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 
     
    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); 
     171        } 
     172         
     173        function getIncompleteCount() 
     174        { 
     175                return end($this->incompleteCounts); 
     176        } 
     177         
     178        function getSkippedCount() 
     179        { 
     180                return end($this->skipCounts); 
    144181        } 
    145182         
    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 
     
    155192                } 
    156193        } 
     194 
     195        private  function getMicrotime() { 
     196                list($usec, $sec) = explode(' ', microtime()); 
     197                return (float)$usec + (float)$sec; 
     198        } 
    157199} 
    158200?> 
  • trunk/classes/phing/tasks/ext/phpunit/phpunit3/PlainPHPUnit3ResultFormatter.php

    r177 r276  
    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                { 
     
    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) 
     93        { 
     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) 
    9299        { 
    93100                if ($test != null) 
  • trunk/classes/phing/tasks/ext/phpunit/phpunit3/SummaryPHPUnit3ResultFormatter.php

    r148 r276  
    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"; 
     42                 
     43                parent::endTestRun($suite); 
    4344                 
    4445                if ($this->out != NULL)