Ticket #151: tasks_ext_phpunit_GroupStuff-151.patch

File tasks_ext_phpunit_GroupStuff-151.patch, 3.2 kB (added by dirk.thomas@4wdmedia.de, 1 year ago)

This patch adds the groups and excludeGroups attributes to the PHPUnitTask. To show a message for PHPUnit < 3.2 a added the minor version only for that special case (to keep the patch simple).

  • PHPUnitTask.php

    old new  
    4444        private $printsummary = false; 
    4545        private $testfailed = false; 
    4646        private $codecoverage = false; 
     47        private $groups = array(); 
     48        private $excludeGroups = array(); 
    4749 
    4850        /** 
    4951         * Initialize Task. 
     
    7880                if (version_compare($version, "3.0.0") >= 0) 
    7981                { 
    8082                        PHPUnitUtil::$installedVersion = 3; 
     83                        if (version_compare($version, "3.2.0") >= 0) 
     84                        { 
     85                                PHPUnitUtil::$installedMinorVersion = 2; 
     86                        } 
    8187                } 
    8288                else 
    8389                { 
     
    153159                $this->codecoverage = $codecoverage; 
    154160        } 
    155161 
     162        function setGroups($groups) 
     163        { 
     164                if (PHPUnitUtil::$installedVersion < 3 || (PHPUnitUtil::$installedVersion == 3 && PHPUnitUtil::$installedMinorVersion < 2)) 
     165                { 
     166                        $this->log("The 'groups' attribute is only available with PHPUnit 3.2.0 or newer", Project::MSG_WARN); 
     167                } 
     168                $token = ' ,;'; 
     169                $this->groups = array(); 
     170                $tok = strtok($groups, $token); 
     171                while ($tok !== false) { 
     172                        $this->groups[] = $tok; 
     173                        $tok = strtok($token); 
     174                } 
     175        } 
     176 
     177        function setExcludeGroups($excludeGroups) 
     178        { 
     179                if (PHPUnitUtil::$installedVersion < 3 || (PHPUnitUtil::$installedVersion == 3 && PHPUnitUtil::$installedMinorVersion < 2)) 
     180                { 
     181                        $this->log("The 'excludeGroups' attribute is only available with PHPUnit 3.2.0 or newer", Project::MSG_WARN); 
     182                } 
     183                $token = ' ,;'; 
     184                $this->excludeGroups = array(); 
     185                $tok = strtok($groups, $token); 
     186                while ($tok !== false) { 
     187                        $this->excludeGroups[] = $tok; 
     188                        $tok = strtok($token); 
     189                } 
     190        } 
     191 
    156192        /** 
    157193         * Add a new formatter to all tests of this task. 
    158194         * 
     
    255291         */ 
    256292        private function execute($suite) 
    257293        { 
    258                 $runner = new PHPUnitTestRunner($suite, $this->project); 
     294                $runner = new PHPUnitTestRunner($suite, $this->project, $this->groups, $this->excludeGroups); 
    259295                 
    260296                $runner->setCodecoverage($this->codecoverage); 
    261297 
  • PHPUnitTestRunner.php

    old new  
    4646         
    4747        private $project = NULL; 
    4848 
    49         function __construct($suite, Project $project) 
     49        private $groups = array(); 
     50        private $excludeGroups = array(); 
     51 
     52        function __construct($suite, Project $project, $groups = array(), $excludeGroups = array()) 
    5053        { 
    5154                $this->suite = $suite; 
    5255                $this->project = $project; 
     56                $this->groups = $groups; 
     57                $this->excludeGroups = $excludeGroups; 
    5358                $this->retCode = self::SUCCESS; 
    5459        } 
    5560         
     
    8893                        $res->addListener($formatter); 
    8994                } 
    9095 
    91                 $this->suite->run($res); 
     96                $this->suite->run($res, false, $this->groups, $this->excludeGroups); 
    9297                 
    9398                if ($this->codecoverage) 
    9499                { 
  • PHPUnitUtil.php

    old new  
    3030class PHPUnitUtil 
    3131{ 
    3232        /** 
    33          * Installed PHPUnit version 
     33         * Installed PHPUnit major version 
    3434         */ 
    3535        public static $installedVersion = 2; 
    3636         
     37        /** 
     38         * Installed PHPUnit minor version 
     39         */ 
     40        public static $installedMinorVersion = 0; 
     41         
    3742        protected static $definedClasses = array(); 
    3843         
    3944        /**