Skip to content

Commit 0dd3e63

Browse files
localheinzsebastianbergmann
authored andcommitted
Enhancement: Extract methods
1 parent 26d2f56 commit 0dd3e63

File tree

1 file changed

+47
-15
lines changed

1 file changed

+47
-15
lines changed

src/Framework/TestResult.php

Lines changed: 47 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -276,8 +276,9 @@ public function flushListeners(): void
276276
public function addError(Test $test, Throwable $t, float $time): void
277277
{
278278
if ($t instanceof RiskyTestError) {
279-
$this->risky[] = new TestFailure($test, $t);
280-
$notifyMethod = 'addRiskyTest';
279+
$this->recordRisky($test, $t);
280+
281+
$notifyMethod = 'addRiskyTest';
281282

282283
if ($test instanceof TestCase) {
283284
$test->markAsRisky();
@@ -287,22 +288,25 @@ public function addError(Test $test, Throwable $t, float $time): void
287288
$this->stop();
288289
}
289290
} elseif ($t instanceof IncompleteTest) {
290-
$this->notImplemented[] = new TestFailure($test, $t);
291-
$notifyMethod = 'addIncompleteTest';
291+
$this->recordNotImplemented($test, $t);
292+
293+
$notifyMethod = 'addIncompleteTest';
292294

293295
if ($this->stopOnIncomplete) {
294296
$this->stop();
295297
}
296298
} elseif ($t instanceof SkippedTest) {
297-
$this->skipped[] = new TestFailure($test, $t);
298-
$notifyMethod = 'addSkippedTest';
299+
$this->recordSkipped($test, $t);
300+
301+
$notifyMethod = 'addSkippedTest';
299302

300303
if ($this->stopOnSkipped) {
301304
$this->stop();
302305
}
303306
} else {
304-
$this->errors[] = new TestFailure($test, $t);
305-
$notifyMethod = 'addError';
307+
$this->recordError($test, $t);
308+
309+
$notifyMethod = 'addError';
306310

307311
if ($this->stopOnError || $this->stopOnFailure) {
308312
$this->stop();
@@ -332,7 +336,7 @@ public function addWarning(Test $test, Warning $e, float $time): void
332336
$this->stop();
333337
}
334338

335-
$this->warnings[] = new TestFailure($test, $e);
339+
$this->recordWarning($test, $e);
336340

337341
foreach ($this->listeners as $listener) {
338342
$listener->addWarning($test, $e, $time);
@@ -348,8 +352,9 @@ public function addWarning(Test $test, Warning $e, float $time): void
348352
public function addFailure(Test $test, AssertionFailedError $e, float $time): void
349353
{
350354
if ($e instanceof RiskyTestError || $e instanceof OutputError) {
351-
$this->risky[] = new TestFailure($test, $e);
352-
$notifyMethod = 'addRiskyTest';
355+
$this->recordRisky($test, $e);
356+
357+
$notifyMethod = 'addRiskyTest';
353358

354359
if ($test instanceof TestCase) {
355360
$test->markAsRisky();
@@ -359,15 +364,17 @@ public function addFailure(Test $test, AssertionFailedError $e, float $time): vo
359364
$this->stop();
360365
}
361366
} elseif ($e instanceof IncompleteTest) {
362-
$this->notImplemented[] = new TestFailure($test, $e);
363-
$notifyMethod = 'addIncompleteTest';
367+
$this->recordNotImplemented($test, $e);
368+
369+
$notifyMethod = 'addIncompleteTest';
364370

365371
if ($this->stopOnIncomplete) {
366372
$this->stop();
367373
}
368374
} elseif ($e instanceof SkippedTest) {
369-
$this->skipped[] = new TestFailure($test, $e);
370-
$notifyMethod = 'addSkippedTest';
375+
$this->recordSkipped($test, $e);
376+
377+
$notifyMethod = 'addSkippedTest';
371378

372379
if ($this->stopOnSkipped) {
373380
$this->stop();
@@ -1254,4 +1261,29 @@ public function setRegisterMockObjectsFromTestArgumentsRecursively(bool $flag):
12541261
{
12551262
$this->registerMockObjectsFromTestArgumentsRecursively = $flag;
12561263
}
1264+
1265+
private function recordError(Test $test, Throwable $t): void
1266+
{
1267+
$this->errors[] = new TestFailure($test, $t);
1268+
}
1269+
1270+
private function recordNotImplemented(Test $test, Throwable $t): void
1271+
{
1272+
$this->notImplemented[] = new TestFailure($test, $t);
1273+
}
1274+
1275+
private function recordRisky(Test $test, Throwable $t): void
1276+
{
1277+
$this->risky[] = new TestFailure($test, $t);
1278+
}
1279+
1280+
private function recordSkipped(Test $test, Throwable $t): void
1281+
{
1282+
$this->skipped[] = new TestFailure($test, $t);
1283+
}
1284+
1285+
private function recordWarning(Test $test, Throwable $t): void
1286+
{
1287+
$this->warnings[] = new TestFailure($test, $t);
1288+
}
12571289
}

0 commit comments

Comments
 (0)