| @@ -1,9 +1,9 @@ discard block | ||
| 1 | 1 | #!/usr/bin/env php | 
| 2 | -<?php declare(strict_types=1); | |
| 2 | +<?php declare(strict_types = 1); | |
| 3 | 3 | |
| 4 | 4 | use Terah\Assert\Tester; | 
| 5 | 5 | |
| 6 | -require_once __DIR__ . '/../vendor/autoload.php'; | |
| 6 | +require_once __DIR__.'/../vendor/autoload.php'; | |
| 7 | 7 | |
| 8 | 8 | class TestRunner | 
| 9 | 9 |  { | 
| @@ -15,7 +15,7 @@ discard block | ||
| 15 | 15 |          $recursive      = (bool)static::getArg('recursive', true); | 
| 16 | 16 |          $generate       = (string)static::getArg('generate', ''); | 
| 17 | 17 |          $output         = (string)static::getArg('output', ''); | 
| 18 | - if ( $generate ) | |
| 18 | + if ($generate) | |
| 19 | 19 |          { | 
| 20 | 20 | static::generate($generate, $output); | 
| 21 | 21 | } | 
| @@ -41,21 +41,21 @@ discard block | ||
| 41 | 41 | $totalFailed = 0; | 
| 42 | 42 | $totalTests = 0; | 
| 43 | 43 | $tests = static::getTestFiles($fileName, $recursive); | 
| 44 | - if ( empty($tests) ) | |
| 44 | + if (empty($tests)) | |
| 45 | 45 |          { | 
| 46 | 46 |              Tester::getLogger()->error("No test files found/specified"); | 
| 47 | 47 | |
| 48 | 48 | exit(1); | 
| 49 | 49 | } | 
| 50 | - foreach ( $tests as $fileName ) | |
| 50 | + foreach ($tests as $fileName) | |
| 51 | 51 |          { | 
| 52 | 52 |              Tester::getLogger()->debug("Loading test file {$fileName}"); | 
| 53 | 53 | require($fileName); | 
| 54 | - $results = Tester::run($suite, $test); | |
| 55 | - $totalFailed += $results['totalFailed']; | |
| 56 | - $totalTests += $results['totalTests']; | |
| 54 | + $results = Tester::run($suite, $test); | |
| 55 | + $totalFailed += $results[ 'totalFailed' ]; | |
| 56 | + $totalTests += $results[ 'totalTests' ]; | |
| 57 | 57 | } | 
| 58 | - if ( $totalFailed ) | |
| 58 | + if ($totalFailed) | |
| 59 | 59 |          { | 
| 60 | 60 |              Tester::getLogger()->error("Tests failed - {$totalFailed} of {$totalTests} tests have failed."); | 
| 61 | 61 | |
| @@ -71,46 +71,46 @@ discard block | ||
| 71 | 71 | * @param bool $recursive | 
| 72 | 72 | * @return array | 
| 73 | 73 | */ | 
| 74 | - protected static function getTestFiles(string $fileName='', bool $recursive=false) : array | |
| 74 | + protected static function getTestFiles(string $fileName = '', bool $recursive = false) : array | |
| 75 | 75 |      { | 
| 76 | - if ( empty($fileName) ) | |
| 76 | + if (empty($fileName)) | |
| 77 | 77 |          { | 
| 78 | - return []; | |
| 78 | + return [ ]; | |
| 79 | 79 | } | 
| 80 | - if ( ! file_exists($fileName) ) | |
| 80 | + if ( ! file_exists($fileName)) | |
| 81 | 81 |          { | 
| 82 | 82 |              Tester::getLogger()->error("{$fileName} does not exist; exiting"); | 
| 83 | 83 | |
| 84 | 84 | exit(1); | 
| 85 | 85 | } | 
| 86 | - $fileName = realpath($fileName); | |
| 87 | - if ( is_dir($fileName) ) | |
| 86 | + $fileName = realpath($fileName); | |
| 87 | + if (is_dir($fileName)) | |
| 88 | 88 |          { | 
| 89 | - $iterator = new \DirectoryIterator($fileName); | |
| 90 | - if ( $recursive ) | |
| 89 | + $iterator = new \DirectoryIterator($fileName); | |
| 90 | + if ($recursive) | |
| 91 | 91 |              { | 
| 92 | 92 | $iterator = new \RecursiveDirectoryIterator($fileName); | 
| 93 | 93 | $iterator = $recursive ? new RecursiveIteratorIterator($iterator) : $iterator; | 
| 94 | 94 | } | 
| 95 | - $testFiles = []; | |
| 96 | - foreach ( $iterator as $fileInfo ) | |
| 95 | + $testFiles = [ ]; | |
| 96 | + foreach ($iterator as $fileInfo) | |
| 97 | 97 |              { | 
| 98 | -                if ( preg_match('/Suite.php$/', $fileInfo->getBasename()) ) | |
| 98 | +                if (preg_match('/Suite.php$/', $fileInfo->getBasename())) | |
| 99 | 99 |                  { | 
| 100 | - $testFiles[] = $fileInfo->getPathname(); | |
| 100 | + $testFiles[ ] = $fileInfo->getPathname(); | |
| 101 | 101 | } | 
| 102 | 102 | } | 
| 103 | 103 | |
| 104 | 104 | return $testFiles; | 
| 105 | 105 | } | 
| 106 | - if ( ! is_file($fileName) ) | |
| 106 | + if ( ! is_file($fileName)) | |
| 107 | 107 |          { | 
| 108 | 108 |              Tester::getLogger()->error("{$fileName} is not a file; exiting"); | 
| 109 | 109 | |
| 110 | 110 | exit(1); | 
| 111 | 111 | } | 
| 112 | 112 | |
| 113 | - return [$fileName]; | |
| 113 | + return [ $fileName ]; | |
| 114 | 114 | } | 
| 115 | 115 | |
| 116 | 116 | /** | 
| @@ -163,16 +163,16 @@ discard block | ||
| 163 | 163 | * @param array $argv | 
| 164 | 164 | * @return array | 
| 165 | 165 | */ | 
| 166 | - protected static function parseArgs(array $argv=[]) : array | |
| 166 | + protected static function parseArgs(array $argv = [ ]) : array | |
| 167 | 167 |      { | 
| 168 | - $argv = $argv ?: ! empty($_SERVER['argv']) ? $_SERVER['argv'] : []; | |
| 168 | + $argv = $argv ?: ! empty($_SERVER[ 'argv' ]) ? $_SERVER[ 'argv' ] : [ ]; | |
| 169 | 169 | array_shift($argv); | 
| 170 | - $out = []; | |
| 171 | - for ( $i = 0, $j = count($argv); $i < $j; $i++ ) | |
| 170 | + $out = [ ]; | |
| 171 | + for ($i = 0, $j = count($argv); $i < $j; $i++) | |
| 172 | 172 |          { | 
| 173 | - $arg = $argv[$i]; | |
| 173 | + $arg = $argv[ $i ]; | |
| 174 | 174 | // --foo --bar=baz | 
| 175 | - if ( mb_substr($arg, 0, 2) === '--' ) | |
| 175 | + if (mb_substr($arg, 0, 2) === '--') | |
| 176 | 176 |              { | 
| 177 | 177 | $eqPos = mb_strpos($arg, '='); | 
| 178 | 178 | // --foo | 
| @@ -180,23 +180,23 @@ discard block | ||
| 180 | 180 |                  { | 
| 181 | 181 | $key = mb_substr($arg, 2); | 
| 182 | 182 | // --foo value | 
| 183 | - if ($i + 1 < $j && $argv[$i + 1][0] !== '-') | |
| 183 | + if ($i + 1 < $j && $argv[ $i + 1 ][ 0 ] !== '-') | |
| 184 | 184 |                      { | 
| 185 | - $value = $argv[$i + 1]; | |
| 185 | + $value = $argv[ $i + 1 ]; | |
| 186 | 186 | $i++; | 
| 187 | 187 | } | 
| 188 | 188 | else | 
| 189 | 189 |                      { | 
| 190 | - $value = isset($out[$key]) ? $out[$key] : true; | |
| 190 | + $value = isset($out[ $key ]) ? $out[ $key ] : true; | |
| 191 | 191 | } | 
| 192 | - $out[$key] = $value; | |
| 192 | + $out[ $key ] = $value; | |
| 193 | 193 | } | 
| 194 | 194 | // --bar=baz | 
| 195 | 195 | else | 
| 196 | 196 |                  { | 
| 197 | 197 | $key = mb_substr($arg, 2, $eqPos - 2); | 
| 198 | 198 | $value = mb_substr($arg, $eqPos + 1); | 
| 199 | - $out[$key] = $value; | |
| 199 | + $out[ $key ] = $value; | |
| 200 | 200 | } | 
| 201 | 201 | } | 
| 202 | 202 | // -k=value -abc | 
| @@ -207,23 +207,23 @@ discard block | ||
| 207 | 207 |                  { | 
| 208 | 208 | $key = mb_substr($arg, 1, 1); | 
| 209 | 209 | $value = mb_substr($arg, 3); | 
| 210 | - $out[$key] = $value; | |
| 210 | + $out[ $key ] = $value; | |
| 211 | 211 | } | 
| 212 | 212 | // -abc | 
| 213 | 213 | else | 
| 214 | 214 |                  { | 
| 215 | 215 | $chars = str_split(mb_substr($arg, 1)); | 
| 216 | 216 | $key = ''; | 
| 217 | - foreach ( $chars as $char ) | |
| 217 | + foreach ($chars as $char) | |
| 218 | 218 |                      { | 
| 219 | 219 | $key = $char; | 
| 220 | - $value = isset($out[$key]) ? $out[$key] : true; | |
| 221 | - $out[$key] = $value; | |
| 220 | + $value = isset($out[ $key ]) ? $out[ $key ] : true; | |
| 221 | + $out[ $key ] = $value; | |
| 222 | 222 | } | 
| 223 | 223 | // -a value1 -abc value2 | 
| 224 | - if ($i + 1 < $j && $argv[$i + 1][0] !== '-') | |
| 224 | + if ($i + 1 < $j && $argv[ $i + 1 ][ 0 ] !== '-') | |
| 225 | 225 |                      { | 
| 226 | - $out[$key] = $argv[$i + 1]; | |
| 226 | + $out[ $key ] = $argv[ $i + 1 ]; | |
| 227 | 227 | $i++; | 
| 228 | 228 | } | 
| 229 | 229 | } | 
| @@ -232,14 +232,14 @@ discard block | ||
| 232 | 232 | else | 
| 233 | 233 |              { | 
| 234 | 234 | $value = $arg; | 
| 235 | - $out[] = $value; | |
| 235 | + $out[ ] = $value; | |
| 236 | 236 | } | 
| 237 | 237 | } | 
| 238 | - foreach ( $out as $idx => $val ) | |
| 238 | + foreach ($out as $idx => $val) | |
| 239 | 239 |          { | 
| 240 | - if ( is_string($val) && strpos($val, '|') !== false ) | |
| 240 | + if (is_string($val) && strpos($val, '|') !== false) | |
| 241 | 241 |              { | 
| 242 | -                $out[$idx] = explode('|', $val); | |
| 242 | +                $out[ $idx ] = explode('|', $val); | |
| 243 | 243 | } | 
| 244 | 244 | } | 
| 245 | 245 | |
| @@ -251,11 +251,11 @@ discard block | ||
| 251 | 251 | * @param mixed $default | 
| 252 | 252 | * @return string | 
| 253 | 253 | */ | 
| 254 | - protected static function getArg($name, $default=null) | |
| 254 | + protected static function getArg($name, $default = null) | |
| 255 | 255 |      { | 
| 256 | 256 | $args = static::parseArgs(); | 
| 257 | 257 | |
| 258 | - return isset($args[$name]) && $args[$name] ? $args[$name] : $default; | |
| 258 | + return isset($args[ $name ]) && $args[ $name ] ? $args[ $name ] : $default; | |
| 259 | 259 | } | 
| 260 | 260 | |
| 261 | 261 | } |