Returns the files and lines a test method wants to cover.
@since Method available since Release 1.2.0
string $className:
string $methodName:
array
protected function getLinesToBeCovered($className, $methodName) {
$codeToCoverList = array();
$result = array();
// @codeCoverageIgnoreStart
if (($pos = strpos($methodName, ' ')) !== FALSE) {
$methodName = substr($methodName, 0, $pos);
}
// @codeCoverageIgnoreEnd
$class = new ReflectionClass($className);
try {
$method = new ReflectionMethod($className, $methodName);
} catch (ReflectionException $e) {
return array();
}
$docComment = substr($class
->getDocComment(), 3, -2) . PHP_EOL . substr($method
->getDocComment(), 3, -2);
$templateMethods = array(
'setUp',
'assertPreConditions',
'assertPostConditions',
'tearDown',
);
foreach ($templateMethods as $templateMethod) {
if ($class
->hasMethod($templateMethod)) {
$reflector = $class
->getMethod($templateMethod);
$docComment .= PHP_EOL . substr($reflector
->getDocComment(), 3, -2);
unset($reflector);
}
}
if (strpos($docComment, '@coversNothing') !== FALSE) {
return FALSE;
}
$classShortcut = preg_match_all('(@coversDefaultClass\\s+(?P<coveredClass>[^\\s]++)\\s*$)m', $class
->getDocComment(), $matches);
if ($classShortcut) {
if ($classShortcut > 1) {
throw new PHP_CodeCoverage_Exception(sprintf('More than one @coversClass annotation in class or interface "%s".', $className));
}
$classShortcut = $matches['coveredClass'][0];
}
$match = preg_match_all('(@covers\\s+(?P<coveredElement>[^\\s()]++)[\\s()]*$)m', $docComment, $matches);
if ($match) {
foreach ($matches['coveredElement'] as $coveredElement) {
if ($classShortcut && strncmp($coveredElement, '::', 2) === 0) {
$coveredElement = $classShortcut . $coveredElement;
}
$codeToCoverList = array_merge($codeToCoverList, $this
->resolveCoversToReflectionObjects($coveredElement));
}
foreach ($codeToCoverList as $codeToCover) {
$fileName = $codeToCover
->getFileName();
if (!isset($result[$fileName])) {
$result[$fileName] = array();
}
$result[$fileName] = array_unique(array_merge($result[$fileName], range($codeToCover
->getStartLine(), $codeToCover
->getEndLine())));
}
}
return $result;
}