@@ -1,4 +1,4 @@ discard block |
||
1 | -<?php declare(strict_types=1); |
|
1 | +<?php declare(strict_types = 1); |
|
2 | 2 | |
3 | 3 | namespace Terah\Assert; |
4 | 4 | |
@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | protected static $currentSuite = self::DEFAULT_SUITE; |
13 | 13 | |
14 | 14 | /** @var Suite[] */ |
15 | - protected static $suites = []; |
|
15 | + protected static $suites = [ ]; |
|
16 | 16 | |
17 | 17 | /** @var Logger $logger */ |
18 | 18 | public static $logger = null; |
@@ -29,12 +29,12 @@ discard block |
||
29 | 29 | * @param string $suiteName |
30 | 30 | * @return Suite |
31 | 31 | */ |
32 | - public static function suite(string $suiteName='') : Suite |
|
32 | + public static function suite(string $suiteName = '') : Suite |
|
33 | 33 | { |
34 | 34 | $suiteName = $suiteName ?: static::$currentSuite; |
35 | - static::$suites[$suiteName] = new Suite(); |
|
35 | + static::$suites[ $suiteName ] = new Suite(); |
|
36 | 36 | |
37 | - return static::$suites[$suiteName]; |
|
37 | + return static::$suites[ $suiteName ]; |
|
38 | 38 | } |
39 | 39 | |
40 | 40 | /** |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | * @return Suite |
48 | 48 | * @throws AssertionFailedException |
49 | 49 | */ |
50 | - public static function test(string $testName, Closure $test, string $suiteName='', string $successMessage='', int $exceptionCode=0, string $exceptionClass='') : Suite |
|
50 | + public static function test(string $testName, Closure $test, string $suiteName = '', string $successMessage = '', int $exceptionCode = 0, string $exceptionClass = '') : Suite |
|
51 | 51 | { |
52 | 52 | Assert::that($successMessage)->notEmpty(); |
53 | 53 | Assert::that($test)->isCallable(); |
@@ -60,15 +60,15 @@ discard block |
||
60 | 60 | * @param string $suiteName |
61 | 61 | * @param string $testName |
62 | 62 | */ |
63 | - public static function run(string $suiteName='', string $testName='') |
|
63 | + public static function run(string $suiteName = '', string $testName = '') |
|
64 | 64 | { |
65 | - $suites = static::$suites; |
|
66 | - if ( ! empty($suiteName) ) |
|
65 | + $suites = static::$suites; |
|
66 | + if ( ! empty($suiteName)) |
|
67 | 67 | { |
68 | 68 | Assert::that($suites)->keyExists($suiteName, "The test suite ({$suiteName}) has not been loaded"); |
69 | - $suites = [$suites[$suiteName]]; |
|
69 | + $suites = [ $suites[ $suiteName ] ]; |
|
70 | 70 | } |
71 | - foreach ( $suites as $suite ) |
|
71 | + foreach ($suites as $suite) |
|
72 | 72 | { |
73 | 73 | $suite->run($testName); |
74 | 74 | } |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | */ |
80 | 80 | public static function getLogger() : Logger |
81 | 81 | { |
82 | - if ( ! static::$logger ) |
|
82 | + if ( ! static::$logger) |
|
83 | 83 | { |
84 | 84 | static::$logger = new Logger(); |
85 | 85 | } |
@@ -91,15 +91,15 @@ discard block |
||
91 | 91 | * @param string $suiteName |
92 | 92 | * @return Suite |
93 | 93 | */ |
94 | - protected static function getSuite(string $suiteName='') : Suite |
|
94 | + protected static function getSuite(string $suiteName = '') : Suite |
|
95 | 95 | { |
96 | - $suiteName = $suiteName ?: static::$currentSuite; |
|
97 | - if ( ! array_key_exists($suiteName, static::$suites) ) |
|
96 | + $suiteName = $suiteName ?: static::$currentSuite; |
|
97 | + if ( ! array_key_exists($suiteName, static::$suites)) |
|
98 | 98 | { |
99 | 99 | return static::suite($suiteName); |
100 | 100 | } |
101 | 101 | |
102 | - return static::$suites[$suiteName]; |
|
102 | + return static::$suites[ $suiteName ]; |
|
103 | 103 | } |
104 | 104 | |
105 | 105 | |
@@ -116,22 +116,22 @@ discard block |
||
116 | 116 | |
117 | 117 | $className = array_values(array_diff_key(get_declared_classes(), $declaredClasses)); |
118 | 118 | |
119 | - $reflectionClass = new \ReflectionClass($className[0]); |
|
119 | + $reflectionClass = new \ReflectionClass($className[ 0 ]); |
|
120 | 120 | $publicMethods = $reflectionClass->getMethods(\ReflectionMethod::IS_PUBLIC); |
121 | 121 | $fullClassName = $reflectionClass->getName(); |
122 | 122 | $className = $reflectionClass->getShortName(); |
123 | 123 | $namespace = $reflectionClass->getNamespaceName(); |
124 | 124 | $constructorParams = ''; |
125 | - foreach ( $publicMethods as $method ) |
|
125 | + foreach ($publicMethods as $method) |
|
126 | 126 | { |
127 | - if ( $method->isConstructor() ) |
|
127 | + if ($method->isConstructor()) |
|
128 | 128 | { |
129 | - $constructorParams = static::getMethodParams($method); |
|
129 | + $constructorParams = static::getMethodParams($method); |
|
130 | 130 | } |
131 | 131 | } |
132 | 132 | $objectInit = "new {$fullClassName}({$constructorParams})"; |
133 | - $output = []; |
|
134 | - $output[] = <<<PHP |
|
133 | + $output = [ ]; |
|
134 | + $output[ ] = <<<PHP |
|
135 | 135 | <?php declare(strict_types=1); |
136 | 136 | |
137 | 137 | namespace {$namespace}\Test; |
@@ -145,22 +145,22 @@ discard block |
||
145 | 145 | ->fixture('testSubject', {$objectInit}) |
146 | 146 | PHP; |
147 | 147 | |
148 | - foreach ( $publicMethods as $method ) |
|
148 | + foreach ($publicMethods as $method) |
|
149 | 149 | { |
150 | 150 | $methodName = $method->getName(); |
151 | 151 | $methodParams = static::getMethodParams($method); |
152 | - $testName = 'test' . ucfirst($methodName); |
|
152 | + $testName = 'test'.ucfirst($methodName); |
|
153 | 153 | $successArgs = static::getMethodArgs($method); |
154 | 154 | $failArgs = static::getMethodArgs($method, ' '); |
155 | 155 | $returnVal = static::getReturnVal($method); |
156 | 156 | $methodSignature = "\$suite->getFixture('testSubject')->{$methodName}({$methodParams})"; |
157 | 157 | |
158 | - if ( $method->isStatic() ) |
|
158 | + if ($method->isStatic()) |
|
159 | 159 | { |
160 | 160 | $methodSignature = "{$className}::{$methodName}({$methodParams})"; |
161 | 161 | } |
162 | 162 | |
163 | - $output[] = <<<PHP |
|
163 | + $output[ ] = <<<PHP |
|
164 | 164 | |
165 | 165 | ->test('{$testName}Success', function(Suite \$suite) { |
166 | 166 | |
@@ -184,7 +184,7 @@ discard block |
||
184 | 184 | |
185 | 185 | } |
186 | 186 | |
187 | - $output[] = " ;"; |
|
187 | + $output[ ] = " ;"; |
|
188 | 188 | |
189 | 189 | return static::createDirectoriesAndSaveFile($outputPath, implode("\n", $output)); |
190 | 190 | } |
@@ -197,7 +197,7 @@ discard block |
||
197 | 197 | * @param int $dirMode |
198 | 198 | * @return bool |
199 | 199 | */ |
200 | - protected static function createDirectoriesAndSaveFile(string $filePath, $data, $flags=0, $dirMode=0755) : bool |
|
200 | + protected static function createDirectoriesAndSaveFile(string $filePath, $data, $flags = 0, $dirMode = 0755) : bool |
|
201 | 201 | { |
202 | 202 | static::createParentDirectories($filePath, $dirMode); |
203 | 203 | Assert::that(file_put_contents($filePath, $data, $flags))->notFalse("Failed to put contents in file ({$filePath})"); |
@@ -210,13 +210,13 @@ discard block |
||
210 | 210 | * @param int $mode |
211 | 211 | * @return bool |
212 | 212 | */ |
213 | - protected static function createParentDirectories(string $filePath, $mode=0755) : bool |
|
213 | + protected static function createParentDirectories(string $filePath, $mode = 0755) : bool |
|
214 | 214 | { |
215 | - $directoryPath = preg_match('/.*\//', $filePath); |
|
215 | + $directoryPath = preg_match('/.*\//', $filePath); |
|
216 | 216 | Assert::that($filePath) |
217 | 217 | ->notEmpty("Failed to identify path ({$directoryPath}) to create") |
218 | 218 | ->notEq(DIRECTORY_SEPARATOR, "Failed to identify path ({$directoryPath}) to create"); |
219 | - if ( file_exists($directoryPath) ) |
|
219 | + if (file_exists($directoryPath)) |
|
220 | 220 | { |
221 | 221 | Assert::that(is_dir($directoryPath))->notFalse("Failed to create parent directories.. files exists and is not a directory({$directoryPath})"); |
222 | 222 | |
@@ -234,10 +234,10 @@ discard block |
||
234 | 234 | */ |
235 | 235 | protected static function getMethodParams(\ReflectionMethod $method) : string |
236 | 236 | { |
237 | - $output = []; |
|
238 | - foreach ( $method->getParameters() as $param ) |
|
237 | + $output = [ ]; |
|
238 | + foreach ($method->getParameters() as $param) |
|
239 | 239 | { |
240 | - $output[] = '$' . $param->getName(); |
|
240 | + $output[ ] = '$'.$param->getName(); |
|
241 | 241 | } |
242 | 242 | |
243 | 243 | return implode(', ', $output); |
@@ -248,16 +248,16 @@ discard block |
||
248 | 248 | * @param string $extraPadding |
249 | 249 | * @return string |
250 | 250 | */ |
251 | - protected static function getMethodArgs(\ReflectionMethod $method, string $extraPadding='') : string |
|
251 | + protected static function getMethodArgs(\ReflectionMethod $method, string $extraPadding = '') : string |
|
252 | 252 | { |
253 | - $output = []; |
|
253 | + $output = [ ]; |
|
254 | 254 | $params = $method->getParameters(); |
255 | - foreach ( $params as $param ) |
|
255 | + foreach ($params as $param) |
|
256 | 256 | { |
257 | 257 | $type = $param->hasType() ? $param->getType()->_toString() : ''; |
258 | - $paramDef = str_pad('$' . $param->getName(), 32, ' ') . '= '; |
|
259 | - $paramDef .= static::getDefaultValue($type); |
|
260 | - $output[] = $paramDef . ';'; |
|
258 | + $paramDef = str_pad('$'.$param->getName(), 32, ' ').'= '; |
|
259 | + $paramDef .= static::getDefaultValue($type); |
|
260 | + $output[ ] = $paramDef.';'; |
|
261 | 261 | } |
262 | 262 | |
263 | 263 | return implode("\n {$extraPadding}", $output); |
@@ -280,9 +280,9 @@ discard block |
||
280 | 280 | * @param string $default |
281 | 281 | * @return string |
282 | 282 | */ |
283 | - protected static function getDefaultValue(string $type='', string $default='null') : string |
|
283 | + protected static function getDefaultValue(string $type = '', string $default = 'null') : string |
|
284 | 284 | { |
285 | - $typeMap = [ |
|
285 | + $typeMap = [ |
|
286 | 286 | 'int' => "0", |
287 | 287 | 'float' => "0.0", |
288 | 288 | 'string' => "''", |
@@ -291,7 +291,7 @@ discard block |
||
291 | 291 | 'array' => "[]", |
292 | 292 | ]; |
293 | 293 | |
294 | - return $typeMap[$type] ?? $default; |
|
294 | + return $typeMap[ $type ] ?? $default; |
|
295 | 295 | } |
296 | 296 | } |
297 | 297 | |
@@ -299,10 +299,10 @@ discard block |
||
299 | 299 | class Suite |
300 | 300 | { |
301 | 301 | /** @var Test[] */ |
302 | - protected $tests = []; |
|
302 | + protected $tests = [ ]; |
|
303 | 303 | |
304 | 304 | /** @var mixed[] */ |
305 | - protected $fixtures = []; |
|
305 | + protected $fixtures = [ ]; |
|
306 | 306 | |
307 | 307 | /** @var Logger */ |
308 | 308 | protected $logger = null; |
@@ -310,12 +310,12 @@ discard block |
||
310 | 310 | /** |
311 | 311 | * @param string $filter |
312 | 312 | */ |
313 | - public function run(string $filter='') |
|
313 | + public function run(string $filter = '') |
|
314 | 314 | { |
315 | - foreach ( $this->tests as $test => $testCase ) |
|
315 | + foreach ($this->tests as $test => $testCase) |
|
316 | 316 | { |
317 | - $testName = $testCase->getTestName(); |
|
318 | - if ( $filter && $test !== $filter ) |
|
317 | + $testName = $testCase->getTestName(); |
|
318 | + if ($filter && $test !== $filter) |
|
319 | 319 | { |
320 | 320 | continue; |
321 | 321 | } |
@@ -323,33 +323,33 @@ discard block |
||
323 | 323 | { |
324 | 324 | $this->getLogger()->info("[{$testName}] - Starting..."); |
325 | 325 | $testCase->runTest($this); |
326 | - $this->getLogger()->info("[{$testName}] - " . $testCase->getSuccessMessage()); |
|
326 | + $this->getLogger()->info("[{$testName}] - ".$testCase->getSuccessMessage()); |
|
327 | 327 | } |
328 | - catch ( \Exception $e ) |
|
328 | + catch (\Exception $e) |
|
329 | 329 | { |
330 | 330 | $expectedCode = $testCase->getExceptionCode(); |
331 | 331 | $expectedClass = $testCase->getExceptionType(); |
332 | 332 | $code = $e->getCode(); |
333 | 333 | $exception = get_class($e); |
334 | - if ( ! $expectedClass && ! $expectedCode ) |
|
334 | + if ( ! $expectedClass && ! $expectedCode) |
|
335 | 335 | { |
336 | - $this->getLogger()->error($e->getMessage(), [compact('testName'), $e]); |
|
336 | + $this->getLogger()->error($e->getMessage(), [ compact('testName'), $e ]); |
|
337 | 337 | |
338 | 338 | continue; |
339 | 339 | } |
340 | - if ( $expectedCode && $expectedCode !== $code ) |
|
340 | + if ($expectedCode && $expectedCode !== $code) |
|
341 | 341 | { |
342 | - $this->getLogger()->error("Exception code({$code}) was expected to be ({$expectedCode})", [compact('testName'), $e]); |
|
342 | + $this->getLogger()->error("Exception code({$code}) was expected to be ({$expectedCode})", [ compact('testName'), $e ]); |
|
343 | 343 | |
344 | 344 | continue; |
345 | 345 | } |
346 | - if ( $expectedClass && $expectedClass !== $exception ) |
|
346 | + if ($expectedClass && $expectedClass !== $exception) |
|
347 | 347 | { |
348 | - $this->getLogger()->error("Exception class({$exception}) was expected to be ({$expectedClass})", [compact('testName'), $e]); |
|
348 | + $this->getLogger()->error("Exception class({$exception}) was expected to be ({$expectedClass})", [ compact('testName'), $e ]); |
|
349 | 349 | |
350 | 350 | continue; |
351 | 351 | } |
352 | - $this->getLogger()->info("[{$test}] - " . $testCase->getSuccessMessage()); |
|
352 | + $this->getLogger()->info("[{$test}] - ".$testCase->getSuccessMessage()); |
|
353 | 353 | } |
354 | 354 | } |
355 | 355 | } |
@@ -363,9 +363,9 @@ discard block |
||
363 | 363 | * @return Suite |
364 | 364 | * @throws AssertionFailedException |
365 | 365 | */ |
366 | - public function test(string $testName, Closure $test, string $successMessage='', int $exceptionCode=0, string $exceptionClass='') : Suite |
|
366 | + public function test(string $testName, Closure $test, string $successMessage = '', int $exceptionCode = 0, string $exceptionClass = '') : Suite |
|
367 | 367 | { |
368 | - $this->tests[] = new Test($testName, $test, $successMessage, $exceptionCode, $exceptionClass); |
|
368 | + $this->tests[ ] = new Test($testName, $test, $successMessage, $exceptionCode, $exceptionClass); |
|
369 | 369 | |
370 | 370 | return $this; |
371 | 371 | } |
@@ -377,7 +377,7 @@ discard block |
||
377 | 377 | */ |
378 | 378 | public function fixture(string $fixtureName, $value) : Suite |
379 | 379 | { |
380 | - $this->fixtures[$fixtureName] = $value; |
|
380 | + $this->fixtures[ $fixtureName ] = $value; |
|
381 | 381 | |
382 | 382 | return $this; |
383 | 383 | } |
@@ -391,7 +391,7 @@ discard block |
||
391 | 391 | { |
392 | 392 | Assert::that($this->fixtures)->keyExists($fixtureName, "The fixture ({$fixtureName}) does not exist."); |
393 | 393 | |
394 | - return $this->fixtures[$fixtureName]; |
|
394 | + return $this->fixtures[ $fixtureName ]; |
|
395 | 395 | } |
396 | 396 | |
397 | 397 | |
@@ -411,7 +411,7 @@ discard block |
||
411 | 411 | */ |
412 | 412 | public function getLogger() : Logger |
413 | 413 | { |
414 | - if ( ! $this->logger ) |
|
414 | + if ( ! $this->logger) |
|
415 | 415 | { |
416 | 416 | $this->logger = new Logger(); |
417 | 417 | } |
@@ -448,7 +448,7 @@ discard block |
||
448 | 448 | * @param string $exceptionClass |
449 | 449 | * @throws AssertionFailedException |
450 | 450 | */ |
451 | - public function __construct(string $testName, Closure $test, string $successMessage='', int $exceptionCode=0, string $exceptionClass='') |
|
451 | + public function __construct(string $testName, Closure $test, string $successMessage = '', int $exceptionCode = 0, string $exceptionClass = '') |
|
452 | 452 | { |
453 | 453 | $this->setTestName($testName); |
454 | 454 | $this->setTest($test); |
@@ -483,7 +483,7 @@ discard block |
||
483 | 483 | */ |
484 | 484 | public function getSuccessMessage() : string |
485 | 485 | { |
486 | - if ( ! $this->successMessage ) |
|
486 | + if ( ! $this->successMessage) |
|
487 | 487 | { |
488 | 488 | return "Successfully run {$this->testName}"; |
489 | 489 | } |
@@ -636,21 +636,21 @@ discard block |
||
636 | 636 | /** |
637 | 637 | * @var array $logLevels List of supported levels |
638 | 638 | */ |
639 | - static protected $logLevels = [ |
|
640 | - self::EMERGENCY => [1, self::WHITE, self::RED, self::DEFAULT, 'EMERG'], |
|
641 | - self::ALERT => [2, self::WHITE, self::YELLOW, self::DEFAULT, 'ALERT'], |
|
642 | - self::CRITICAL => [3, self::RED, self::DEFAULT, self::BOLD , 'CRIT'], |
|
643 | - self::ERROR => [4, self::RED, self::DEFAULT, self::DEFAULT, 'ERROR'], |
|
644 | - self::WARNING => [5, self::YELLOW, self::DEFAULT, self::DEFAULT, 'WARN'], |
|
645 | - self::NOTICE => [6, self::CYAN, self::DEFAULT, self::DEFAULT, 'NOTE'], |
|
646 | - self::INFO => [7, self::GREEN, self::DEFAULT, self::DEFAULT, 'INFO'], |
|
647 | - self::DEBUG => [8, self::LIGHT_GRAY, self::DEFAULT, self::DEFAULT, 'DEBUG'], |
|
639 | + static protected $logLevels = [ |
|
640 | + self::EMERGENCY => [ 1, self::WHITE, self::RED, self::DEFAULT, 'EMERG' ], |
|
641 | + self::ALERT => [ 2, self::WHITE, self::YELLOW, self::DEFAULT, 'ALERT' ], |
|
642 | + self::CRITICAL => [ 3, self::RED, self::DEFAULT, self::BOLD, 'CRIT' ], |
|
643 | + self::ERROR => [ 4, self::RED, self::DEFAULT, self::DEFAULT, 'ERROR' ], |
|
644 | + self::WARNING => [ 5, self::YELLOW, self::DEFAULT, self::DEFAULT, 'WARN' ], |
|
645 | + self::NOTICE => [ 6, self::CYAN, self::DEFAULT, self::DEFAULT, 'NOTE' ], |
|
646 | + self::INFO => [ 7, self::GREEN, self::DEFAULT, self::DEFAULT, 'INFO' ], |
|
647 | + self::DEBUG => [ 8, self::LIGHT_GRAY, self::DEFAULT, self::DEFAULT, 'DEBUG' ], |
|
648 | 648 | ]; |
649 | 649 | |
650 | 650 | /** |
651 | 651 | * @var array |
652 | 652 | */ |
653 | - static protected $colours = [ |
|
653 | + static protected $colours = [ |
|
654 | 654 | 'fore' => [ |
655 | 655 | self::BLACK => '0;30', |
656 | 656 | self::DARK_GRAY => '1;30', |
@@ -681,7 +681,7 @@ discard block |
||
681 | 681 | self::CYAN => '46', |
682 | 682 | self::LIGHT_GRAY => '47', |
683 | 683 | ], |
684 | - self::BOLD => [], |
|
684 | + self::BOLD => [ ], |
|
685 | 685 | ]; |
686 | 686 | |
687 | 687 | /** |
@@ -691,7 +691,7 @@ discard block |
||
691 | 691 | * @param bool $gzipFile |
692 | 692 | * @param bool $addDate |
693 | 693 | */ |
694 | - public function __construct($resource=STDOUT, string $level=self::INFO, bool $useLocking=false, bool $gzipFile=false, bool $addDate=true) |
|
694 | + public function __construct($resource = STDOUT, string $level = self::INFO, bool $useLocking = false, bool $gzipFile = false, bool $addDate = true) |
|
695 | 695 | { |
696 | 696 | $this->resource = $resource; |
697 | 697 | $this->setLogLevel($level); |
@@ -706,7 +706,7 @@ discard block |
||
706 | 706 | * @param string $message |
707 | 707 | * @param array $context |
708 | 708 | */ |
709 | - public function emergency(string $message, array $context=[]) |
|
709 | + public function emergency(string $message, array $context = [ ]) |
|
710 | 710 | { |
711 | 711 | $this->log(self::EMERGENCY, $message, $context); |
712 | 712 | } |
@@ -720,7 +720,7 @@ discard block |
||
720 | 720 | * @param string $message |
721 | 721 | * @param array $context |
722 | 722 | */ |
723 | - public function alert(string $message, array $context=[]) |
|
723 | + public function alert(string $message, array $context = [ ]) |
|
724 | 724 | { |
725 | 725 | $this->log(self::ALERT, $message, $context); |
726 | 726 | } |
@@ -733,7 +733,7 @@ discard block |
||
733 | 733 | * @param string $message |
734 | 734 | * @param array $context |
735 | 735 | */ |
736 | - public function critical(string $message, array $context=[]) |
|
736 | + public function critical(string $message, array $context = [ ]) |
|
737 | 737 | { |
738 | 738 | $this->log(self::CRITICAL, $message, $context); |
739 | 739 | } |
@@ -745,7 +745,7 @@ discard block |
||
745 | 745 | * @param string $message |
746 | 746 | * @param array $context |
747 | 747 | */ |
748 | - public function error(string $message, array $context=[]) |
|
748 | + public function error(string $message, array $context = [ ]) |
|
749 | 749 | { |
750 | 750 | $this->log(self::ERROR, $message, $context); |
751 | 751 | } |
@@ -759,7 +759,7 @@ discard block |
||
759 | 759 | * @param string $message |
760 | 760 | * @param array $context |
761 | 761 | */ |
762 | - public function warning(string $message, array $context=[]) |
|
762 | + public function warning(string $message, array $context = [ ]) |
|
763 | 763 | { |
764 | 764 | $this->log(self::WARNING, $message, $context); |
765 | 765 | } |
@@ -770,7 +770,7 @@ discard block |
||
770 | 770 | * @param string $message |
771 | 771 | * @param array $context |
772 | 772 | */ |
773 | - public function notice(string $message, array $context=[]) |
|
773 | + public function notice(string $message, array $context = [ ]) |
|
774 | 774 | { |
775 | 775 | $this->log(self::NOTICE, $message, $context); |
776 | 776 | } |
@@ -783,7 +783,7 @@ discard block |
||
783 | 783 | * @param string $message |
784 | 784 | * @param array $context |
785 | 785 | */ |
786 | - public function info(string $message, array $context=[]) |
|
786 | + public function info(string $message, array $context = [ ]) |
|
787 | 787 | { |
788 | 788 | $this->log(self::INFO, $message, $context); |
789 | 789 | } |
@@ -794,7 +794,7 @@ discard block |
||
794 | 794 | * @param string $message |
795 | 795 | * @param array $context |
796 | 796 | */ |
797 | - public function debug(string $message, array $context=[]) |
|
797 | + public function debug(string $message, array $context = [ ]) |
|
798 | 798 | { |
799 | 799 | $this->log(self::DEBUG, $message, $context); |
800 | 800 | } |
@@ -805,7 +805,7 @@ discard block |
||
805 | 805 | */ |
806 | 806 | public function setLogFile($resource) : Logger |
807 | 807 | { |
808 | - $this->resource = $resource; |
|
808 | + $this->resource = $resource; |
|
809 | 809 | |
810 | 810 | return $this; |
811 | 811 | } |
@@ -817,23 +817,23 @@ discard block |
||
817 | 817 | * @param bool $bold |
818 | 818 | * @return string |
819 | 819 | */ |
820 | - public static function addColour(string $string, string $foregroundColor='', string $backgroundColor='', bool $bold=false) : string |
|
820 | + public static function addColour(string $string, string $foregroundColor = '', string $backgroundColor = '', bool $bold = false) : string |
|
821 | 821 | { |
822 | 822 | // todo: support bold |
823 | 823 | unset($bold); |
824 | 824 | $coloredString = ''; |
825 | 825 | // Check if given foreground color found |
826 | - if ( isset(static::$colours['fore'][$foregroundColor]) ) |
|
826 | + if (isset(static::$colours[ 'fore' ][ $foregroundColor ])) |
|
827 | 827 | { |
828 | - $coloredString .= "\033[" . static::$colours['fore'][$foregroundColor] . "m"; |
|
828 | + $coloredString .= "\033[".static::$colours[ 'fore' ][ $foregroundColor ]."m"; |
|
829 | 829 | } |
830 | 830 | // Check if given background color found |
831 | - if ( isset(static::$colours['back'][$backgroundColor]) ) |
|
831 | + if (isset(static::$colours[ 'back' ][ $backgroundColor ])) |
|
832 | 832 | { |
833 | - $coloredString .= "\033[" . static::$colours['back'][$backgroundColor] . "m"; |
|
833 | + $coloredString .= "\033[".static::$colours[ 'back' ][ $backgroundColor ]."m"; |
|
834 | 834 | } |
835 | 835 | // Add string and end coloring |
836 | - $coloredString .= $string . "\033[0m"; |
|
836 | + $coloredString .= $string."\033[0m"; |
|
837 | 837 | |
838 | 838 | return $coloredString; |
839 | 839 | } |
@@ -845,7 +845,7 @@ discard block |
||
845 | 845 | * @param bool $bold |
846 | 846 | * @return string |
847 | 847 | */ |
848 | - public function colourize(string $string, string $foregroundColor='', string $backgroundColor='', bool $bold=false) : string |
|
848 | + public function colourize(string $string, string $foregroundColor = '', string $backgroundColor = '', bool $bold = false) : string |
|
849 | 849 | { |
850 | 850 | return static::addColour($string, $foregroundColor, $backgroundColor, $bold); |
851 | 851 | } |
@@ -856,11 +856,11 @@ discard block |
||
856 | 856 | */ |
857 | 857 | public function setLogLevel(string $level) : Logger |
858 | 858 | { |
859 | - if ( ! isset(static::$logLevels[$level]) ) |
|
859 | + if ( ! isset(static::$logLevels[ $level ])) |
|
860 | 860 | { |
861 | 861 | throw new \InvalidArgumentException("Log level is invalid"); |
862 | 862 | } |
863 | - $this->level = static::$logLevels[$level][0]; |
|
863 | + $this->level = static::$logLevels[ $level ][ 0 ]; |
|
864 | 864 | |
865 | 865 | return $this; |
866 | 866 | } |
@@ -904,25 +904,25 @@ discard block |
||
904 | 904 | * @param string|object $message If an object is passed it must implement __toString() |
905 | 905 | * @param array $context Placeholders to be substituted in the message |
906 | 906 | */ |
907 | - public function log($level, $message, array $context=[]) |
|
907 | + public function log($level, $message, array $context = [ ]) |
|
908 | 908 | { |
909 | - $level = isset(static::$logLevels[$level]) ? $level : self::INFO; |
|
910 | - list($logLevel, $fore, $back, $style) = static::$logLevels[$level]; |
|
909 | + $level = isset(static::$logLevels[ $level ]) ? $level : self::INFO; |
|
910 | + list($logLevel, $fore, $back, $style) = static::$logLevels[ $level ]; |
|
911 | 911 | unset($style); |
912 | - if ( $logLevel > $this->level ) |
|
912 | + if ($logLevel > $this->level) |
|
913 | 913 | { |
914 | - return ; |
|
914 | + return; |
|
915 | 915 | } |
916 | - if ( is_callable($this->formatter) ) |
|
916 | + if (is_callable($this->formatter)) |
|
917 | 917 | { |
918 | - $message = $this->formatter->__invoke(static::$logLevels[$level][4], $message, $context); |
|
918 | + $message = $this->formatter->__invoke(static::$logLevels[ $level ][ 4 ], $message, $context); |
|
919 | 919 | } |
920 | 920 | else |
921 | 921 | { |
922 | 922 | $message = $this->formatMessage($level, $message, $context); |
923 | 923 | } |
924 | 924 | $this->lastLogEntry = $message; |
925 | - $this->write($this->colourize($message, $fore, $back) . PHP_EOL); |
|
925 | + $this->write($this->colourize($message, $fore, $back).PHP_EOL); |
|
926 | 926 | } |
927 | 927 | |
928 | 928 | /** |
@@ -932,8 +932,8 @@ discard block |
||
932 | 932 | */ |
933 | 933 | public static function style(string $style, string $message) : string |
934 | 934 | { |
935 | - $style = isset(static::$logLevels[$style]) ? $style : self::INFO; |
|
936 | - list($logLevel, $fore, $back, $style) = static::$logLevels[$style]; |
|
935 | + $style = isset(static::$logLevels[ $style ]) ? $style : self::INFO; |
|
936 | + list($logLevel, $fore, $back, $style) = static::$logLevels[ $style ]; |
|
937 | 937 | unset($logLevel, $style); |
938 | 938 | |
939 | 939 | return static::addColour($message, $fore, $back); |
@@ -945,14 +945,14 @@ discard block |
||
945 | 945 | * @param array $context |
946 | 946 | * @return string |
947 | 947 | */ |
948 | - protected function formatMessage(string $level, string $message, array $context=[]) : string |
|
948 | + protected function formatMessage(string $level, string $message, array $context = [ ]) : string |
|
949 | 949 | { |
950 | 950 | # Handle objects implementing __toString |
951 | - $message = (string) $message; |
|
952 | - $message .= empty($context) ? '' : PHP_EOL . json_encode($context, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES); |
|
953 | - $data = $this->addDate ? ['date' => date('Y-m-d H:i:s')] : []; |
|
954 | - $data['level'] = strtoupper(str_pad(static::$logLevels[$level][4], 5, ' ', STR_PAD_RIGHT)); |
|
955 | - $data['message'] = $message; |
|
951 | + $message = (string)$message; |
|
952 | + $message .= empty($context) ? '' : PHP_EOL.json_encode($context, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES); |
|
953 | + $data = $this->addDate ? [ 'date' => date('Y-m-d H:i:s') ] : [ ]; |
|
954 | + $data[ 'level' ] = strtoupper(str_pad(static::$logLevels[ $level ][ 4 ], 5, ' ', STR_PAD_RIGHT)); |
|
955 | + $data[ 'message' ] = $message; |
|
956 | 956 | |
957 | 957 | return implode($this->separator, $data); |
958 | 958 | } |
@@ -965,12 +965,12 @@ discard block |
||
965 | 965 | public function write(string $content) |
966 | 966 | { |
967 | 967 | $resource = $this->getResource(); |
968 | - if ( $this->useLocking ) |
|
968 | + if ($this->useLocking) |
|
969 | 969 | { |
970 | 970 | flock($resource, LOCK_EX); |
971 | 971 | } |
972 | 972 | gzwrite($resource, $content); |
973 | - if ( $this->useLocking ) |
|
973 | + if ($this->useLocking) |
|
974 | 974 | { |
975 | 975 | flock($resource, LOCK_UN); |
976 | 976 | } |
@@ -982,14 +982,14 @@ discard block |
||
982 | 982 | */ |
983 | 983 | protected function getResource() |
984 | 984 | { |
985 | - if ( is_resource($this->resource) ) |
|
985 | + if (is_resource($this->resource)) |
|
986 | 986 | { |
987 | 987 | return $this->resource; |
988 | 988 | } |
989 | 989 | $fileName = $this->resource; |
990 | 990 | $this->closeLocally = true; |
991 | 991 | $this->resource = $this->openResource(); |
992 | - if ( ! is_resource($this->resource) ) |
|
992 | + if ( ! is_resource($this->resource)) |
|
993 | 993 | { |
994 | 994 | throw new \Exception("The resource ({$fileName}) could not be opened"); |
995 | 995 | } |
@@ -1010,7 +1010,7 @@ discard block |
||
1010 | 1010 | */ |
1011 | 1011 | protected function openResource() |
1012 | 1012 | { |
1013 | - if ( $this->gzipFile ) |
|
1013 | + if ($this->gzipFile) |
|
1014 | 1014 | { |
1015 | 1015 | return gzopen($this->resource, 'a'); |
1016 | 1016 | } |
@@ -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 | } |
@@ -32,14 +32,14 @@ discard block |
||
32 | 32 | |
33 | 33 | public static function runTests(string $fileName, string $suite, string $test, bool $recursive) |
34 | 34 | { |
35 | - $tests = static::getTestFiles($fileName, $recursive); |
|
36 | - if ( empty($tests) ) |
|
35 | + $tests = static::getTestFiles($fileName, $recursive); |
|
36 | + if (empty($tests)) |
|
37 | 37 | { |
38 | 38 | Tester::getLogger()->error("No test files found/specified"); |
39 | 39 | |
40 | 40 | exit(1); |
41 | 41 | } |
42 | - foreach ( $tests as $fileName ) |
|
42 | + foreach ($tests as $fileName) |
|
43 | 43 | { |
44 | 44 | Tester::getLogger()->debug("Loading test file {$fileName}"); |
45 | 45 | require($fileName); |
@@ -54,46 +54,46 @@ discard block |
||
54 | 54 | * @param bool $recursive |
55 | 55 | * @return array |
56 | 56 | */ |
57 | - protected static function getTestFiles(string $fileName='', bool $recursive=false) : array |
|
57 | + protected static function getTestFiles(string $fileName = '', bool $recursive = false) : array |
|
58 | 58 | { |
59 | - if ( empty($fileName) ) |
|
59 | + if (empty($fileName)) |
|
60 | 60 | { |
61 | - return []; |
|
61 | + return [ ]; |
|
62 | 62 | } |
63 | - if ( ! file_exists($fileName) ) |
|
63 | + if ( ! file_exists($fileName)) |
|
64 | 64 | { |
65 | 65 | Tester::getLogger()->error("{$fileName} does not exist; exiting"); |
66 | 66 | |
67 | 67 | exit(1); |
68 | 68 | } |
69 | - $fileName = realpath($fileName); |
|
70 | - if ( is_dir($fileName) ) |
|
69 | + $fileName = realpath($fileName); |
|
70 | + if (is_dir($fileName)) |
|
71 | 71 | { |
72 | - $iterator = new \DirectoryIterator($fileName); |
|
73 | - if ( $recursive ) |
|
72 | + $iterator = new \DirectoryIterator($fileName); |
|
73 | + if ($recursive) |
|
74 | 74 | { |
75 | 75 | $iterator = new \RecursiveDirectoryIterator($fileName); |
76 | 76 | $iterator = $recursive ? new RecursiveIteratorIterator($iterator) : $iterator; |
77 | 77 | } |
78 | - $testFiles = []; |
|
79 | - foreach ( $iterator as $fileInfo ) |
|
78 | + $testFiles = [ ]; |
|
79 | + foreach ($iterator as $fileInfo) |
|
80 | 80 | { |
81 | - if ( preg_match('/Suite.php$/', $fileInfo->getBasename()) ) |
|
81 | + if (preg_match('/Suite.php$/', $fileInfo->getBasename())) |
|
82 | 82 | { |
83 | - $testFiles[] = $fileInfo->getPathname(); |
|
83 | + $testFiles[ ] = $fileInfo->getPathname(); |
|
84 | 84 | } |
85 | 85 | } |
86 | 86 | |
87 | 87 | return $testFiles; |
88 | 88 | } |
89 | - if ( ! is_file($fileName) ) |
|
89 | + if ( ! is_file($fileName)) |
|
90 | 90 | { |
91 | 91 | Tester::getLogger()->error("{$fileName} is not a file; exiting"); |
92 | 92 | |
93 | 93 | exit(1); |
94 | 94 | } |
95 | 95 | |
96 | - return [$fileName]; |
|
96 | + return [ $fileName ]; |
|
97 | 97 | } |
98 | 98 | |
99 | 99 | /** |
@@ -146,16 +146,16 @@ discard block |
||
146 | 146 | * @param array $argv |
147 | 147 | * @return array |
148 | 148 | */ |
149 | - protected static function parseArgs(array $argv=[]) : array |
|
149 | + protected static function parseArgs(array $argv = [ ]) : array |
|
150 | 150 | { |
151 | - $argv = $argv ?: ! empty($_SERVER['argv']) ? $_SERVER['argv'] : []; |
|
151 | + $argv = $argv ?: ! empty($_SERVER[ 'argv' ]) ? $_SERVER[ 'argv' ] : [ ]; |
|
152 | 152 | array_shift($argv); |
153 | - $out = []; |
|
154 | - for ( $i = 0, $j = count($argv); $i < $j; $i++ ) |
|
153 | + $out = [ ]; |
|
154 | + for ($i = 0, $j = count($argv); $i < $j; $i++) |
|
155 | 155 | { |
156 | - $arg = $argv[$i]; |
|
156 | + $arg = $argv[ $i ]; |
|
157 | 157 | // --foo --bar=baz |
158 | - if ( mb_substr($arg, 0, 2) === '--' ) |
|
158 | + if (mb_substr($arg, 0, 2) === '--') |
|
159 | 159 | { |
160 | 160 | $eqPos = mb_strpos($arg, '='); |
161 | 161 | // --foo |
@@ -163,23 +163,23 @@ discard block |
||
163 | 163 | { |
164 | 164 | $key = mb_substr($arg, 2); |
165 | 165 | // --foo value |
166 | - if ($i + 1 < $j && $argv[$i + 1][0] !== '-') |
|
166 | + if ($i + 1 < $j && $argv[ $i + 1 ][ 0 ] !== '-') |
|
167 | 167 | { |
168 | - $value = $argv[$i + 1]; |
|
168 | + $value = $argv[ $i + 1 ]; |
|
169 | 169 | $i++; |
170 | 170 | } |
171 | 171 | else |
172 | 172 | { |
173 | - $value = isset($out[$key]) ? $out[$key] : true; |
|
173 | + $value = isset($out[ $key ]) ? $out[ $key ] : true; |
|
174 | 174 | } |
175 | - $out[$key] = $value; |
|
175 | + $out[ $key ] = $value; |
|
176 | 176 | } |
177 | 177 | // --bar=baz |
178 | 178 | else |
179 | 179 | { |
180 | 180 | $key = mb_substr($arg, 2, $eqPos - 2); |
181 | 181 | $value = mb_substr($arg, $eqPos + 1); |
182 | - $out[$key] = $value; |
|
182 | + $out[ $key ] = $value; |
|
183 | 183 | } |
184 | 184 | } |
185 | 185 | // -k=value -abc |
@@ -190,23 +190,23 @@ discard block |
||
190 | 190 | { |
191 | 191 | $key = mb_substr($arg, 1, 1); |
192 | 192 | $value = mb_substr($arg, 3); |
193 | - $out[$key] = $value; |
|
193 | + $out[ $key ] = $value; |
|
194 | 194 | } |
195 | 195 | // -abc |
196 | 196 | else |
197 | 197 | { |
198 | 198 | $chars = str_split(mb_substr($arg, 1)); |
199 | 199 | $key = ''; |
200 | - foreach ( $chars as $char ) |
|
200 | + foreach ($chars as $char) |
|
201 | 201 | { |
202 | 202 | $key = $char; |
203 | - $value = isset($out[$key]) ? $out[$key] : true; |
|
204 | - $out[$key] = $value; |
|
203 | + $value = isset($out[ $key ]) ? $out[ $key ] : true; |
|
204 | + $out[ $key ] = $value; |
|
205 | 205 | } |
206 | 206 | // -a value1 -abc value2 |
207 | - if ($i + 1 < $j && $argv[$i + 1][0] !== '-') |
|
207 | + if ($i + 1 < $j && $argv[ $i + 1 ][ 0 ] !== '-') |
|
208 | 208 | { |
209 | - $out[$key] = $argv[$i + 1]; |
|
209 | + $out[ $key ] = $argv[ $i + 1 ]; |
|
210 | 210 | $i++; |
211 | 211 | } |
212 | 212 | } |
@@ -215,14 +215,14 @@ discard block |
||
215 | 215 | else |
216 | 216 | { |
217 | 217 | $value = $arg; |
218 | - $out[] = $value; |
|
218 | + $out[ ] = $value; |
|
219 | 219 | } |
220 | 220 | } |
221 | - foreach ( $out as $idx => $val ) |
|
221 | + foreach ($out as $idx => $val) |
|
222 | 222 | { |
223 | - if ( is_string($val) && strpos($val, '|') !== false ) |
|
223 | + if (is_string($val) && strpos($val, '|') !== false) |
|
224 | 224 | { |
225 | - $out[$idx] = explode('|', $val); |
|
225 | + $out[ $idx ] = explode('|', $val); |
|
226 | 226 | } |
227 | 227 | } |
228 | 228 | |
@@ -234,11 +234,11 @@ discard block |
||
234 | 234 | * @param mixed $default |
235 | 235 | * @return string |
236 | 236 | */ |
237 | - protected static function getArg($name, $default=null) |
|
237 | + protected static function getArg($name, $default = null) |
|
238 | 238 | { |
239 | 239 | $args = static::parseArgs(); |
240 | 240 | |
241 | - return isset($args[$name]) && $args[$name] ? $args[$name] : $default; |
|
241 | + return isset($args[ $name ]) && $args[ $name ] ? $args[ $name ] : $default; |
|
242 | 242 | } |
243 | 243 | |
244 | 244 | } |