/**
* Returns the methods of the class under test
* that are called from the test methods.
*
* @return array
*/
protected function findTestedMethods()
{
$setUpVariables = array();
$testedMethods = array();
$classes = PHPUnit_Util_File::getClassesInFile($this->inSourceFile);
$testMethods = $classes[$this->inClassName['fullyQualifiedClassName']]['methods'];
unset($classes);
foreach ($testMethods as $name => $testMethod) {
if (strtolower($name) == 'setup') {
$setUpVariables = $this->findVariablesThatReferenceClass($testMethod['tokens']);
break;
}
}
foreach ($testMethods as $name => $testMethod) {
$argVariables = array();
if (strtolower($name) == 'setup') {
continue;
}
$start = strpos($testMethod['signature'], '(') + 1;
$end = strlen($testMethod['signature']) - $start - 1;
$args = substr($testMethod['signature'], $start, $end);
foreach (explode(',', $args) as $arg) {
$arg = explode(' ', trim($arg));
if (count($arg) == 2) {
$type = $arg[0];
$var = $arg[1];
} else {
$type = NULL;
$var = $arg[0];
}
if ($type == $this->outClassName['fullyQualifiedClassName']) {
$argVariables[] = $var;
}
}
$variables = array_unique(array_merge($setUpVariables, $argVariables, $this->findVariablesThatReferenceClass($testMethod['tokens'])));
foreach ($testMethod['tokens'] as $i => $token) {
// Class::method()
if (is_array($token) && $token[0] == T_DOUBLE_COLON && is_array($testMethod['tokens'][$i - 1]) && $testMethod['tokens'][$i - 1][0] == T_STRING && $testMethod['tokens'][$i - 1][1] == $this->outClassName['fullyQualifiedClassName'] && is_array($testMethod['tokens'][$i + 1]) && $testMethod['tokens'][$i + 1][0] == T_STRING && $testMethod['tokens'][$i + 2] == '(') {
$testedMethods[] = $testMethod['tokens'][$i + 1][1];
} else {
if (is_array($token) && $token[0] == T_OBJECT_OPERATOR && in_array($this->findVariableName($testMethod['tokens'], $i), $variables) && is_array($testMethod['tokens'][$i + 2]) && $testMethod['tokens'][$i + 2][0] == T_OBJECT_OPERATOR && is_array($testMethod['tokens'][$i + 3]) && $testMethod['tokens'][$i + 3][0] == T_STRING && $testMethod['tokens'][$i + 4] == '(') {
$testedMethods[] = $testMethod['tokens'][$i + 3][1];
} else {
if (is_array($token) && $token[0] == T_OBJECT_OPERATOR && in_array($this->findVariableName($testMethod['tokens'], $i), $variables) && is_array($testMethod['tokens'][$i + 1]) && $testMethod['tokens'][$i + 1][0] == T_STRING && $testMethod['tokens'][$i + 2] == '(') {
$testedMethods[] = $testMethod['tokens'][$i + 1][1];
}
}
}
}
}
$testedMethods = array_unique($testedMethods);
sort($testedMethods);
return $testedMethods;
}