Skip to content

Commit

Permalink
Use [FQCN, datarow.id] as the key for test identification
Browse files Browse the repository at this point in the history
  • Loading branch information
epdenouden authored and sebastianbergmann committed Nov 14, 2018
1 parent 1c5c39d commit bad99b9
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 32 deletions.
25 changes: 9 additions & 16 deletions src/Runner/TestSuiteSorter.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,10 @@ private function addSuiteToDefectSortOrder(TestSuite $suite): void
$max = 0;

foreach ($suite->tests() as $test) {
if (!isset($this->defectSortOrder[$test->getName()])) {
$this->defectSortOrder[$test->getName()] = self::DEFECT_SORT_WEIGHT[$this->cache->getState($test->getName())];
$max = \max($max, $this->defectSortOrder[$test->getName()]);
$testname = $this->getNormalizedTestName($test);
if (!isset($this->defectSortOrder[$testname])) {
$this->defectSortOrder[$testname] = self::DEFECT_SORT_WEIGHT[$this->cache->getState($testname)];
$max = \max($max, $this->defectSortOrder[$testname]);
}
}

Expand Down Expand Up @@ -203,12 +204,8 @@ function ($left, $right) {
*/
private function cmpDefectPriorityAndTime(Test $a, Test $b): int
{
if (!$a instanceof TestCase || !$b instanceof TestCase) {
return 0;
}

$priorityA = $this->defectSortOrder[$a->getName()] ?? 0;
$priorityB = $this->defectSortOrder[$b->getName()] ?? 0;
$priorityA = $this->defectSortOrder[$this->getNormalizedTestName($a)] ?? 0;
$priorityB = $this->defectSortOrder[$this->getNormalizedTestName($b)] ?? 0;

if ($priorityB <=> $priorityA) {
// Sort defect weight descending
Expand All @@ -228,11 +225,7 @@ private function cmpDefectPriorityAndTime(Test $a, Test $b): int
*/
private function cmpDuration(Test $a, Test $b): int
{
if (!$a instanceof TestCase || !$b instanceof TestCase) {
return 0;
}

return $this->cache->getTime($a->getName()) <=> $this->cache->getTime($b->getName());
return $this->cache->getTime($this->getNormalizedTestName($a)) <=> $this->cache->getTime($this->getNormalizedTestName($b));
}

/**
Expand Down Expand Up @@ -286,10 +279,10 @@ private function getNormalizedTestName($test): string
}

if (\strpos($test->getName(), '::') !== false) {
return $test->getName();
return $test->getName(true);
}

return \get_class($test) . '::' . $test->getName();
return \get_class($test) . '::' . $test->getName(true);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/end-to-end/cache-result.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ Time: %s, Memory: %s

OK, but incomplete, skipped, or risky tests!
Tests: 5, Assertions: 3, Skipped: 2.
C:30:"PHPUnit\Runner\TestResultCache":%d:{a:2:{s:7:"defects";a:2:{s:8:"testFour";i:1;s:9:"testThree";i:1;}s:5:"times";a:5:{s:8:"testFive";d:%f;s:8:"testFour";d:%f;s:9:"testThree";d:%f;s:7:"testTwo";d:%f;s:7:"testOne";d:%f;}}}
C:30:"PHPUnit\Runner\TestResultCache":335:{a:2:{s:7:"defects";a:2:{s:29:"MultiDependencyTest::testFour";i:1;s:30:"MultiDependencyTest::testThree";i:1;}s:5:"times";a:5:{s:29:"MultiDependencyTest::testFive";d:%f;s:29:"MultiDependencyTest::testFour";d:%f;s:30:"MultiDependencyTest::testThree";d:%f;s:28:"MultiDependencyTest::testTwo";d:%f;s:28:"MultiDependencyTest::testOne";d:%f;}}}
26 changes: 13 additions & 13 deletions tests/unit/Runner/ResultCacheExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,14 @@ public function longTestNamesDataprovider(): array
{
return [
'ClassName::testMethod' => [
TestCaseTest::class . '::testSomething',
'testSomething', ],
'testSomething',
TestCaseTest::class . '::testSomething', ],
'ClassName::testMethod and data set number and vardump' => [
TestCaseTest::class . '::testMethod with data set #123 (\'a\', "A", 0, false)',
'testMethod with data set #123', ],
'testMethod with data set #123 (\'a\', "A", 0, false)',
TestCaseTest::class . '::testMethod with data set #123', ],
'ClassName::testMethod and data set name and vardump' => [
TestCaseTest::class . '::testMethod with data set "data name" (\'a\', "A\", 0, false)',
'testMethod with data set "data name"', ],
'testMethod with data set "data name" (\'a\', "A\", 0, false)',
TestCaseTest::class . '::testMethod with data set "data name"', ],
];
}

Expand All @@ -77,55 +77,55 @@ public function testError(): void
$test = new \TestError('test_name');
$test->run($this->result);

$this->assertSame(BaseTestRunner::STATUS_ERROR, $this->cache->getState('test_name'));
$this->assertSame(BaseTestRunner::STATUS_ERROR, $this->cache->getState(\TestError::class . '::test_name'));
}

public function testFailure(): void
{
$test = new \Failure('test_name');
$test->run($this->result);

$this->assertSame(BaseTestRunner::STATUS_FAILURE, $this->cache->getState('test_name'));
$this->assertSame(BaseTestRunner::STATUS_FAILURE, $this->cache->getState(\Failure::class . '::test_name'));
}

public function testSkipped(): void
{
$test = new \TestSkipped('test_name');
$test->run($this->result);

$this->assertSame(BaseTestRunner::STATUS_SKIPPED, $this->cache->getState('test_name'));
$this->assertSame(BaseTestRunner::STATUS_SKIPPED, $this->cache->getState(\TestSkipped::class . '::test_name'));
}

public function testIncomplete(): void
{
$test = new \TestIncomplete('test_name');
$test->run($this->result);

$this->assertSame(BaseTestRunner::STATUS_INCOMPLETE, $this->cache->getState('test_name'));
$this->assertSame(BaseTestRunner::STATUS_INCOMPLETE, $this->cache->getState(\TestIncomplete::class . '::test_name'));
}

public function testPassedTestsOnlyCacheTime(): void
{
$test = new \Success('test_name');
$test->run($this->result);

$this->assertSame(BaseTestRunner::STATUS_UNKNOWN, $this->cache->getState('test_name'));
$this->assertSame(BaseTestRunner::STATUS_UNKNOWN, $this->cache->getState(\Success::class . '::test_name'));
}

public function testWarning(): void
{
$test = new \TestWarning('test_name');
$test->run($this->result);

$this->assertSame(BaseTestRunner::STATUS_WARNING, $this->cache->getState('test_name'));
$this->assertSame(BaseTestRunner::STATUS_WARNING, $this->cache->getState(\TestWarning::class . '::test_name'));
}

public function testRisky(): void
{
$test = new \TestRisky('test_name');
$test->run($this->result);

$this->assertSame(BaseTestRunner::STATUS_RISKY, $this->cache->getState('test_name'));
$this->assertSame(BaseTestRunner::STATUS_RISKY, $this->cache->getState(\TestRisky::class . '::test_name'));
}

public function testEmptySuite(): void
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/Runner/TestSuiteSorterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,8 @@ public function testSuiteSorterDefectsOptions(int $order, bool $resolveDependenc
$cache = new TestResultCache;

foreach ($runState as $testName => $data) {
$cache->setState($testName, $data['state']);
$cache->setTime($testName, $data['time']);
$cache->setState(\MultiDependencyTest::class . '::' . $testName, $data['state']);
$cache->setTime(\MultiDependencyTest::class . '::' . $testName, $data['time']);
}

$sorter = new TestSuiteSorter($cache);
Expand Down

0 comments on commit bad99b9

Please sign in to comment.