Skip to content

Commit

Permalink
Fix CS/WS issues
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Jun 24, 2018
1 parent 1a3f78e commit 2e9ab30
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 16 deletions.
4 changes: 2 additions & 2 deletions src/Framework/TestResult.php
Expand Up @@ -177,12 +177,12 @@ class TestResult implements Countable
/**
* @var bool
*/
private $stopOnDefect = false;
protected $lastTestFailed = false;

/**
* @var bool
*/
protected $lastTestFailed = false;
private $stopOnDefect = false;

/**
* @var bool
Expand Down
7 changes: 7 additions & 0 deletions src/Runner/ResultCacheExtension.php
Expand Up @@ -29,47 +29,54 @@ public function flush(): void
public function executeAfterSuccessfulTest(string $test, float $time): void
{
$testName = $this->getTestName($test);

$this->cache->setTime($testName, \round($time, 3));
}

public function executeAfterIncompleteTest(string $test, string $message, float $time): void
{
$testName = $this->getTestName($test);

$this->cache->setTime($testName, \round($time, 3));
$this->cache->setState($testName, BaseTestRunner::STATUS_INCOMPLETE);
}

public function executeAfterRiskyTest(string $test, string $message, float $time): void
{
$testName = $this->getTestName($test);

$this->cache->setTime($testName, \round($time, 3));
$this->cache->setState($testName, BaseTestRunner::STATUS_RISKY);
}

public function executeAfterSkippedTest(string $test, string $message, float $time): void
{
$testName = $this->getTestName($test);

$this->cache->setTime($testName, \round($time, 3));
$this->cache->setState($testName, BaseTestRunner::STATUS_SKIPPED);
}

public function executeAfterTestError(string $test, string $message, float $time): void
{
$testName = $this->getTestName($test);

$this->cache->setTime($testName, \round($time, 3));
$this->cache->setState($testName, BaseTestRunner::STATUS_ERROR);
}

public function executeAfterTestFailure(string $test, string $message, float $time): void
{
$testName = $this->getTestName($test);

$this->cache->setTime($testName, \round($time, 3));
$this->cache->setState($testName, BaseTestRunner::STATUS_FAILURE);
}

public function executeAfterTestWarning(string $test, string $message, float $time): void
{
$testName = $this->getTestName($test);

$this->cache->setTime($testName, \round($time, 3));
$this->cache->setState($testName, BaseTestRunner::STATUS_WARNING);
}
Expand Down
40 changes: 26 additions & 14 deletions src/Runner/TestSuiteSorter.php
Expand Up @@ -89,6 +89,7 @@ public function reorderTestsInSuite(Test $suite, int $order, bool $resolveDepend
if ($orderDefects === self::ORDER_DEFECTS_FIRST) {
$this->addSuiteToDefectSortOrder($suite);
}

$this->sort($suite, $order, $resolveDependencies, $orderDefects);
}
}
Expand Down Expand Up @@ -130,9 +131,13 @@ private function addSuiteToDefectSortOrder(TestSuite $suite): void

private function suiteOnlyContainsTests(TestSuite $suite): bool
{
return \array_reduce($suite->tests(), function ($carry, $test) {
return $carry && ($test instanceof TestCase || $test instanceof DataProviderTestSuite);
}, true);
return \array_reduce(
$suite->tests(),
function ($carry, $test) {
return $carry && ($test instanceof TestCase || $test instanceof DataProviderTestSuite);
},
true
);
}

private function reverse(array $tests): array
Expand All @@ -149,9 +154,12 @@ private function randomize(array $tests): array

private function sortDefectsFirst(array $tests): array
{
\usort($tests, function ($left, $right) {
return $this->cmpDefectPriorityAndTime($left, $right);
});
\usort(
$tests,
function ($left, $right) {
return $this->cmpDefectPriorityAndTime($left, $right);
}
);

return $tests;
}
Expand Down Expand Up @@ -202,9 +210,12 @@ private function resolveDependencies(array $tests): array
$i = 0;

do {
$todoNames = \array_map(function ($test) {
return $this->getNormalizedTestName($test);
}, $tests);
$todoNames = \array_map(
function ($test) {
return $this->getNormalizedTestName($test);
},
$tests
);

if (!$tests[$i]->hasDependencies() || empty(\array_intersect($this->getNormalizedDependencyNames($tests[$i]), $todoNames))) {
$newTestOrder = \array_merge($newTestOrder, \array_splice($tests, $i, 1));
Expand Down Expand Up @@ -244,11 +255,12 @@ private function getNormalizedDependencyNames($test): array
$testClass = \get_class($test);
}

$names = \array_map(function ($name) use ($testClass) {
return \strpos($name, '::') === false
? $testClass . '::' . $name
: $name;
}, $test->getDependencies());
$names = \array_map(
function ($name) use ($testClass) {
return \strpos($name, '::') === false ? $testClass . '::' . $name : $name;
},
$test->getDependencies()
);

return $names;
}
Expand Down
5 changes: 5 additions & 0 deletions src/TextUI/Command.php
Expand Up @@ -1330,22 +1330,27 @@ private function handleOrderByOption(string $value): void
$this->arguments['resolveDependencies'] = false;

break;

case 'reverse':
$this->arguments['executionOrder'] = TestSuiteSorter::ORDER_REVERSED;

break;

case 'random':
$this->arguments['executionOrder'] = TestSuiteSorter::ORDER_RANDOMIZED;

break;

case 'defects':
$this->arguments['executionOrderDefects'] = TestSuiteSorter::ORDER_DEFECTS_FIRST;

break;

case 'depends':
$this->arguments['resolveDependencies'] = true;

break;

default:
$this->exitWithErrorMessage("unrecognized --order-by option: $order");
}
Expand Down
3 changes: 3 additions & 0 deletions src/TextUI/TestRunner.php
Expand Up @@ -183,14 +183,17 @@ public function doRun(Test $suite, array $arguments = [], bool $exit = true): Te
} else {
$cache = new TestResultCache;
}

$this->extensions[] = new ResultCacheExtension($cache);
}

if ($arguments['executionOrder'] !== TestSuiteSorter::ORDER_DEFAULT || $arguments['executionOrderDefects'] !== TestSuiteSorter::ORDER_DEFAULT || $arguments['resolveDependencies']) {
if (!isset($cache)) {
$cache = new NullTestResultCache;
}

$cache->load();

$sorter = new TestSuiteSorter($cache);

$sorter->reorderTestsInSuite($suite, $arguments['executionOrder'], $arguments['resolveDependencies'], $arguments['executionOrderDefects']);
Expand Down

0 comments on commit 2e9ab30

Please sign in to comment.