| 71 | | function tryToAddToSuite(PHPUnit_Framework_TestSuite &$suite,$file) |
|---|
| 72 | | { |
|---|
| 73 | | if (substr($file,0,1)=='_'){ |
|---|
| 74 | | return false; |
|---|
| 75 | | }elseif (is_file($file)){ |
|---|
| | 78 | private function addFilter($arg) |
|---|
| | 79 | { |
|---|
| | 80 | switch ($arg{0}){ |
|---|
| | 81 | case '-': $mode = 'sub'; break; |
|---|
| | 82 | case '+': $mode = 'add'; break; |
|---|
| | 83 | default: return false; |
|---|
| | 84 | } |
|---|
| | 85 | |
|---|
| | 86 | $param = substr($arg,1); |
|---|
| | 87 | switch ($this->typeOfFilter($param)){ |
|---|
| | 88 | case 'method': |
|---|
| | 89 | $pattern = str_replace('*','.*',$param); |
|---|
| | 90 | if ($mode=='add'){ |
|---|
| | 91 | $pattern = "/^$pattern/"; |
|---|
| | 92 | $this->options['filter'] = $pattern; |
|---|
| | 93 | }else{ |
|---|
| | 94 | //conditional regex-pattern: |
|---|
| | 95 | //if <$pattern> matches, the actual method-name must begin with 'tset' which is always false |
|---|
| | 96 | $pattern = "/^(?(?=$pattern)tset)/"; |
|---|
| | 97 | $this->options['filter'] = $pattern; |
|---|
| | 98 | } |
|---|
| | 99 | break; |
|---|
| | 100 | case 'group': |
|---|
| | 101 | $mode == 'add' ? $this->options['groups'][] = $param : $this->options['excludeGroups'][] = $param; |
|---|
| | 102 | break; |
|---|
| | 103 | case 'filename': |
|---|
| | 104 | $pattern = str_replace(array('\\','.','*'),array('\\\\','\.','.*'),$param); |
|---|
| | 105 | |
|---|
| | 106 | $this->filename_filter = $mode == 'add' ? "/$pattern$/" : "/^(?(?=.*$pattern$).*hph$)/"; |
|---|
| | 107 | break; |
|---|
| | 108 | } |
|---|
| | 109 | } |
|---|
| | 110 | |
|---|
| | 111 | private function typeOfFilter($param) |
|---|
| | 112 | { |
|---|
| | 113 | if (substr($param,0,4)=='test') return 'method'; |
|---|
| | 114 | if (substr($param,-4)=='.php') return 'filename'; |
|---|
| | 115 | return 'group'; |
|---|
| | 116 | } |
|---|
| | 117 | |
|---|
| | 118 | private function addFile(PHPUnit_Framework_TestSuite &$suite,$file) |
|---|
| | 119 | { |
|---|
| | 120 | if (is_file($file)){ |
|---|
| | 121 | if (!$this->ensureValidFilename((string)$file)) return false; |
|---|
| 108 | | test_runner [-v] [tests/test-suites/folders] |
|---|
| 109 | | -v verbose |
|---|
| 110 | | -? this help |
|---|
| 111 | | |
|---|
| 112 | | This script creates TestSuites on-the fly and runs them. It will exclude filenames or folders which start with an underscore. |
|---|
| | 173 | test_runner [-v|?] [-|+group] [-|+method] [-|+filename] <filenames|folders> |
|---|
| | 174 | -v verbose |
|---|
| | 175 | -? this help |
|---|
| | 176 | -+group see below |
|---|
| | 177 | -+method |
|---|
| | 178 | -+file |
|---|
| | 179 | |
|---|
| | 180 | This script creates TestSuites on-the fly and runs them. |
|---|
| | 181 | It will exclude filenames or folders which start with an underscore. As a |
|---|
| | 182 | convention it will not run filenames which end with <_TestCase.php> but instead |
|---|
| | 183 | include them. This is so because 'TestCases' use to be abstract classes which |
|---|
| | 184 | contain common methods or a special Test-Api. |
|---|
| | 185 | |
|---|
| | 186 | You can exclude or include groups, methods and/or files. |
|---|
| | 187 | A minus [-] means 'except', a plus means 'only'. E.g.: |
|---|
| | 188 | |
|---|
| | 189 | > test_runner -v -slow -test*Postgre + DbAdap*.php tests/ |
|---|
| | 190 | |
|---|
| | 191 | this will search through all files in the folder <tests/> and its subfolders, |
|---|
| | 192 | include the one which filename begins with <DbAdap> and exclude the tests which |
|---|
| | 193 | belong to a group called <slow> or which method name matches <test.*Postgre>. |
|---|
| | 194 | |
|---|
| | 195 | So how does this work. We take the sign -|+ to decide if we exclude or include |
|---|
| | 196 | the following parameter. The parameter gets parsed: if it begins with <test> we |
|---|
| | 197 | take it as an method-name, if it ends with <.php> we say its a filename, |
|---|
| | 198 | otherwise it should be a group name. You can use a <*> to match "any character". |
|---|
| | 199 | You can specify multiple groups, but only one methodname or filename pattern. |
|---|
| | 200 | |
|---|
| | 201 | > test_runner tests/ -postgre -sqlite |
|---|
| | 202 | > test_runner tests/ +mysql |
|---|
| | 203 | > test_runner tests/ + Request*.php |
|---|
| | 204 | > test_runner tests/AkRequest/ tests/AkRouter/ |
|---|
| | 205 | > test_runner tests/ +test*Cast*Null |
|---|