o2system /
gear
| 1 | <?php |
||
| 2 | /** |
||
| 3 | * This file is part of the O2System Framework package. |
||
| 4 | * |
||
| 5 | * For the full copyright and license information, please view the LICENSE |
||
| 6 | * file that was distributed with this source code. |
||
| 7 | * |
||
| 8 | * @author Steeve Andrian Salim |
||
| 9 | * @copyright Copyright (c) Steeve Andrian Salim |
||
| 10 | */ |
||
| 11 | |||
| 12 | // ------------------------------------------------------------------------ |
||
| 13 | |||
| 14 | namespace O2System\Gear; |
||
| 15 | |||
| 16 | // ------------------------------------------------------------------------ |
||
| 17 | |||
| 18 | use O2System\Spl\Iterators\ArrayIterator; |
||
|
0 ignored issues
–
show
|
|||
| 19 | |||
| 20 | /** |
||
| 21 | * Class UnitTesting |
||
| 22 | * |
||
| 23 | * @package O2System\Gear |
||
| 24 | */ |
||
| 25 | class UnitTesting |
||
| 26 | { |
||
| 27 | /** |
||
| 28 | * UnitTesting::$reports |
||
| 29 | * |
||
| 30 | * @var \O2System\Spl\Iterators\ArrayIterator |
||
| 31 | */ |
||
| 32 | private $reports; |
||
| 33 | |||
| 34 | // ------------------------------------------------------------------------ |
||
| 35 | |||
| 36 | /** |
||
| 37 | * UnitTesting::__construct |
||
| 38 | */ |
||
| 39 | public function __construct() |
||
| 40 | { |
||
| 41 | $this->reports = new ArrayIterator(); |
||
| 42 | } |
||
| 43 | |||
| 44 | // ------------------------------------------------------------------------ |
||
| 45 | |||
| 46 | /** |
||
| 47 | * UnitTesting::test |
||
| 48 | * |
||
| 49 | * @param string $label |
||
| 50 | * @param \Closure $closure |
||
| 51 | * @param mixed $expected |
||
| 52 | * @param string|null $notes |
||
| 53 | */ |
||
| 54 | public function test($label, $closure, $expected, $notes = null) |
||
| 55 | { |
||
| 56 | if ($closure instanceof \Closure) { |
||
|
0 ignored issues
–
show
|
|||
| 57 | $closure = call_user_func($closure, $this); |
||
| 58 | } |
||
| 59 | |||
| 60 | if (in_array($expected, [ |
||
| 61 | 'object', |
||
| 62 | 'string', |
||
| 63 | 'bool', |
||
| 64 | 'true', |
||
| 65 | 'false', |
||
| 66 | 'int', |
||
| 67 | 'integer', |
||
| 68 | 'numeric', |
||
| 69 | 'float', |
||
| 70 | 'double', |
||
| 71 | 'array', |
||
| 72 | 'null', |
||
| 73 | 'resource', |
||
| 74 | ], true)) { |
||
| 75 | $expectedDataType = $expected; |
||
| 76 | $passed = (bool)call_user_func('is_' . $expected, $closure); |
||
| 77 | } else { |
||
| 78 | $expectedDataType = gettype($expected); |
||
| 79 | $passed = (bool)($closure === $expected); |
||
| 80 | } |
||
| 81 | |||
| 82 | if (is_bool($closure)) { |
||
| 83 | $closure = ($closure === true) ? 'true' : 'false'; |
||
| 84 | } |
||
| 85 | |||
| 86 | if (is_bool($expected)) { |
||
| 87 | $expected = ($expected === true) ? 'true' : 'false'; |
||
| 88 | } |
||
| 89 | |||
| 90 | $this->reports[] = new \ArrayObject([ |
||
| 91 | 'label' => $label, |
||
| 92 | 'result' => $closure, |
||
| 93 | 'expected' => $expected, |
||
| 94 | 'datatype' => new \ArrayObject([ |
||
| 95 | 'expected' => $expectedDataType, |
||
| 96 | 'result' => gettype($closure), |
||
| 97 | ], \ArrayObject::ARRAY_AS_PROPS), |
||
| 98 | 'status' => ($passed === true) ? 'passed' : 'failed', |
||
| 99 | 'trace' => $this->getBacktrace(), |
||
| 100 | 'notes' => $notes, |
||
| 101 | ], \ArrayObject::ARRAY_AS_PROPS); |
||
| 102 | } |
||
| 103 | |||
| 104 | // ------------------------------------------------------------------------ |
||
| 105 | |||
| 106 | /** |
||
| 107 | * UnitTesting::getBacktrace |
||
| 108 | * |
||
| 109 | * @return \O2System\Gear\Trace\DataStructures\Chronology |
||
| 110 | */ |
||
| 111 | protected function getBacktrace() |
||
| 112 | { |
||
| 113 | $backtrace = debug_backtrace(); |
||
| 114 | $backtrace = $backtrace[ 1 ]; |
||
| 115 | |||
| 116 | if (isset($backtrace[ 'class' ]) AND isset($backtrace[ 'type' ])) { |
||
| 117 | $chronology[ 'call' ] = $backtrace[ 'class' ] . $backtrace[ 'type' ] . $backtrace[ 'function' ] . '()'; |
||
|
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||
| 118 | $chronology[ 'type' ] = $backtrace[ 'type' ] === '->' ? 'non-static' : 'static'; |
||
| 119 | } else { |
||
| 120 | $chronology[ 'call' ] = $backtrace[ 'function' ] . '()'; |
||
| 121 | $chronology[ 'type' ] = 'non-static'; |
||
| 122 | } |
||
| 123 | |||
| 124 | if (isset($backtrace[ 'file' ])) { |
||
| 125 | $chronology[ 'file' ] = (isset($backtrace[ 'file' ]) ? $backtrace[ 'file' ] : ''); |
||
| 126 | $chronology[ 'line' ] = (isset($backtrace[ 'line' ]) ? $backtrace[ 'line' ] : ''); |
||
| 127 | } |
||
| 128 | |||
| 129 | if (defined('PATH_ROOT')) { |
||
| 130 | $chronology[ 'file' ] = str_replace(PATH_ROOT, '', $chronology[ 'file' ]); |
||
|
0 ignored issues
–
show
|
|||
| 131 | } |
||
| 132 | |||
| 133 | return new Trace\DataStructures\Chronology($chronology); |
||
| 134 | } |
||
| 135 | |||
| 136 | // ------------------------------------------------------------------------ |
||
| 137 | |||
| 138 | /** |
||
| 139 | * UnitTesting::getReports |
||
| 140 | * |
||
| 141 | * @return \O2System\Spl\Iterators\ArrayIterator |
||
| 142 | */ |
||
| 143 | public function getReports() |
||
| 144 | { |
||
| 145 | return $this->reports; |
||
| 146 | } |
||
| 147 | |||
| 148 | // ------------------------------------------------------------------------ |
||
| 149 | |||
| 150 | /** |
||
| 151 | * UnitTesting::render |
||
| 152 | */ |
||
| 153 | public function render() |
||
| 154 | { |
||
| 155 | $reports = $this->reports; |
||
| 156 | |||
| 157 | ob_start(); |
||
| 158 | include __DIR__ . '/Views/UnitTesting.php'; |
||
| 159 | $output = ob_get_contents(); |
||
| 160 | ob_end_clean(); |
||
| 161 | |||
| 162 | echo $output; |
||
| 163 | } |
||
| 164 | } |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths