Page MenuHomePhabricator
Paste P1134

TestResultsSampeler.php
ActivePublic

Authored by avivey on May 7 2014, 12:11 AM.
Tags
None
Referenced Files
F150984: TestResultsSampeler.php
May 7 2014, 12:11 AM
Subscribers
None
<?php
/**
* Reduces tests results sets for brevity and reducing number of conduit calls needed.
* Ignores coverage data.
*/
final class TestResultsSampeler {
private $sample_size = 6;
private $extra_test_coverage = null;
private $extra_test_uri = null;
private $extra_test_status = null;
private $extra_test_text = '';
public function sampelize($results) {
$grouped = mgroup($results, 'getResult');
$counts = array();
$sampled = array();
foreach ($grouped as $status => $tests) {
$to_show =
$status == ArcanistUnitTestResult::RESULT_PASS ?
0 :
$this->sample_size;
$counts[$status] = count($tests) - $to_show;
$sampled[$status] = array_slice($tests, 0, $to_show);
}
$sampled = array_mergev($sampled);
$text_order = array(
ArcanistUnitTestResult::RESULT_BROKEN,
ArcanistUnitTestResult::RESULT_FAIL,
ArcanistUnitTestResult::RESULT_SKIP,
ArcanistUnitTestResult::RESULT_UNSOUND,
ArcanistUnitTestResult::RESULT_POSTPONED,
ArcanistUnitTestResult::RESULT_PASS);
$extra_text = $this->extra_test_text;
$extra_test_status = $this->extra_test_status;
foreach ($text_order as $status) {
$count = idx($counts, $status, 0);
if ($count <= 0)
continue;
$extra_text .= "$count more tests $status. ";
if ($extra_test_status == null)
$extra_test_status = $status;
}
if (!$extra_text) {
$extra_text = 'Click for full report.';
}
if ($extra_test_status == null) {
$extra_test_status = ArcanistUnitTestResult::RESULT_PASS;
}
$extra_test = id(new ArcanistUnitTestResult())
->setName($extra_text)
->setResult($extra_test_status)
->setDuration(0)
->setCoverage($this->extra_test_coverage)
->setLink($this->extra_test_uri);
return array(
'sampled' => $sampled,
'extra test' => $extra_test,
);
}
public function setExtraTestCoverage($coverage) {
$this->extra_test_coverage = $coverage;
}
public function setExtraTestLink($uri) {
$this->extra_test_uri = $uri;
}
public function setExtraTestStatus($status) {
$this->extra_test_status = $status;
}
public function setExtraTestText($text) {
$this->extra_test_text = $text;
}
}

Event Timeline

avivey changed the title of this paste from untitled to TestResultsSampeler.php.
avivey updated the paste's language from autodetect to autodetect.

This class might be useful if you have lots of tests, and only want to report the failing ones.

Used with P1132, and with care.