/** * Reduces the paths by cutting the longest common start path. * * For instance, * * <code> * Array * ( * [/home/sb/PHPUnit/Samples/Money/Money.php] => Array * ( * ... * ) * * [/home/sb/PHPUnit/Samples/Money/MoneyBag.php] => Array * ( * ... * ) * ) * </code> * * is reduced to * * <code> * Array * ( * [Money.php] => Array * ( * ... * ) * * [MoneyBag.php] => Array * ( * ... * ) * ) * </code> * * @param array $files * @return string * @access protected * @static */ protected static function reducePaths(&$files) { if (empty($files)) { return '.'; } $commonPath = ''; $paths = array_keys($files); if (count($files) == 1) { $commonPath = dirname($paths[0]); $files[basename($paths[0])] = $files[$paths[0]]; unset($files[$paths[0]]); return $commonPath; } $max = count($paths); for ($i = 0; $i < $max; $i++) { $paths[$i] = explode(DIRECTORY_SEPARATOR, $paths[$i]); if (empty($paths[$i][0])) { $paths[$i][0] = DIRECTORY_SEPARATOR; } } $done = FALSE; $max = count($paths); while (!$done) { for ($i = 0; $i < $max - 1; $i++) { if (!isset($paths[$i][0]) || !isset($paths[$i + 1][0]) || $paths[$i][0] != $paths[$i + 1][0]) { $done = TRUE; break; } } if (!$done) { $commonPath .= $paths[0][0] . ($paths[0][0] != DIRECTORY_SEPARATOR ? DIRECTORY_SEPARATOR : ''); for ($i = 0; $i < $max; $i++) { array_shift($paths[$i]); } } } $original = array_keys($files); $max = count($original); for ($i = 0; $i < $max; $i++) { $files[join('/', $paths[$i])] = $files[$original[$i]]; unset($files[$original[$i]]); } $files = PHPUnit_Util_Array::sortRecursively($files); return $commonPath; }
/** * @param PHPUnit_Util_Report_Test_Node_TestSuite $testSuite * @param array $files * @access protected * @static */ public function setupCoveringTests(PHPUnit_Util_Report_Test_Node_TestSuite $testSuite, $files) { $testCase = array(); $thisName = $this->getName(TRUE); foreach ($files[$thisName] as $line => $tests) { if (is_array($tests)) { foreach ($tests as $test) { if (isset($test->__testNode->testId)) { $testId = $test->__testNode->testId; if (!isset($testCase[$testId])) { $testCase[$testId] = array('numLinesExecuted' => 1, 'object' => $test); } else { $testCase[$testId]['numLinesExecuted']++; } if (!isset($this->coveringTestsByLine[$line])) { $this->coveringTestsByLine[$line] = array(); } $found = FALSE; foreach ($this->coveringTestsByLine[$line] as $_test) { if ($_test === $test) { $found = TRUE; break; } } if (!$found) { $this->coveringTestsByLine[$line][] = $test; } } } } } foreach ($testCase as $coveringTest) { $test = $coveringTest['object']; $test = $test->__testNode; $name = $test->getName(TRUE); if (!isset($this->coveringTests[$name[0]])) { $this->coveringTests[$name[0]] = array(); } $found = FALSE; foreach ($this->coveringTests[$name[0]] as $_name => $existingTest) { if ($existingTest['object'] === $test) { $found = TRUE; break; } } if (!$found) { $test->addCoveredFile($this); $this->coveringTests[$name[0]][$name[1]] = array('numLinesExecuted' => $coveringTest['numLinesExecuted'], 'object' => $test); } else { $this->coveringTests[$name[0]][$name[1]]['numLinesExecuted'] += $coveringTest['numLinesExecuted']; } } $this->coveringTests = PHPUnit_Util_Array::sortRecursively($this->coveringTests); }