@@ -6,10 +6,10 @@ |
||
| 6 | 6 | |
| 7 | 7 | class TestClass1Input { |
| 8 | 8 | /** |
| 9 | - * @param \Bar\Foo |
|
| 10 | - * |
|
| 11 | - * @return void |
|
| 12 | - */ |
|
| 9 | + * @param \Bar\Foo |
|
| 10 | + * |
|
| 11 | + * @return void |
|
| 12 | + */ |
|
| 13 | 13 | public function replace() { |
| 14 | 14 | // A comment |
| 15 | 15 | } |
@@ -5,18 +5,18 @@ |
||
| 5 | 5 | class TestClass1Input { |
| 6 | 6 | |
| 7 | 7 | /** |
| 8 | - * @return void |
|
| 9 | - */ |
|
| 8 | + * @return void |
|
| 9 | + */ |
|
| 10 | 10 | public function replaceFunction() { |
| 11 | 11 | $foo = PHP_SAPI; |
| 12 | 12 | $foo = substr(PHP_SAPI, 0, 3); |
| 13 | 13 | } |
| 14 | 14 | |
| 15 | 15 | /** |
| 16 | - * Do not replace |
|
| 17 | - * |
|
| 18 | - * @return void |
|
| 19 | - */ |
|
| 16 | + * Do not replace |
|
| 17 | + * |
|
| 18 | + * @return void |
|
| 19 | + */ |
|
| 20 | 20 | public function php_sapi_name() { |
| 21 | 21 | $foo = $this->php_sapi_name(); |
| 22 | 22 | $foo = php_sapi_name($foo); |
@@ -40,7 +40,7 @@ |
||
| 40 | 40 | return [ |
| 41 | 41 | T_ELSE, |
| 42 | 42 | T_ELSEIF, |
| 43 | - ]; |
|
| 43 | + ]; |
|
| 44 | 44 | } |
| 45 | 45 | |
| 46 | 46 | |
@@ -62,7 +62,7 @@ |
||
| 62 | 62 | T_ELSEIF, |
| 63 | 63 | T_TRY, |
| 64 | 64 | T_CATCH, |
| 65 | - ]; |
|
| 65 | + ]; |
|
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | /** |
@@ -8,321 +8,321 @@ |
||
| 8 | 8 | */ |
| 9 | 9 | class SpeedTrapListener implements PHPUnit_Framework_TestListener |
| 10 | 10 | { |
| 11 | - /** |
|
| 12 | - * Internal tracking for test suites. |
|
| 13 | - * |
|
| 14 | - * Increments as more suites are run, then decremented as they finish. All |
|
| 15 | - * suites have been run when returns to 0. |
|
| 16 | - * |
|
| 17 | - * @var integer |
|
| 18 | - */ |
|
| 19 | - protected $suites = 0; |
|
| 20 | - |
|
| 21 | - /** |
|
| 22 | - * Time in milliseconds at which a test will be considered "slow" and be |
|
| 23 | - * reported by this listener. |
|
| 24 | - * |
|
| 25 | - * @var int |
|
| 26 | - */ |
|
| 27 | - protected $slowThreshold; |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * Number of tests to report on for slowness. |
|
| 31 | - * |
|
| 32 | - * @var int |
|
| 33 | - */ |
|
| 34 | - protected $reportLength; |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * Collection of slow tests. |
|
| 38 | - * |
|
| 39 | - * @var array |
|
| 40 | - */ |
|
| 41 | - protected $slow = array(); |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * Construct a new instance. |
|
| 45 | - * |
|
| 46 | - * @param array $options |
|
| 47 | - */ |
|
| 48 | - public function __construct(array $options = array()) |
|
| 49 | - { |
|
| 50 | - $this->loadOptions($options); |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * An error occurred. |
|
| 55 | - * |
|
| 56 | - * @param PHPUnit_Framework_Test $test |
|
| 57 | - * @param Exception $e |
|
| 58 | - * @param float $time |
|
| 59 | - */ |
|
| 60 | - public function addError(PHPUnit_Framework_Test $test, Exception $e, $time) |
|
| 61 | - { |
|
| 62 | - } |
|
| 63 | - |
|
| 64 | - /** |
|
| 65 | - * A warning occurred. |
|
| 66 | - * |
|
| 67 | - * @param PHPUnit_Framework_Test $test |
|
| 68 | - * @param PHPUnit_Framework_Warning $e |
|
| 69 | - * @param float $time |
|
| 70 | - * @since Method available since Release 5.1.0 |
|
| 71 | - */ |
|
| 72 | - public function addWarning(PHPUnit_Framework_Test $test, PHPUnit_Framework_Warning $e, $time) |
|
| 73 | - { |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - /** |
|
| 77 | - * A failure occurred. |
|
| 78 | - * |
|
| 79 | - * @param PHPUnit_Framework_Test $test |
|
| 80 | - * @param PHPUnit_Framework_AssertionFailedError $e |
|
| 81 | - * @param float $time |
|
| 82 | - */ |
|
| 83 | - public function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time) |
|
| 84 | - { |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - /** |
|
| 88 | - * Incomplete test. |
|
| 89 | - * |
|
| 90 | - * @param PHPUnit_Framework_Test $test |
|
| 91 | - * @param Exception $e |
|
| 92 | - * @param float $time |
|
| 93 | - */ |
|
| 94 | - public function addIncompleteTest(PHPUnit_Framework_Test $test, Exception $e, $time) |
|
| 95 | - { |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - /** |
|
| 99 | - * Risky test. |
|
| 100 | - * |
|
| 101 | - * @param PHPUnit_Framework_Test $test |
|
| 102 | - * @param Exception $e |
|
| 103 | - * @param float $time |
|
| 104 | - * @since Method available since Release 4.0.0 |
|
| 105 | - */ |
|
| 106 | - public function addRiskyTest(PHPUnit_Framework_Test $test, Exception $e, $time) |
|
| 107 | - { |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - /** |
|
| 111 | - * Skipped test. |
|
| 112 | - * |
|
| 113 | - * @param PHPUnit_Framework_Test $test |
|
| 114 | - * @param Exception $e |
|
| 115 | - * @param float $time |
|
| 116 | - */ |
|
| 117 | - public function addSkippedTest(PHPUnit_Framework_Test $test, Exception $e, $time) |
|
| 118 | - { |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - /** |
|
| 122 | - * A test started. |
|
| 123 | - * |
|
| 124 | - * @param PHPUnit_Framework_Test $test |
|
| 125 | - */ |
|
| 126 | - public function startTest(PHPUnit_Framework_Test $test) |
|
| 127 | - { |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - /** |
|
| 131 | - * A test ended. |
|
| 132 | - * |
|
| 133 | - * @param PHPUnit_Framework_Test $test |
|
| 134 | - * @param float $time |
|
| 135 | - */ |
|
| 136 | - public function endTest(PHPUnit_Framework_Test $test, $time) |
|
| 137 | - { |
|
| 138 | - if (!$test instanceof PHPUnit_Framework_TestCase) return; |
|
| 139 | - |
|
| 140 | - $time = $this->toMilliseconds($time); |
|
| 141 | - $threshold = $this->getSlowThreshold($test); |
|
| 142 | - |
|
| 143 | - if ($this->isSlow($time, $threshold)) { |
|
| 144 | - $this->addSlowTest($test, $time); |
|
| 145 | - } |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - /** |
|
| 149 | - * A test suite started. |
|
| 150 | - * |
|
| 151 | - * @param PHPUnit_Framework_TestSuite $suite |
|
| 152 | - */ |
|
| 153 | - public function startTestSuite(PHPUnit_Framework_TestSuite $suite) |
|
| 154 | - { |
|
| 155 | - $this->suites++; |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - /** |
|
| 159 | - * A test suite ended. |
|
| 160 | - * |
|
| 161 | - * @param PHPUnit_Framework_TestSuite $suite |
|
| 162 | - */ |
|
| 163 | - public function endTestSuite(PHPUnit_Framework_TestSuite $suite) |
|
| 164 | - { |
|
| 165 | - $this->suites--; |
|
| 166 | - |
|
| 167 | - if (0 === $this->suites && $this->hasSlowTests()) { |
|
| 168 | - arsort($this->slow); // Sort longest running tests to the top |
|
| 169 | - |
|
| 170 | - $this->renderHeader(); |
|
| 171 | - $this->renderBody(); |
|
| 172 | - $this->renderFooter(); |
|
| 173 | - } |
|
| 174 | - } |
|
| 175 | - |
|
| 176 | - /** |
|
| 177 | - * Whether the given test execution time is considered slow. |
|
| 178 | - * |
|
| 179 | - * @param int $time Test execution time in milliseconds |
|
| 180 | - * @param int $slowThreshold Test execution time at which a test should be considered slow (milliseconds) |
|
| 181 | - * @return bool |
|
| 182 | - */ |
|
| 183 | - protected function isSlow($time, $slowThreshold) |
|
| 184 | - { |
|
| 185 | - return $time >= $slowThreshold; |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - /** |
|
| 189 | - * Stores a test as slow. |
|
| 190 | - * |
|
| 191 | - * @param PHPUnit_Framework_TestCase $test |
|
| 192 | - * @param int $time Test execution time in milliseconds |
|
| 193 | - */ |
|
| 194 | - protected function addSlowTest(PHPUnit_Framework_TestCase $test, $time) |
|
| 195 | - { |
|
| 196 | - $label = $this->makeLabel($test); |
|
| 197 | - |
|
| 198 | - $this->slow[$label] = $time; |
|
| 199 | - } |
|
| 200 | - |
|
| 201 | - /** |
|
| 202 | - * Whether at least one test has been considered slow. |
|
| 203 | - * |
|
| 204 | - * @return bool |
|
| 205 | - */ |
|
| 206 | - protected function hasSlowTests() |
|
| 207 | - { |
|
| 208 | - return !empty($this->slow); |
|
| 209 | - } |
|
| 210 | - |
|
| 211 | - /** |
|
| 212 | - * Convert PHPUnit's reported test time (microseconds) to milliseconds. |
|
| 213 | - * |
|
| 214 | - * @param float $time |
|
| 215 | - * @return int |
|
| 216 | - */ |
|
| 217 | - protected function toMilliseconds($time) |
|
| 218 | - { |
|
| 219 | - return (int) round($time * 1000); |
|
| 220 | - } |
|
| 221 | - |
|
| 222 | - /** |
|
| 223 | - * Label for describing a test. |
|
| 224 | - * |
|
| 225 | - * @param PHPUnit_Framework_TestCase $test |
|
| 226 | - * @return string |
|
| 227 | - */ |
|
| 228 | - protected function makeLabel(PHPUnit_Framework_TestCase $test) |
|
| 229 | - { |
|
| 230 | - return sprintf('%s:%s', get_class($test), $test->getName()); |
|
| 231 | - } |
|
| 232 | - |
|
| 233 | - /** |
|
| 234 | - * Calculate number of slow tests to report about. |
|
| 235 | - * |
|
| 236 | - * @return int |
|
| 237 | - */ |
|
| 238 | - protected function getReportLength() |
|
| 239 | - { |
|
| 240 | - return min(count($this->slow), $this->reportLength); |
|
| 241 | - } |
|
| 242 | - |
|
| 243 | - /** |
|
| 244 | - * Find how many slow tests occurred that won't be shown due to list length. |
|
| 245 | - * |
|
| 246 | - * @return int Number of hidden slow tests |
|
| 247 | - */ |
|
| 248 | - protected function getHiddenCount() |
|
| 249 | - { |
|
| 250 | - $total = count($this->slow); |
|
| 251 | - $showing = $this->getReportLength($this->slow); |
|
| 252 | - |
|
| 253 | - $hidden = 0; |
|
| 254 | - if ($total > $showing) { |
|
| 255 | - $hidden = $total - $showing; |
|
| 256 | - } |
|
| 257 | - |
|
| 258 | - return $hidden; |
|
| 259 | - } |
|
| 260 | - |
|
| 261 | - /** |
|
| 262 | - * Renders slow test report header. |
|
| 263 | - */ |
|
| 264 | - protected function renderHeader() |
|
| 265 | - { |
|
| 266 | - echo sprintf("\n\nYou should really fix these slow tests (>%sms)...\n", $this->slowThreshold); |
|
| 267 | - } |
|
| 268 | - |
|
| 269 | - /** |
|
| 270 | - * Renders slow test report body. |
|
| 271 | - */ |
|
| 272 | - protected function renderBody() |
|
| 273 | - { |
|
| 274 | - $slowTests = $this->slow; |
|
| 275 | - |
|
| 276 | - $length = $this->getReportLength($slowTests); |
|
| 277 | - for ($i = 1; $i <= $length; ++$i) { |
|
| 278 | - $label = key($slowTests); |
|
| 279 | - $time = array_shift($slowTests); |
|
| 280 | - |
|
| 281 | - echo sprintf(" %s. %sms to run %s\n", $i, $time, $label); |
|
| 282 | - } |
|
| 283 | - } |
|
| 284 | - |
|
| 285 | - /** |
|
| 286 | - * Renders slow test report footer. |
|
| 287 | - */ |
|
| 288 | - protected function renderFooter() |
|
| 289 | - { |
|
| 290 | - if ($hidden = $this->getHiddenCount($this->slow)) { |
|
| 291 | - echo sprintf("...and there %s %s more above your threshold hidden from view", $hidden == 1 ? 'is' : 'are', $hidden); |
|
| 292 | - } |
|
| 293 | - } |
|
| 294 | - |
|
| 295 | - /** |
|
| 296 | - * Populate options into class internals. |
|
| 297 | - * |
|
| 298 | - * @param array $options |
|
| 299 | - */ |
|
| 300 | - protected function loadOptions(array $options) |
|
| 301 | - { |
|
| 302 | - $this->slowThreshold = isset($options['slowThreshold']) ? $options['slowThreshold'] : 500; |
|
| 303 | - $this->reportLength = isset($options['reportLength']) ? $options['reportLength'] : 10; |
|
| 304 | - } |
|
| 305 | - |
|
| 306 | - /** |
|
| 307 | - * Get slow test threshold for given test. A TestCase can override the |
|
| 308 | - * suite-wide slow threshold by using the annotation @slowThreshold with |
|
| 309 | - * the threshold value in milliseconds. |
|
| 310 | - * |
|
| 311 | - * The following test will only be considered slow when its execution time |
|
| 312 | - * reaches 5000ms (5 seconds): |
|
| 313 | - * |
|
| 314 | - * <code> |
|
| 315 | - * @slowThreshold 5000 |
|
| 316 | - * public function testLongRunningProcess() {} |
|
| 317 | - * </code> |
|
| 318 | - * |
|
| 319 | - * @param PHPUnit_Framework_TestCase $test |
|
| 320 | - * @return int |
|
| 321 | - */ |
|
| 322 | - protected function getSlowThreshold(PHPUnit_Framework_TestCase $test) |
|
| 323 | - { |
|
| 324 | - $ann = $test->getAnnotations(); |
|
| 325 | - |
|
| 326 | - return isset($ann['method']['slowThreshold'][0]) ? $ann['method']['slowThreshold'][0] : $this->slowThreshold; |
|
| 327 | - } |
|
| 11 | + /** |
|
| 12 | + * Internal tracking for test suites. |
|
| 13 | + * |
|
| 14 | + * Increments as more suites are run, then decremented as they finish. All |
|
| 15 | + * suites have been run when returns to 0. |
|
| 16 | + * |
|
| 17 | + * @var integer |
|
| 18 | + */ |
|
| 19 | + protected $suites = 0; |
|
| 20 | + |
|
| 21 | + /** |
|
| 22 | + * Time in milliseconds at which a test will be considered "slow" and be |
|
| 23 | + * reported by this listener. |
|
| 24 | + * |
|
| 25 | + * @var int |
|
| 26 | + */ |
|
| 27 | + protected $slowThreshold; |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * Number of tests to report on for slowness. |
|
| 31 | + * |
|
| 32 | + * @var int |
|
| 33 | + */ |
|
| 34 | + protected $reportLength; |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * Collection of slow tests. |
|
| 38 | + * |
|
| 39 | + * @var array |
|
| 40 | + */ |
|
| 41 | + protected $slow = array(); |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * Construct a new instance. |
|
| 45 | + * |
|
| 46 | + * @param array $options |
|
| 47 | + */ |
|
| 48 | + public function __construct(array $options = array()) |
|
| 49 | + { |
|
| 50 | + $this->loadOptions($options); |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * An error occurred. |
|
| 55 | + * |
|
| 56 | + * @param PHPUnit_Framework_Test $test |
|
| 57 | + * @param Exception $e |
|
| 58 | + * @param float $time |
|
| 59 | + */ |
|
| 60 | + public function addError(PHPUnit_Framework_Test $test, Exception $e, $time) |
|
| 61 | + { |
|
| 62 | + } |
|
| 63 | + |
|
| 64 | + /** |
|
| 65 | + * A warning occurred. |
|
| 66 | + * |
|
| 67 | + * @param PHPUnit_Framework_Test $test |
|
| 68 | + * @param PHPUnit_Framework_Warning $e |
|
| 69 | + * @param float $time |
|
| 70 | + * @since Method available since Release 5.1.0 |
|
| 71 | + */ |
|
| 72 | + public function addWarning(PHPUnit_Framework_Test $test, PHPUnit_Framework_Warning $e, $time) |
|
| 73 | + { |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + /** |
|
| 77 | + * A failure occurred. |
|
| 78 | + * |
|
| 79 | + * @param PHPUnit_Framework_Test $test |
|
| 80 | + * @param PHPUnit_Framework_AssertionFailedError $e |
|
| 81 | + * @param float $time |
|
| 82 | + */ |
|
| 83 | + public function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time) |
|
| 84 | + { |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + /** |
|
| 88 | + * Incomplete test. |
|
| 89 | + * |
|
| 90 | + * @param PHPUnit_Framework_Test $test |
|
| 91 | + * @param Exception $e |
|
| 92 | + * @param float $time |
|
| 93 | + */ |
|
| 94 | + public function addIncompleteTest(PHPUnit_Framework_Test $test, Exception $e, $time) |
|
| 95 | + { |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + /** |
|
| 99 | + * Risky test. |
|
| 100 | + * |
|
| 101 | + * @param PHPUnit_Framework_Test $test |
|
| 102 | + * @param Exception $e |
|
| 103 | + * @param float $time |
|
| 104 | + * @since Method available since Release 4.0.0 |
|
| 105 | + */ |
|
| 106 | + public function addRiskyTest(PHPUnit_Framework_Test $test, Exception $e, $time) |
|
| 107 | + { |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + /** |
|
| 111 | + * Skipped test. |
|
| 112 | + * |
|
| 113 | + * @param PHPUnit_Framework_Test $test |
|
| 114 | + * @param Exception $e |
|
| 115 | + * @param float $time |
|
| 116 | + */ |
|
| 117 | + public function addSkippedTest(PHPUnit_Framework_Test $test, Exception $e, $time) |
|
| 118 | + { |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + /** |
|
| 122 | + * A test started. |
|
| 123 | + * |
|
| 124 | + * @param PHPUnit_Framework_Test $test |
|
| 125 | + */ |
|
| 126 | + public function startTest(PHPUnit_Framework_Test $test) |
|
| 127 | + { |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + /** |
|
| 131 | + * A test ended. |
|
| 132 | + * |
|
| 133 | + * @param PHPUnit_Framework_Test $test |
|
| 134 | + * @param float $time |
|
| 135 | + */ |
|
| 136 | + public function endTest(PHPUnit_Framework_Test $test, $time) |
|
| 137 | + { |
|
| 138 | + if (!$test instanceof PHPUnit_Framework_TestCase) return; |
|
| 139 | + |
|
| 140 | + $time = $this->toMilliseconds($time); |
|
| 141 | + $threshold = $this->getSlowThreshold($test); |
|
| 142 | + |
|
| 143 | + if ($this->isSlow($time, $threshold)) { |
|
| 144 | + $this->addSlowTest($test, $time); |
|
| 145 | + } |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + /** |
|
| 149 | + * A test suite started. |
|
| 150 | + * |
|
| 151 | + * @param PHPUnit_Framework_TestSuite $suite |
|
| 152 | + */ |
|
| 153 | + public function startTestSuite(PHPUnit_Framework_TestSuite $suite) |
|
| 154 | + { |
|
| 155 | + $this->suites++; |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + /** |
|
| 159 | + * A test suite ended. |
|
| 160 | + * |
|
| 161 | + * @param PHPUnit_Framework_TestSuite $suite |
|
| 162 | + */ |
|
| 163 | + public function endTestSuite(PHPUnit_Framework_TestSuite $suite) |
|
| 164 | + { |
|
| 165 | + $this->suites--; |
|
| 166 | + |
|
| 167 | + if (0 === $this->suites && $this->hasSlowTests()) { |
|
| 168 | + arsort($this->slow); // Sort longest running tests to the top |
|
| 169 | + |
|
| 170 | + $this->renderHeader(); |
|
| 171 | + $this->renderBody(); |
|
| 172 | + $this->renderFooter(); |
|
| 173 | + } |
|
| 174 | + } |
|
| 175 | + |
|
| 176 | + /** |
|
| 177 | + * Whether the given test execution time is considered slow. |
|
| 178 | + * |
|
| 179 | + * @param int $time Test execution time in milliseconds |
|
| 180 | + * @param int $slowThreshold Test execution time at which a test should be considered slow (milliseconds) |
|
| 181 | + * @return bool |
|
| 182 | + */ |
|
| 183 | + protected function isSlow($time, $slowThreshold) |
|
| 184 | + { |
|
| 185 | + return $time >= $slowThreshold; |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + /** |
|
| 189 | + * Stores a test as slow. |
|
| 190 | + * |
|
| 191 | + * @param PHPUnit_Framework_TestCase $test |
|
| 192 | + * @param int $time Test execution time in milliseconds |
|
| 193 | + */ |
|
| 194 | + protected function addSlowTest(PHPUnit_Framework_TestCase $test, $time) |
|
| 195 | + { |
|
| 196 | + $label = $this->makeLabel($test); |
|
| 197 | + |
|
| 198 | + $this->slow[$label] = $time; |
|
| 199 | + } |
|
| 200 | + |
|
| 201 | + /** |
|
| 202 | + * Whether at least one test has been considered slow. |
|
| 203 | + * |
|
| 204 | + * @return bool |
|
| 205 | + */ |
|
| 206 | + protected function hasSlowTests() |
|
| 207 | + { |
|
| 208 | + return !empty($this->slow); |
|
| 209 | + } |
|
| 210 | + |
|
| 211 | + /** |
|
| 212 | + * Convert PHPUnit's reported test time (microseconds) to milliseconds. |
|
| 213 | + * |
|
| 214 | + * @param float $time |
|
| 215 | + * @return int |
|
| 216 | + */ |
|
| 217 | + protected function toMilliseconds($time) |
|
| 218 | + { |
|
| 219 | + return (int) round($time * 1000); |
|
| 220 | + } |
|
| 221 | + |
|
| 222 | + /** |
|
| 223 | + * Label for describing a test. |
|
| 224 | + * |
|
| 225 | + * @param PHPUnit_Framework_TestCase $test |
|
| 226 | + * @return string |
|
| 227 | + */ |
|
| 228 | + protected function makeLabel(PHPUnit_Framework_TestCase $test) |
|
| 229 | + { |
|
| 230 | + return sprintf('%s:%s', get_class($test), $test->getName()); |
|
| 231 | + } |
|
| 232 | + |
|
| 233 | + /** |
|
| 234 | + * Calculate number of slow tests to report about. |
|
| 235 | + * |
|
| 236 | + * @return int |
|
| 237 | + */ |
|
| 238 | + protected function getReportLength() |
|
| 239 | + { |
|
| 240 | + return min(count($this->slow), $this->reportLength); |
|
| 241 | + } |
|
| 242 | + |
|
| 243 | + /** |
|
| 244 | + * Find how many slow tests occurred that won't be shown due to list length. |
|
| 245 | + * |
|
| 246 | + * @return int Number of hidden slow tests |
|
| 247 | + */ |
|
| 248 | + protected function getHiddenCount() |
|
| 249 | + { |
|
| 250 | + $total = count($this->slow); |
|
| 251 | + $showing = $this->getReportLength($this->slow); |
|
| 252 | + |
|
| 253 | + $hidden = 0; |
|
| 254 | + if ($total > $showing) { |
|
| 255 | + $hidden = $total - $showing; |
|
| 256 | + } |
|
| 257 | + |
|
| 258 | + return $hidden; |
|
| 259 | + } |
|
| 260 | + |
|
| 261 | + /** |
|
| 262 | + * Renders slow test report header. |
|
| 263 | + */ |
|
| 264 | + protected function renderHeader() |
|
| 265 | + { |
|
| 266 | + echo sprintf("\n\nYou should really fix these slow tests (>%sms)...\n", $this->slowThreshold); |
|
| 267 | + } |
|
| 268 | + |
|
| 269 | + /** |
|
| 270 | + * Renders slow test report body. |
|
| 271 | + */ |
|
| 272 | + protected function renderBody() |
|
| 273 | + { |
|
| 274 | + $slowTests = $this->slow; |
|
| 275 | + |
|
| 276 | + $length = $this->getReportLength($slowTests); |
|
| 277 | + for ($i = 1; $i <= $length; ++$i) { |
|
| 278 | + $label = key($slowTests); |
|
| 279 | + $time = array_shift($slowTests); |
|
| 280 | + |
|
| 281 | + echo sprintf(" %s. %sms to run %s\n", $i, $time, $label); |
|
| 282 | + } |
|
| 283 | + } |
|
| 284 | + |
|
| 285 | + /** |
|
| 286 | + * Renders slow test report footer. |
|
| 287 | + */ |
|
| 288 | + protected function renderFooter() |
|
| 289 | + { |
|
| 290 | + if ($hidden = $this->getHiddenCount($this->slow)) { |
|
| 291 | + echo sprintf("...and there %s %s more above your threshold hidden from view", $hidden == 1 ? 'is' : 'are', $hidden); |
|
| 292 | + } |
|
| 293 | + } |
|
| 294 | + |
|
| 295 | + /** |
|
| 296 | + * Populate options into class internals. |
|
| 297 | + * |
|
| 298 | + * @param array $options |
|
| 299 | + */ |
|
| 300 | + protected function loadOptions(array $options) |
|
| 301 | + { |
|
| 302 | + $this->slowThreshold = isset($options['slowThreshold']) ? $options['slowThreshold'] : 500; |
|
| 303 | + $this->reportLength = isset($options['reportLength']) ? $options['reportLength'] : 10; |
|
| 304 | + } |
|
| 305 | + |
|
| 306 | + /** |
|
| 307 | + * Get slow test threshold for given test. A TestCase can override the |
|
| 308 | + * suite-wide slow threshold by using the annotation @slowThreshold with |
|
| 309 | + * the threshold value in milliseconds. |
|
| 310 | + * |
|
| 311 | + * The following test will only be considered slow when its execution time |
|
| 312 | + * reaches 5000ms (5 seconds): |
|
| 313 | + * |
|
| 314 | + * <code> |
|
| 315 | + * @slowThreshold 5000 |
|
| 316 | + * public function testLongRunningProcess() {} |
|
| 317 | + * </code> |
|
| 318 | + * |
|
| 319 | + * @param PHPUnit_Framework_TestCase $test |
|
| 320 | + * @return int |
|
| 321 | + */ |
|
| 322 | + protected function getSlowThreshold(PHPUnit_Framework_TestCase $test) |
|
| 323 | + { |
|
| 324 | + $ann = $test->getAnnotations(); |
|
| 325 | + |
|
| 326 | + return isset($ann['method']['slowThreshold'][0]) ? $ann['method']['slowThreshold'][0] : $this->slowThreshold; |
|
| 327 | + } |
|
| 328 | 328 | } |
@@ -30,11 +30,11 @@ |
||
| 30 | 30 | |
| 31 | 31 | |
| 32 | 32 | if ( true ) { |
| 33 | - while ( false ) { |
|
| 33 | + while ( false ) { |
|
| 34 | 34 | |
| 35 | - echo 'OK'; |
|
| 35 | + echo 'OK'; |
|
| 36 | 36 | |
| 37 | - } |
|
| 37 | + } |
|
| 38 | 38 | |
| 39 | 39 | } |
| 40 | 40 | |
@@ -52,30 +52,30 @@ |
||
| 52 | 52 | |
| 53 | 53 | // This is OK. |
| 54 | 54 | class A_Class_With_Really_Long_Name |
| 55 | - extends Another_Class_With_A_Really_Long_Name { |
|
| 55 | + extends Another_Class_With_A_Really_Long_Name { |
|
| 56 | 56 | |
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | // This is OK too. |
| 60 | 60 | class A_Class_With_Really_Long_Name_2 |
| 61 | - extends Another_Class_With_A_Really_Long_Name |
|
| 62 | - implements Some_Interface_With_A_Long_Name, |
|
| 63 | - Another_Interface_With_A_Long_Name { |
|
| 61 | + extends Another_Class_With_A_Really_Long_Name |
|
| 62 | + implements Some_Interface_With_A_Long_Name, |
|
| 63 | + Another_Interface_With_A_Long_Name { |
|
| 64 | 64 | |
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | // But this is not. |
| 68 | 68 | class A_Class_With_Really_Long_Name_3 |
| 69 | - extends Another_Class_With_A_Really_Long_Name |
|
| 69 | + extends Another_Class_With_A_Really_Long_Name |
|
| 70 | 70 | { |
| 71 | 71 | |
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | // Nor is this. |
| 75 | 75 | class A_Class_With_Really_Long_Name_4 |
| 76 | - extends Another_Class_With_A_Really_Long_Name |
|
| 77 | - implements Some_Interface_With_A_Long_Name, |
|
| 78 | - Another_Interface_With_A_Long_Name |
|
| 76 | + extends Another_Class_With_A_Really_Long_Name |
|
| 77 | + implements Some_Interface_With_A_Long_Name, |
|
| 78 | + Another_Interface_With_A_Long_Name |
|
| 79 | 79 | { |
| 80 | 80 | |
| 81 | 81 | } |
@@ -22,13 +22,13 @@ discard block |
||
| 22 | 22 | // Issue:#53. |
| 23 | 23 | function custom_column_display( $column, $post_id ) |
| 24 | 24 | { |
| 25 | - global $post; |
|
| 26 | - switch ( $column ) { |
|
| 27 | - case 'some_number' : |
|
| 28 | - echo (int) $test; |
|
| 29 | - echo (int) get_post_meta( $post_id, SOME_NUMBER, true ); |
|
| 30 | - break; |
|
| 31 | - } |
|
| 25 | + global $post; |
|
| 26 | + switch ( $column ) { |
|
| 27 | + case 'some_number' : |
|
| 28 | + echo (int) $test; |
|
| 29 | + echo (int) get_post_meta( $post_id, SOME_NUMBER, true ); |
|
| 30 | + break; |
|
| 31 | + } |
|
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | |
@@ -160,10 +160,10 @@ discard block |
||
| 160 | 160 | esc_html_e( 'Something' ); // Ok. |
| 161 | 161 | |
| 162 | 162 | echo $something // Bad. |
| 163 | - . esc_attr( 'baz-' // Rest is OK. |
|
| 164 | - . $r |
|
| 165 | - . ( $r === $active_round ? ' foo' : '' ) |
|
| 166 | - . ( $r < $active_round ? ' bar' : '' ) |
|
| 163 | + . esc_attr( 'baz-' // Rest is OK. |
|
| 164 | + . $r |
|
| 165 | + . ( $r === $active_round ? ' foo' : '' ) |
|
| 166 | + . ( $r < $active_round ? ' bar' : '' ) |
|
| 167 | 167 | ) . 'something'; |
| 168 | 168 | |
| 169 | 169 | echo implode( '<br>', $items ); // Bad. |
@@ -174,9 +174,9 @@ discard block |
||
| 174 | 174 | echo join( '<br>', array_map( 'esc_html', $items ) ); // Ok. |
| 175 | 175 | |
| 176 | 176 | echo '<option name="' . esc_attr( $name ) . '"' . |
| 177 | - ( $name === $selected ? ' selected' : '' ) . |
|
| 178 | - '>' . esc_html( $value ) |
|
| 179 | - . '</option>'; |
|
| 177 | + ( $name === $selected ? ' selected' : '' ) . |
|
| 178 | + '>' . esc_html( $value ) |
|
| 179 | + . '</option>'; |
|
| 180 | 180 | |
| 181 | 181 | _deprecated_hook( 'some_filter', '1.3.0', esc_html__( 'The $arg is deprecated.' ), 'some_other_filter' ); // Ok. |
| 182 | 182 | _deprecated_hook( "filter_{$context}", '1.3.0', __( 'The $arg is deprecated.' ), sprintf( __( 'Some parsed message %s', $variable ) ) ); // Bad. |
@@ -86,9 +86,9 @@ |
||
| 86 | 86 | * @return array |
| 87 | 87 | */ |
| 88 | 88 | public function register() { |
| 89 | - return array( |
|
| 90 | - T_VARIABLE, |
|
| 91 | - ); |
|
| 89 | + return array( |
|
| 90 | + T_VARIABLE, |
|
| 91 | + ); |
|
| 92 | 92 | } |
| 93 | 93 | |
| 94 | 94 | /** |