本文整理汇总了PHP中PHPUnit_Framework_TestResult::topTestSuite方法的典型用法代码示例。如果您正苦于以下问题:PHP PHPUnit_Framework_TestResult::topTestSuite方法的具体用法?PHP PHPUnit_Framework_TestResult::topTestSuite怎么用?PHP PHPUnit_Framework_TestResult::topTestSuite使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PHPUnit_Framework_TestResult
的用法示例。
在下文中一共展示了PHPUnit_Framework_TestResult::topTestSuite方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: storeCodeCoverage
/**
* Stores code coverage information.
*
* @param PHPUnit_Framework_TestResult $result
* @param integer $revision
* @access public
*/
public function storeCodeCoverage(PHPUnit_Framework_TestResult $result, $revision)
{
$codeCoverage = $result->getCodeCoverageInformation(FALSE, TRUE);
$summary = PHPUnit_Util_CodeCoverage::getSummary($codeCoverage);
$files = array_keys($summary);
$commonPath = PHPUnit_Util_Filesystem::getCommonPath($files);
$this->dbh->beginTransaction();
foreach ($files as $file) {
$filename = str_replace($commonPath, '', $file);
$fileId = FALSE;
$lines = file($file);
$numLines = count($lines);
$stmt = $this->dbh->query(sprintf('SELECT code_file_id
FROM code_file
WHERE code_file_name = "%s"
AND revision = %d;', $filename, $revision));
if ($stmt) {
$fileId = (int) $stmt->fetchColumn();
}
unset($stmt);
if ($fileId == 0) {
$this->dbh->exec(sprintf('INSERT INTO code_file
(code_file_name, code_file_md5, revision)
VALUES("%s", "%s", %d);', $filename, md5_file($file), $revision));
$fileId = $this->dbh->lastInsertId();
$classes = PHPUnit_Util_Class::getClassesInFile($file, $commonPath);
foreach ($classes as $class) {
$this->dbh->exec(sprintf('INSERT INTO code_class
(code_file_id, code_class_name,
code_class_start_line, code_class_end_line)
VALUES(%d, "%s", %d, %d);', $fileId, $class->getName(), $class->getStartLine(), $class->getEndLine()));
$classId = $this->dbh->lastInsertId();
foreach ($class->getMethods() as $method) {
if ($class->getName() != $method->getDeclaringClass()->getName()) {
continue;
}
$this->dbh->exec(sprintf('INSERT INTO code_method
(code_class_id, code_method_name,
code_method_start_line, code_method_end_line)
VALUES(%d, "%s", %d, %d);', $classId, $method->getName(), $method->getStartLine(), $method->getEndLine()));
}
}
$i = 1;
foreach ($lines as $line) {
$this->dbh->exec(sprintf('INSERT INTO code_line
(code_file_id, code_line_number, code_line,
code_line_covered)
VALUES(%d, %d, "%s", %d);', $fileId, $i, trim($line), isset($summary[$file][$i]) ? $summary[$file][$i] : 0));
$i++;
}
}
for ($lineNumber = 1; $lineNumber <= $numLines; $lineNumber++) {
$coveringTests = PHPUnit_Util_CodeCoverage::getCoveringTests($codeCoverage, $file, $lineNumber);
if (is_array($coveringTests)) {
$stmt = $this->dbh->query(sprintf('SELECT code_line_id, code_line_covered
FROM code_line
WHERE code_file_id = %d
AND code_line_number = %d;', $fileId, $lineNumber));
$codeLineId = (int) $stmt->fetchColumn(0);
$oldCoverageFlag = (int) $stmt->fetchColumn(1);
unset($stmt);
$newCoverageFlag = $summary[$file][$lineNumber];
if ($oldCoverageFlag == 0 && $newCoverageFlag != 0 || $oldCoverageFlag < 0 && $newCoverageFlag > 0) {
$this->dbh->exec(sprintf('UPDATE code_line
SET code_line_covered = %d
WHERE code_line_id = %d;', $newCoverageFlag, $codeLineId));
}
foreach ($coveringTests as $test) {
$this->dbh->exec(sprintf('INSERT INTO code_coverage
(test_id, code_line_id)
VALUES(%d, %d);', $test->__db_id, $codeLineId));
}
}
}
}
foreach ($result->topTestSuite() as $test) {
if ($test instanceof PHPUnit_Framework_TestCase) {
$stmt = $this->dbh->query(sprintf('SELECT code_method.code_method_id
FROM code_class, code_method
WHERE code_class.code_class_id = code_method.code_class_id
AND code_class.code_class_name = "%s"
AND code_method.code_method_name = "%s";', get_class($test), $test->getName()));
$methodId = (int) $stmt->fetchColumn();
unset($stmt);
$this->dbh->exec(sprintf('UPDATE test
SET code_method_id = %d
WHERE test_id = %d;', $methodId, $test->__db_id));
}
}
$this->dbh->commit();
}
示例2: process
/**
* @param PHPUnit_Framework_TestResult $result
* @todo Count conditionals.
*/
public function process(PHPUnit_Framework_TestResult $result)
{
$time = time();
$document = new DOMDocument('1.0', 'UTF-8');
$document->formatOutput = TRUE;
$coverage = $document->createElement('coverage');
$coverage->setAttribute('generated', $time);
$coverage->setAttribute('phpunit', PHPUnit_Runner_Version::id());
$document->appendChild($coverage);
$project = $document->createElement('project');
$project->setAttribute('name', $result->topTestSuite()->getName());
$project->setAttribute('timestamp', $time);
$coverage->appendChild($project);
$codeCoverageInformation = $result->getCodeCoverageInformation();
$files = PHPUnit_Util_CodeCoverage::getSummary($codeCoverageInformation);
$packages = array();
$projectFiles = 0;
$projectLoc = 0;
$projectNcloc = 0;
$projectClasses = 0;
$projectMethods = 0;
$projectCoveredMethods = 0;
$projectConditionals = 0;
$projectCoveredConditionals = 0;
$projectStatements = 0;
$projectCoveredStatements = 0;
foreach ($files as $filename => $data) {
$projectFiles++;
$fileClasses = 0;
$fileConditionals = 0;
$fileCoveredConditionals = 0;
$fileStatements = 0;
$fileCoveredStatements = 0;
$fileMethods = 0;
$fileCoveredMethods = 0;
$file = $document->createElement('file');
$file->setAttribute('name', $filename);
$namespace = 'global';
$classes = PHPUnit_Util_Class::getClassesInFile($filename);
$lines = array();
foreach ($classes as $class) {
if ($class->isInterface()) {
continue;
}
$className = $class->getName();
$methods = $class->getMethods();
$packageInformation = PHPUnit_Util_Class::getPackageInformation($className);
$numMethods = 0;
$fileClasses++;
$projectClasses++;
if (!empty($packageInformation['namespace'])) {
$namespace = $packageInformation['namespace'];
}
$classConditionals = 0;
$classCoveredConditionals = 0;
$classStatements = 0;
$classCoveredStatements = 0;
$classCoveredMethods = 0;
foreach ($methods as $method) {
if ($method->getDeclaringClass()->getName() == $class->getName()) {
$startLine = $method->getStartLine();
$endLine = $method->getEndLine();
$tests = array();
for ($i = $startLine; $i <= $endLine; $i++) {
if (isset($files[$filename][$i])) {
if (is_array($files[$filename][$i])) {
foreach ($files[$filename][$i] as $_test) {
$add = TRUE;
foreach ($tests as $test) {
if ($test === $_test) {
$add = FALSE;
break;
}
}
if ($add) {
$tests[] = $_test;
}
}
$classCoveredStatements++;
}
$classStatements++;
}
}
$count = count($tests);
$lines[$startLine] = array('count' => $count, 'type' => 'method');
if ($count > 0) {
$classCoveredMethods++;
$fileCoveredMethods++;
$projectCoveredMethods++;
}
$classStatements--;
$numMethods++;
$fileMethods++;
$projectMethods++;
}
}
//.........这里部分代码省略.........
示例3: storeCodeCoverage
//.........这里部分代码省略.........
for ($lineNumber = 1; $lineNumber <= $fileLoc; $lineNumber++) {
$coveringTests = PHPUnit_Util_CodeCoverage::getCoveringTests($codeCoverage, $fileName, $lineNumber);
if (is_array($coveringTests)) {
$stmt->bindParam(':fileId', $fileId, PDO::PARAM_INT);
$stmt->bindParam(':lineNumber', $lineNumber, PDO::PARAM_INT);
$stmt->execute();
$codeLineId = (int) $stmt->fetchColumn(0);
$oldCoverageFlag = (int) $stmt->fetchColumn(1);
$newCoverageFlag = isset($summary[$fileName][$lineNumber]) ? 1 : 0;
if ($oldCoverageFlag == 0 && $newCoverageFlag != 0 || $oldCoverageFlag < 0 && $newCoverageFlag > 0) {
$stmt2->bindParam(':lineCovered', $newCoverageFlag, PDO::PARAM_INT);
$stmt2->bindParam(':lineId', $codeLineId, PDO::PARAM_INT);
$stmt2->execute();
}
foreach ($coveringTests as $test) {
$stmt3->bindParam(':testId', $test->__db_id, PDO::PARAM_INT);
$stmt3->bindParam(':lineId', $codeLineId, PDO::PARAM_INT);
$stmt3->execute();
}
}
}
}
unset($stmt);
unset($stmt2);
unset($stmt3);
$stmt = $this->dbh->prepare('SELECT code_method.code_method_id
FROM code_class, code_method
WHERE code_class.code_class_id = code_method.code_class_id
AND code_class.code_class_name = :className
AND code_method.code_method_name = :methodName;');
$stmt2 = $this->dbh->prepare('UPDATE test
SET code_method_id = :methodId
WHERE test_id = :testId;');
foreach ($result->topTestSuite() as $test) {
if ($test instanceof PHPUnit_Framework_TestCase) {
$className = get_class($test);
$methodName = $test->getName();
$stmt->bindParam(':className', $className, PDO::PARAM_STR);
$stmt->bindParam(':methodName', $methodName, PDO::PARAM_STR);
$stmt->execute();
$methodId = (int) $stmt->fetchColumn();
$stmt->closeCursor();
$stmt2->bindParam(':methodId', $methodId, PDO::PARAM_INT);
$stmt2->bindParam(':testId', $test->__db_id, PDO::PARAM_INT);
$stmt2->execute();
}
}
unset($stmt);
unset($stmt2);
$stmt = $this->dbh->prepare('INSERT INTO metrics_project
(run_id, metrics_project_cls, metrics_project_clsa,
metrics_project_clsc, metrics_project_roots,
metrics_project_leafs, metrics_project_interfs,
metrics_project_maxdit)
VALUES(:runId, :cls, :clsa, :clsc, :roots, :leafs,
:interfs, :maxdit);');
$cls = $projectMetrics->getCLS();
$clsa = $projectMetrics->getCLSa();
$clsc = $projectMetrics->getCLSc();
$interfs = $projectMetrics->getInterfs();
$roots = $projectMetrics->getRoots();
$leafs = $projectMetrics->getLeafs();
$maxDit = $projectMetrics->getMaxDit();
$stmt->bindParam(':runId', $runId, PDO::PARAM_INT);
$stmt->bindParam(':cls', $cls, PDO::PARAM_INT);
$stmt->bindParam(':clsa', $clsa, PDO::PARAM_INT);
示例4: render
/**
* Renders the report.
*
* @param PHPUnit_Framework_TestResult $result
* @param string $title
* @param string $target
* @param string $charset
* @param boolean $yui
* @param boolean $highlight
* @param integer $lowUpperBound
* @param integer $highLowerBound
*/
public static function render(PHPUnit_Framework_TestResult $result, $target, $title = '', $charset = 'ISO-8859-1', $yui = TRUE, $highlight = FALSE, $lowUpperBound = 35, $highLowerBound = 70)
{
$target = PHPUnit_Util_Filesystem::getDirectory($target);
self::$templatePath = sprintf('%s%sReport%sTemplate%s', dirname(__FILE__), DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR);
$codeCoverageInformation = $result->getCodeCoverageInformation();
$files = PHPUnit_Util_CodeCoverage::getSummary($codeCoverageInformation);
$commonPath = PHPUnit_Util_Filesystem::reducePaths($files);
$items = self::buildDirectoryStructure($files);
unset($codeCoverageInformation);
if ($title == '') {
$topTestSuite = $result->topTestSuite();
if ($topTestSuite instanceof PHPUnit_Framework_TestSuite) {
$title = $topTestSuite->getName();
}
}
unset($result);
$root = new PHPUnit_Util_Report_Node_Directory($commonPath, NULL);
self::addItems($root, $items, $files, $yui, $highlight);
self::copyFiles($target);
PHPUnit_Util_CodeCoverage::clearSummary();
$root->render($target, $title, $charset, $lowUpperBound, $highLowerBound);
}
示例5: getTests
/**
* @param PHPUnit_Framework_TestResult $result
* @param PHPUnit_Framework_TestSuite $testSuite
* @return array
* @access protected
* @since Method available since Release 3.0.0
*/
protected static function getTests(PHPUnit_Framework_TestResult $result, PHPUnit_Framework_TestSuite $testSuite = NULL)
{
if ($testSuite === NULL) {
$testSuite = $result->topTestSuite();
}
$tests = array();
foreach ($testSuite->tests() as $test) {
if ($test instanceof PHPUnit_Framework_TestSuite) {
$tests = array_merge($tests, self::getTests($result, $test));
} else {
$testName = PHPUnit_Util_Test::describe($test, FALSE);
$tests[] = array('name' => $testName[1], 'object' => $test, 'result' => PHPUnit_Util_Test::lookupResult($test, $result));
}
}
return array($testSuite->getName() => $tests);
}
示例6: process
/**
* @param PHPUnit_Framework_TestResult $result
* @todo Count conditionals.
*/
public function process(PHPUnit_Framework_TestResult $result)
{
$time = time();
$document = new DOMDocument('1.0', 'UTF-8');
$document->formatOutput = TRUE;
$coverage = $document->createElement('coverage');
$coverage->setAttribute('generated', $time);
$coverage->setAttribute('phpunit', PHPUnit_Runner_Version::id());
$document->appendChild($coverage);
$project = $document->createElement('project');
$project->setAttribute('name', $result->topTestSuite()->getName());
$project->setAttribute('timestamp', $time);
$coverage->appendChild($project);
$codeCoverageInformation = $result->getCodeCoverageInformation();
$files = PHPUnit_Util_CodeCoverage::getSummary($codeCoverageInformation);
$packages = array();
$projectStatistics = array('files' => 0, 'loc' => 0, 'ncloc' => 0, 'classes' => 0, 'methods' => 0, 'coveredMethods' => 0, 'conditionals' => 0, 'coveredConditionals' => 0, 'statements' => 0, 'coveredStatements' => 0);
foreach ($files as $filename => $data) {
$namespace = 'global';
if (file_exists($filename)) {
$fileStatistics = array('classes' => 0, 'methods' => 0, 'coveredMethods' => 0, 'conditionals' => 0, 'coveredConditionals' => 0, 'statements' => 0, 'coveredStatements' => 0);
$file = $document->createElement('file');
$file->setAttribute('name', $filename);
$classesInFile = PHPUnit_Util_File::getClassesInFile($filename);
$lines = array();
foreach ($classesInFile as $className => $_class) {
$classStatistics = array('methods' => 0, 'coveredMethods' => 0, 'conditionals' => 0, 'coveredConditionals' => 0, 'statements' => 0, 'coveredStatements' => 0);
foreach ($_class['methods'] as $methodName => $method) {
$classStatistics['methods']++;
$methodCount = 0;
for ($i = $method['startLine']; $i <= $method['endLine']; $i++) {
$add = TRUE;
$count = 0;
if (isset($files[$filename][$i])) {
if ($files[$filename][$i] != -2) {
$classStatistics['statements']++;
}
if (is_array($files[$filename][$i])) {
$classStatistics['coveredStatements']++;
$count = count($files[$filename][$i]);
} else {
if ($files[$filename][$i] == -2) {
$add = FALSE;
}
}
} else {
$add = FALSE;
}
$methodCount = max($methodCount, $count);
if ($add) {
$lines[$i] = array('count' => $count, 'type' => 'stmt');
}
}
if ($methodCount > 0) {
$classStatistics['coveredMethods']++;
}
$lines[$method['startLine']] = array('count' => $methodCount, 'type' => 'method', 'name' => $methodName);
}
$packageInformation = PHPUnit_Util_Class::getPackageInformation($className, $_class['docComment']);
if (!empty($packageInformation['namespace'])) {
$namespace = $packageInformation['namespace'];
}
$class = $document->createElement('class');
$class->setAttribute('name', $className);
$class->setAttribute('namespace', $namespace);
if (!empty($packageInformation['fullPackage'])) {
$class->setAttribute('fullPackage', $packageInformation['fullPackage']);
}
if (!empty($packageInformation['category'])) {
$class->setAttribute('category', $packageInformation['category']);
}
if (!empty($packageInformation['package'])) {
$class->setAttribute('package', $packageInformation['package']);
}
if (!empty($packageInformation['subpackage'])) {
$class->setAttribute('subpackage', $packageInformation['subpackage']);
}
$file->appendChild($class);
$metrics = $document->createElement('metrics');
$metrics->setAttribute('methods', $classStatistics['methods']);
$metrics->setAttribute('coveredmethods', $classStatistics['coveredMethods']);
//$metrics->setAttribute('conditionals', $classStatistics['conditionals']);
//$metrics->setAttribute('coveredconditionals', $classStatistics['coveredConditionals']);
$metrics->setAttribute('statements', $classStatistics['statements']);
$metrics->setAttribute('coveredstatements', $classStatistics['coveredStatements']);
$metrics->setAttribute('elements', $classStatistics['conditionals'] + $classStatistics['statements'] + $classStatistics['methods']);
$metrics->setAttribute('coveredelements', $classStatistics['coveredConditionals'] + $classStatistics['coveredStatements'] + $classStatistics['coveredMethods']);
$class->appendChild($metrics);
$fileStatistics['methods'] += $classStatistics['methods'];
$fileStatistics['coveredMethods'] += $classStatistics['coveredMethods'];
$fileStatistics['conditionals'] += $classStatistics['conditionals'];
$fileStatistics['coveredConditionals'] += $classStatistics['coveredConditionals'];
$fileStatistics['statements'] += $classStatistics['statements'];
$fileStatistics['coveredStatements'] += $classStatistics['coveredStatements'];
$fileStatistics['classes']++;
}
//.........这里部分代码省略.........
示例7: printResult
/**
* Print the final results in HTML format.
*
* The output is printed using the templates in the given
* template directory {@link $tpldir}.
*
* @param PHPUnit_Framework_TestResult $result
* @return void
*/
public function printResult(PHPUnit_Framework_TestResult $result)
{
$title = $result->topTestSuite()->getName();
$suiteno = 0;
$numsuites = count($this->results['suites']);
include $this->tpldir . '/header.php';
foreach ($this->results['suites'] as $suitename => $suite) {
if ($suitename && count($suite['tests'])) {
include $this->tpldir . '/suite.php';
}
$suiteno++;
}
include $this->tpldir . '/footer.php';
}