You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@shindig.apache.org by ch...@apache.org on 2008/06/06 16:56:03 UTC

svn commit: r663970 [18/25] - in /incubator/shindig/trunk/php: ./ test/ test/PHPUnit/ test/PHPUnit/Extensions/ test/PHPUnit/Extensions/Database/ test/PHPUnit/Extensions/Database/Constraint/ test/PHPUnit/Extensions/Database/DB/ test/PHPUnit/Extensions/D...

Added: incubator/shindig/trunk/php/test/PHPUnit/Util/Log/CodeCoverage/Database.php
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/test/PHPUnit/Util/Log/CodeCoverage/Database.php?rev=663970&view=auto
==============================================================================
--- incubator/shindig/trunk/php/test/PHPUnit/Util/Log/CodeCoverage/Database.php (added)
+++ incubator/shindig/trunk/php/test/PHPUnit/Util/Log/CodeCoverage/Database.php Fri Jun  6 07:55:55 2008
@@ -0,0 +1,587 @@
+<?php
+/**
+ * PHPUnit
+ *
+ * Copyright (c) 2002-2008, Sebastian Bergmann <sb...@sebastian-bergmann.de>.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ *   * Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ *
+ *   * Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in
+ *     the documentation and/or other materials provided with the
+ *     distribution.
+ *
+ *   * Neither the name of Sebastian Bergmann nor the names of his
+ *     contributors may be used to endorse or promote products derived
+ *     from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * @category   Testing
+ * @package    PHPUnit
+ * @author     Sebastian Bergmann <sb...@sebastian-bergmann.de>
+ * @copyright  2002-2008 Sebastian Bergmann <sb...@sebastian-bergmann.de>
+ * @license    http://www.opensource.org/licenses/bsd-license.php  BSD License
+ * @version    SVN: $Id: Database.php 1985 2007-12-26 18:11:55Z sb $
+ * @link       http://www.phpunit.de/
+ * @since      File available since Release 3.1.4
+ */
+
+require_once '../PHPUnit/Framework.php';
+require_once '../PHPUnit/Util/Metrics/Project.php';
+require_once '../PHPUnit/Util/Class.php';
+require_once '../PHPUnit/Util/CodeCoverage.php';
+require_once '../PHPUnit/Util/Filesystem.php';
+require_once '../PHPUnit/Util/Filter.php';
+
+PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT');
+
+/**
+ * 
+ *
+ * @category   Testing
+ * @package    PHPUnit
+ * @author     Sebastian Bergmann <sb...@sebastian-bergmann.de>
+ * @copyright  2002-2008 Sebastian Bergmann <sb...@sebastian-bergmann.de>
+ * @license    http://www.opensource.org/licenses/bsd-license.php  BSD License
+ * @version    Release: 3.2.9
+ * @link       http://www.phpunit.de/
+ * @since      Class available since Release 3.1.4
+ */
+class PHPUnit_Util_Log_CodeCoverage_Database
+{
+    /**
+     * @var    PDO
+     * @access protected
+     */
+    protected $dbh;
+
+    /**
+     * Constructor.
+     *
+     * @param  PDO $dbh
+     * @throws PDOException
+     * @access public
+     */
+    public function __construct(PDO $dbh)
+    {
+        $this->dbh = $dbh;
+    }
+
+    /**
+     * Stores code coverage information.
+     *
+     * @param  PHPUnit_Framework_TestResult $result
+     * @param  integer                      $runId
+     * @param  integer                      $revision
+     * @param  string                       $commonPath
+     * @access public
+     */
+    public function storeCodeCoverage(PHPUnit_Framework_TestResult $result, $runId, $revision, $commonPath = '')
+    {
+        $codeCoverage   = $result->getCodeCoverageInformation(FALSE, TRUE);
+        $summary        = PHPUnit_Util_CodeCoverage::getSummary($codeCoverage);
+        $files          = array_keys($summary);
+        $projectMetrics = new PHPUnit_Util_Metrics_Project($files, $summary);
+        $storedClasses  = array();
+
+        if (empty($commonPath)) {
+            $commonPath = PHPUnit_Util_Filesystem::getCommonPath($files);
+        }
+
+        $this->dbh->beginTransaction();
+
+        foreach ($files as $file) {
+            $filename    = str_replace($commonPath, '', $file);
+            $fileId      = FALSE;
+            $fileMetrics = $projectMetrics->getFile($file);
+            $lines       = $fileMetrics->getLines();
+            $hash        = md5_file($file);
+
+            $stmt = $this->dbh->prepare(
+              'SELECT code_file_id
+                 FROM code_file
+                WHERE code_file_name = :filename
+                  AND revision       = :revision;'
+            );
+
+            $stmt->bindParam(':filename', $filename, PDO::PARAM_STR);
+            $stmt->bindParam(':revision', $revision, PDO::PARAM_INT);
+            $stmt->execute();
+
+            if ($stmt) {
+                $fileId = (int)$stmt->fetchColumn();
+            }
+
+            unset($stmt);
+
+            if ($fileId == 0) {
+                $stmt = $this->dbh->prepare(
+                  'INSERT INTO code_file
+                               (code_file_name, code_file_md5, revision)
+                         VALUES(:filename, :hash, :revision);'
+                );
+
+                $stmt->bindParam(':filename', $filename, PDO::PARAM_STR);
+                $stmt->bindParam(':hash', $hash, PDO::PARAM_STR);
+                $stmt->bindParam(':revision', $revision, PDO::PARAM_INT);
+                $stmt->execute();
+
+                $fileId  = $this->dbh->lastInsertId();
+
+                $stmt = $this->dbh->prepare(
+                  'INSERT INTO code_class
+                               (code_file_id, code_class_name,
+                                code_class_start_line, code_class_end_line)
+                         VALUES(:fileId, :className, :startLine, :endLine);'
+                );
+
+                foreach ($fileMetrics->getClasses() as $classMetrics) {
+                    $className      = $classMetrics->getClass()->getName();
+                    $classStartLine = $classMetrics->getClass()->getStartLine();
+                    $classEndLine   = $classMetrics->getClass()->getEndLine();
+
+                    $stmt->bindParam(':fileId', $fileId, PDO::PARAM_INT);
+                    $stmt->bindParam(':className', $className, PDO::PARAM_STR);
+                    $stmt->bindParam(':startLine', $classStartLine, PDO::PARAM_INT);
+                    $stmt->bindParam(':endLine', $classEndLine, PDO::PARAM_INT);
+                    $stmt->execute();
+
+                    $classId                   = $this->dbh->lastInsertId();
+                    $storedClasses[$className] = $classId;
+
+                    $stmt2 = $this->dbh->prepare(
+                      'INSERT INTO code_method
+                                   (code_class_id, code_method_name,
+                                    code_method_start_line, code_method_end_line)
+                             VALUES(:classId, :methodName, :startLine, :endLine);'
+                    );
+
+                    foreach ($classMetrics->getMethods() as $methodMetrics) {
+                        $methodName       = $methodMetrics->getMethod()->getName();
+                        $methodStartLine  = $methodMetrics->getMethod()->getStartLine();
+                        $methodEndLine    = $methodMetrics->getMethod()->getEndLine();
+
+                        $stmt2->bindParam(':classId', $classId, PDO::PARAM_INT);
+                        $stmt2->bindParam(':methodName', $methodName, PDO::PARAM_STR);
+                        $stmt2->bindParam(':startLine', $methodStartLine, PDO::PARAM_INT);
+                        $stmt2->bindParam(':endLine', $methodEndLine, PDO::PARAM_INT);
+                        $stmt2->execute();
+                    }
+
+                    unset($stmt2);
+                }
+
+                $stmt = $this->dbh->prepare(
+                  'INSERT INTO code_line
+                               (code_file_id, code_line_number, code_line,
+                                code_line_covered)
+                         VALUES(:fileId, :lineNumber, :line, :covered);'
+                );
+
+                $i = 1;
+
+                foreach ($lines as $line) {
+                    $covered = isset($summary[$file][$i]) ? 1 : 0;
+
+                    $stmt->bindParam(':fileId', $fileId, PDO::PARAM_INT);
+                    $stmt->bindParam(':lineNumber', $i, PDO::PARAM_INT);
+                    $stmt->bindParam(':line', $line, PDO::PARAM_STR);
+                    $stmt->bindParam(':covered', $covered, PDO::PARAM_INT);
+                    $stmt->execute();
+
+                    $i++;
+                }
+            }
+
+            $stmt = $this->dbh->prepare(
+              'INSERT INTO metrics_file
+                           (run_id, code_file_id, metrics_file_coverage,
+                           metrics_file_loc, metrics_file_cloc, metrics_file_ncloc,
+                           metrics_file_loc_executable, metrics_file_loc_executed)
+                     VALUES(:runId, :fileId, :coverage, :loc, :cloc, :ncloc,
+                            :locExecutable, :locExecuted);'
+            );
+
+            $fileCoverage      = $fileMetrics->getCoverage();
+            $fileLoc           = $fileMetrics->getLoc();
+            $fileCloc          = $fileMetrics->getCloc();
+            $fileNcloc         = $fileMetrics->getNcloc();
+            $fileLocExecutable = $fileMetrics->getLocExecutable();
+            $fileLocExecuted   = $fileMetrics->getLocExecuted();
+
+            $stmt->bindParam(':runId', $runId, PDO::PARAM_INT);
+            $stmt->bindParam(':fileId', $fileId, PDO::PARAM_INT);
+            $stmt->bindParam(':coverage', $fileCoverage);
+            $stmt->bindParam(':loc', $fileLoc, PDO::PARAM_INT);
+            $stmt->bindParam(':cloc', $fileCloc, PDO::PARAM_INT);
+            $stmt->bindParam(':ncloc', $fileNcloc, PDO::PARAM_INT);
+            $stmt->bindParam(':locExecutable', $fileLocExecutable, PDO::PARAM_INT);
+            $stmt->bindParam(':locExecuted', $fileLocExecuted, PDO::PARAM_INT);
+            $stmt->execute();
+
+            $stmtSelectFunctionId = $this->dbh->prepare(
+              'SELECT code_function_id
+                 FROM code_file, code_function
+                WHERE code_function.code_file_id       = code_file.code_file_id
+                  AND code_file.revision               = :revision
+                  AND code_function.code_function_name = :functionName;'
+            );
+
+            $stmtInsertFunction = $this->dbh->prepare(
+              'INSERT INTO metrics_function
+                           (run_id, code_function_id, metrics_function_coverage,
+                           metrics_function_loc, metrics_function_loc_executable, metrics_function_loc_executed,
+                           metrics_function_ccn, metrics_function_crap, metrics_function_npath)
+                     VALUES(:runId, :functionId, :coverage, :loc,
+                            :locExecutable, :locExecuted, :ccn, :crap, :npath);'
+            );
+
+            $stmtSelectClassId = $this->dbh->prepare(
+              'SELECT code_class_id
+                 FROM code_file, code_class
+                WHERE code_class.code_file_id    = code_file.code_file_id
+                  AND code_file.revision         = :revision
+                  AND code_class.code_class_name = :className;'
+            );
+
+            $stmtInsertClass = $this->dbh->prepare(
+              'INSERT INTO metrics_class
+                           (run_id, code_class_id, metrics_class_coverage,
+                           metrics_class_loc, metrics_class_loc_executable, metrics_class_loc_executed,
+                           metrics_class_aif, metrics_class_ahf,
+                           metrics_class_cis, metrics_class_csz, metrics_class_dit,
+                           metrics_class_impl, metrics_class_mif, metrics_class_mhf,
+                           metrics_class_noc, metrics_class_pf, metrics_class_vars,
+                           metrics_class_varsnp, metrics_class_varsi,
+                           metrics_class_wmc, metrics_class_wmcnp, metrics_class_wmci)
+                     VALUES(:runId, :classId, :coverage, :loc, :locExecutable,
+                            :locExecuted, :aif, :ahf, :cis, :csz, :dit, :impl, 
+                            :mif, :mhf, :noc, :pf, :vars, :varsnp, :varsi,
+                            :wmc, :wmcnp, :wmci);'
+            );
+
+            $stmtSelectMethodId = $this->dbh->prepare(
+              'SELECT code_method_id
+                 FROM code_file, code_class, code_method
+                WHERE code_class.code_file_id      = code_file.code_file_id
+                  AND code_class.code_class_id     = code_method.code_class_id
+                  AND code_file.revision           = :revision
+                  AND code_class.code_class_name   = :className
+                  AND code_method.code_method_name = :methodName;'
+            );
+
+            $stmtInsertMethod = $this->dbh->prepare(
+              'INSERT INTO metrics_method
+                           (run_id, code_method_id, metrics_method_coverage,
+                           metrics_method_loc, metrics_method_loc_executable, metrics_method_loc_executed,
+                           metrics_method_ccn, metrics_method_crap, metrics_method_npath)
+                     VALUES(:runId, :methodId, :coverage, :loc,
+                            :locExecutable, :locExecuted, :ccn, :crap, :npath);'
+            );
+
+            foreach ($fileMetrics->getFunctions() as $functionMetrics) {
+                $functionName = $functionMetrics->getFunction()->getName();
+
+                $stmtSelectFunctionId->bindParam(':functionName', $functionName, PDO::PARAM_STR);
+                $stmtSelectFunctionId->bindParam(':revision', $revision, PDO::PARAM_INT);
+                $stmtSelectFunctionId->execute();
+
+                $functionId    = (int)$stmtSelectFunctionId->fetchColumn();
+                $stmtSelectFunctionId->closeCursor();
+
+                $functionCoverage      = $functionMetrics->getCoverage();
+                $functionLoc           = $functionMetrics->getLoc();
+                $functionLocExecutable = $functionMetrics->getLocExecutable();
+                $functionLocExecuted   = $functionMetrics->getLocExecuted();
+                $functionCcn           = $functionMetrics->getCCN();
+                $functionCrap          = $functionMetrics->getCrapIndex();
+                $functionNpath         = $functionMetrics->getNPath();
+
+                $stmtInsertFunction->bindParam(':runId', $runId, PDO::PARAM_INT);
+                $stmtInsertFunction->bindParam(':functionId', $functionId, PDO::PARAM_INT);
+                $stmtInsertFunction->bindParam(':coverage', $functionCoverage);
+                $stmtInsertFunction->bindParam(':loc', $functionLoc, PDO::PARAM_INT);
+                $stmtInsertFunction->bindParam(':locExecutable', $functionLocExecutable, PDO::PARAM_INT);
+                $stmtInsertFunction->bindParam(':locExecuted', $functionLocExecuted, PDO::PARAM_INT);
+                $stmtInsertFunction->bindParam(':ccn', $functionCcn, PDO::PARAM_INT);
+                $stmtInsertFunction->bindParam(':crap', $functionCrap);
+                $stmtInsertFunction->bindParam(':npath', $functionNpath, PDO::PARAM_INT);
+                $stmtInsertFunction->execute();
+            }
+
+            foreach ($fileMetrics->getClasses() as $classMetrics) {
+                $className = $classMetrics->getClass()->getName();
+
+                $stmtSelectClassId->bindParam(':className', $className, PDO::PARAM_STR);
+                $stmtSelectClassId->bindParam(':revision', $revision, PDO::PARAM_INT);
+                $stmtSelectClassId->execute();
+
+                $classId       = (int)$stmtSelectClassId->fetchColumn();
+                $stmtSelectClassId->closeCursor();
+
+                $classCoverage      = $classMetrics->getCoverage();
+                $classLoc           = $classMetrics->getLoc();
+                $classLocExecutable = $classMetrics->getLocExecutable();
+                $classLocExecuted   = $classMetrics->getLocExecuted();
+                $classAif           = $classMetrics->getAIF();
+                $classAhf           = $classMetrics->getAHF();
+                $classCis           = $classMetrics->getCIS();
+                $classCsz           = $classMetrics->getCSZ();
+                $classDit           = $classMetrics->getDIT();
+                $classImpl          = $classMetrics->getIMPL();
+                $classMif           = $classMetrics->getMIF();
+                $classMhf           = $classMetrics->getMHF();
+                $classNoc           = $classMetrics->getNOC();
+                $classPf            = $classMetrics->getPF();
+                $classVars          = $classMetrics->getVARS();
+                $classVarsnp        = $classMetrics->getVARSnp();
+                $classVarsi         = $classMetrics->getVARSi();
+                $classWmc           = $classMetrics->getWMC();
+                $classWmcnp         = $classMetrics->getWMCnp();
+                $classWmci          = $classMetrics->getWMCi();
+
+                $stmtInsertClass->bindParam(':runId', $runId, PDO::PARAM_INT);
+                $stmtInsertClass->bindParam(':classId', $classId, PDO::PARAM_INT);
+                $stmtInsertClass->bindParam(':coverage', $classCoverage);
+                $stmtInsertClass->bindParam(':loc', $classLoc, PDO::PARAM_INT);
+                $stmtInsertClass->bindParam(':locExecutable', $classLocExecutable, PDO::PARAM_INT);
+                $stmtInsertClass->bindParam(':locExecuted', $classLocExecuted, PDO::PARAM_INT);
+                $stmtInsertClass->bindParam(':aif', $classAif);
+                $stmtInsertClass->bindParam(':ahf', $classAhf);
+                $stmtInsertClass->bindParam(':cis', $classCis, PDO::PARAM_INT);
+                $stmtInsertClass->bindParam(':csz', $classCsz, PDO::PARAM_INT);
+                $stmtInsertClass->bindParam(':dit', $classDit, PDO::PARAM_INT);
+                $stmtInsertClass->bindParam(':impl', $classImpl, PDO::PARAM_INT);
+                $stmtInsertClass->bindParam(':mif', $classMif);
+                $stmtInsertClass->bindParam(':mhf', $classMhf);
+                $stmtInsertClass->bindParam(':noc', $classNoc, PDO::PARAM_INT);
+                $stmtInsertClass->bindParam(':pf', $classPf);
+                $stmtInsertClass->bindParam(':vars', $classVars, PDO::PARAM_INT);
+                $stmtInsertClass->bindParam(':varsnp', $classVarsnp, PDO::PARAM_INT);
+                $stmtInsertClass->bindParam(':varsi', $classVarsi, PDO::PARAM_INT);
+                $stmtInsertClass->bindParam(':wmc', $classWmc, PDO::PARAM_INT);
+                $stmtInsertClass->bindParam(':wmcnp', $classWmcnp, PDO::PARAM_INT);
+                $stmtInsertClass->bindParam(':wmci', $classWmci, PDO::PARAM_INT);
+                $stmtInsertClass->execute();
+
+                foreach ($classMetrics->getMethods() as $methodMetrics) {
+                    $methodName = $methodMetrics->getMethod()->getName();
+
+                    $stmtSelectMethodId->bindParam(':className', $className, PDO::PARAM_STR);
+                    $stmtSelectMethodId->bindParam(':methodName', $methodName, PDO::PARAM_STR);
+                    $stmtSelectMethodId->bindParam(':revision', $revision, PDO::PARAM_INT);
+                    $stmtSelectMethodId->execute();
+
+                    $methodId      = (int)$stmtSelectMethodId->fetchColumn();
+                    $stmtSelectMethodId->closeCursor();
+
+                    $methodCoverage      = $methodMetrics->getCoverage();
+                    $methodLoc           = $methodMetrics->getLoc();
+                    $methodLocExecutable = $methodMetrics->getLocExecutable();
+                    $methodLocExecuted   = $methodMetrics->getLocExecuted();
+                    $methodCcn           = $methodMetrics->getCCN();
+                    $methodCrap          = $methodMetrics->getCrapIndex();
+                    $methodNpath         = $methodMetrics->getNPath();
+
+                    $stmtInsertMethod->bindParam(':runId', $runId, PDO::PARAM_INT);
+                    $stmtInsertMethod->bindParam(':methodId', $methodId, PDO::PARAM_INT);
+                    $stmtInsertMethod->bindParam(':coverage', $methodCoverage);
+                    $stmtInsertMethod->bindParam(':loc', $methodLoc, PDO::PARAM_INT);
+                    $stmtInsertMethod->bindParam(':locExecutable', $methodLocExecutable, PDO::PARAM_INT);
+                    $stmtInsertMethod->bindParam(':locExecuted', $methodLocExecuted, PDO::PARAM_INT);
+                    $stmtInsertMethod->bindParam(':ccn', $methodCcn, PDO::PARAM_INT);
+                    $stmtInsertMethod->bindParam(':crap', $methodCrap);
+                    $stmtInsertMethod->bindParam(':npath', $methodNpath, PDO::PARAM_INT);
+                    $stmtInsertMethod->execute();
+                }
+            }
+
+            unset($stmtSelectFunctionId);
+            unset($stmtInsertFunction);
+            unset($stmtSelectClassId);
+            unset($stmtInsertClass);
+            unset($stmtSelectMethodId);
+            unset($stmtInsertMethod);
+
+            $stmt = $this->dbh->prepare(
+              'SELECT code_line_id, code_line_covered
+                 FROM code_line
+                WHERE code_file_id     = :fileId
+                  AND code_line_number = :lineNumber;'
+            );
+
+            $stmt2 = $this->dbh->prepare(
+              'UPDATE code_line
+                  SET code_line_covered = :lineCovered
+                WHERE code_line_id      = :lineId;'
+            );
+
+            $stmt3 = $this->dbh->prepare(
+              'INSERT INTO code_coverage
+                      (test_id, code_line_id)
+                VALUES(:testId, :lineId);'
+            );
+
+            for ($lineNumber = 1; $lineNumber <= $fileLoc; $lineNumber++) {
+                $coveringTests = PHPUnit_Util_CodeCoverage::getCoveringTests(
+                  $codeCoverage, $file, $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[$file][$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();
+
+                $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);
+        $stmt->bindParam(':clsc', $clsc, PDO::PARAM_INT);
+        $stmt->bindParam(':roots', $roots, PDO::PARAM_INT);
+        $stmt->bindParam(':leafs', $leafs, PDO::PARAM_INT);
+        $stmt->bindParam(':interfs', $interfs, PDO::PARAM_INT);
+        $stmt->bindParam(':maxdit', $maxDit, PDO::PARAM_INT);
+        $stmt->execute();
+
+        unset($stmt);
+
+        $stmt = $this->dbh->prepare(
+          'UPDATE code_class
+              SET code_class_parent_id = :parentClassId
+            WHERE code_class_id = :classId;'
+        );
+
+        $stmt2 = $this->dbh->prepare(
+          'SELECT code_class.code_class_id as code_class_id
+             FROM code_class, code_file
+            WHERE code_class.code_file_id    = code_file.code_file_id
+              AND code_file.revision         = :revision
+              AND code_class.code_class_name = :parentClassName;'
+        );
+
+        foreach ($storedClasses as $className => $classId) {
+            $class       = new ReflectionClass($className);
+            $parentClass = $class->getParentClass();
+
+            if ($parentClass !== FALSE) {
+                $parentClassName = $parentClass->getName();
+                $parentClassId   = 0;
+
+                if (isset($storedClasses[$parentClassName])) {
+                    $parentClassId = $storedClasses[$parentClassName];
+                } else {
+                    $stmt2->bindParam(':parentClassName', $parentClassName, PDO::PARAM_STR);
+                    $stmt2->bindParam(':revision', $revision, PDO::PARAM_INT);
+                    $stmt2->execute();
+
+                    $parentClassId = (int)$stmt->fetchColumn();
+                }
+
+                if ($parentClassId > 0) {
+                    $stmt->bindParam(':classId', $classId, PDO::PARAM_INT);
+                    $stmt->bindParam(':parentClassId', $parentClassId, PDO::PARAM_INT);
+                    $stmt->execute();
+                }
+            }
+        }
+
+        unset($stmt);
+        unset($stmt2);
+
+        $this->dbh->commit();
+    }
+}
+?>

Added: incubator/shindig/trunk/php/test/PHPUnit/Util/Log/CodeCoverage/XML.php
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/test/PHPUnit/Util/Log/CodeCoverage/XML.php?rev=663970&view=auto
==============================================================================
--- incubator/shindig/trunk/php/test/PHPUnit/Util/Log/CodeCoverage/XML.php (added)
+++ incubator/shindig/trunk/php/test/PHPUnit/Util/Log/CodeCoverage/XML.php Fri Jun  6 07:55:55 2008
@@ -0,0 +1,293 @@
+<?php
+/**
+ * PHPUnit
+ *
+ * Copyright (c) 2002-2008, Sebastian Bergmann <sb...@sebastian-bergmann.de>.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ *   * Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ *
+ *   * Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in
+ *     the documentation and/or other materials provided with the
+ *     distribution.
+ *
+ *   * Neither the name of Sebastian Bergmann nor the names of his
+ *     contributors may be used to endorse or promote products derived
+ *     from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * @category   Testing
+ * @package    PHPUnit
+ * @author     Sebastian Bergmann <sb...@sebastian-bergmann.de>
+ * @copyright  2002-2008 Sebastian Bergmann <sb...@sebastian-bergmann.de>
+ * @license    http://www.opensource.org/licenses/bsd-license.php  BSD License
+ * @version    SVN: $Id: XML.php 1985 2007-12-26 18:11:55Z sb $
+ * @link       http://www.phpunit.de/
+ * @since      File available since Release 3.1.4
+ */
+
+require_once '../PHPUnit/Runner/Version.php';
+require_once '../PHPUnit/Util/Metrics/File.php';
+require_once '../PHPUnit/Util/Class.php';
+require_once '../PHPUnit/Util/CodeCoverage.php';
+require_once '../PHPUnit/Util/Filter.php';
+require_once '../PHPUnit/Util/Printer.php';
+
+PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT');
+
+/**
+ * Generates an XML logfile with code coverage information using the
+ * Clover format "documented" at
+ * http://svn.atlassian.com/svn/public/contrib/bamboo/bamboo-coverage-plugin/trunk/src/test/resources/test-clover-report.xml
+ *
+ * @category   Testing
+ * @package    PHPUnit
+ * @author     Sebastian Bergmann <sb...@sebastian-bergmann.de>
+ * @copyright  2002-2008 Sebastian Bergmann <sb...@sebastian-bergmann.de>
+ * @license    http://www.opensource.org/licenses/bsd-license.php  BSD License
+ * @version    Release: 3.2.9
+ * @link       http://www.phpunit.de/
+ * @since      Class available since Release 3.1.4
+ */
+class PHPUnit_Util_Log_CodeCoverage_XML extends PHPUnit_Util_Printer
+{
+    /**
+     * @param  PHPUnit_Framework_TestResult $result
+     * @access public
+     * @todo   Count conditionals.
+     */
+    public function process(PHPUnit_Framework_TestResult $result)
+    {
+        $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);
+
+        $projectFiles               = 0;
+        $projectLoc                 = 0;
+        $projectNcloc               = 0;
+        $projectLinesExecutable     = 0;
+        $projectLinesExecuted       = 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);
+
+            $classes = PHPUnit_Util_Class::getClassesInFile($filename);
+            $lines   = array();
+
+            foreach ($classes as $class) {
+                $methods    = $class->getMethods();
+                $numMethods = 0;
+                $fileClasses++;
+                $projectClasses++;
+
+                $classConditionals        = 0;
+                $classCoveredConditionals = 0;
+                $classStatements          = 0;
+                $classCoveredStatements   = 0;
+                $classCoveredMethods      = 0;
+
+                foreach ($methods as $method) {
+                    if ($method->getDeclaringClass()->getName() == $class->getName()) {
+                        $startLine = $method->getStartLine();
+                        $numMethods++;
+                        $fileMethods++;
+                        $projectMethods++;
+
+                        if ($startLine) {
+                            $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++;
+                            }
+                        }
+                    }
+                }
+
+                $classXML = $document->createElement('class');
+                $classXML->setAttribute('name', $class->getName());
+                $file->appendChild($classXML);
+
+                $classMetricsXML = $document->createElement('metrics');
+                $classMetricsXML->setAttribute('methods', $numMethods);
+                $classMetricsXML->setAttribute('coveredmethods', $classCoveredMethods);
+                //$classMetricsXML->setAttribute('conditionals', $classConditionals);
+                //$classMetricsXML->setAttribute('coveredconditionals', $classCoveredConditionals);
+                $classMetricsXML->setAttribute('statements', $classStatements);
+                $classMetricsXML->setAttribute('coveredstatements', $classCoveredStatements);
+                $classMetricsXML->setAttribute('elements', $classConditionals + $classStatements + $numMethods);
+                $classMetricsXML->setAttribute('coveredelements', $classCoveredConditionals + $classCoveredStatements + $classCoveredMethods);
+                $classXML->appendChild($classMetricsXML);
+
+                $fileStatements += $classStatements;
+                $fileCoveredStatements += $classCoveredStatements;
+            }
+
+            foreach ($data as $_line => $_data) {
+                if (is_array($_data)) {
+                    $count = count($_data);
+                }
+
+                else if ($_data == -1) {
+                    $count = 0;
+                }
+
+                else if ($_data == -2) {
+                    continue;
+                }
+
+                $lines[$_line] = array(
+                  'count' => $count,
+                  'type' => 'stmt'
+                );
+            }
+
+            ksort($lines);
+
+            foreach ($lines as $_line => $_data) {
+                $line = $document->createElement('line');
+                $line->setAttribute('num', $_line);
+                $line->setAttribute('type', $_data['type']);
+                $line->setAttribute('count', $_data['count']);
+
+                $file->appendChild($line);
+            }
+
+            if (file_exists($filename)) {
+                $fileMetrics         = PHPUnit_Util_Metrics_File::factory($filename, $files);
+                $fileLoc             = $fileMetrics->getLoc();
+                $fileNcloc           = $fileMetrics->getNcloc();
+                $fileLinesExecutable = $fileMetrics->getLocExecutable();
+                $fileLinesExecuted   = $fileMetrics->getLocExecuted();
+
+                $fileMetricsXML = $document->createElement('metrics');
+                $fileMetricsXML->setAttribute('loc', $fileLoc);
+                $fileMetricsXML->setAttribute('ncloc', $fileNcloc);
+                $fileMetricsXML->setAttribute('executablelines', $fileLinesExecutable);
+                $fileMetricsXML->setAttribute('executedlines', $fileLinesExecuted);
+                $fileMetricsXML->setAttribute('classes', $fileClasses);
+                $fileMetricsXML->setAttribute('methods', $fileMethods);
+                $fileMetricsXML->setAttribute('coveredmethods', $fileCoveredMethods);
+                //$fileMetricsXML->setAttribute('conditionals', $fileConditionals);
+                //$fileMetricsXML->setAttribute('coveredconditionals', $fileCoveredConditionals);
+                $fileMetricsXML->setAttribute('statements', $fileStatements);
+                $fileMetricsXML->setAttribute('coveredstatements', $fileCoveredStatements);
+                $fileMetricsXML->setAttribute('elements', $fileConditionals + $fileStatements + $fileMethods);
+                $fileMetricsXML->setAttribute('coveredelements', $fileCoveredConditionals + $fileCoveredStatements + $fileCoveredMethods);
+
+                $file->appendChild($fileMetricsXML);
+                $project->appendChild($file);
+
+                $projectLoc               += $fileLoc;
+                $projectNcloc             += $fileNcloc;
+                $projectLinesExecutable   += $fileLinesExecutable;
+                $projectLinesExecuted     += $fileLinesExecuted;
+                $projectStatements        += $fileStatements;
+                $projectCoveredStatements += $fileCoveredStatements;
+            }
+        }
+
+        $projectMetricsXML = $document->createElement('metrics');
+        $projectMetricsXML->setAttribute('files', $projectFiles);
+        $projectMetricsXML->setAttribute('loc', $projectLoc);
+        $projectMetricsXML->setAttribute('ncloc', $projectNcloc);
+        $projectMetricsXML->setAttribute('executablelines', $projectLinesExecutable);
+        $projectMetricsXML->setAttribute('executedlines', $projectLinesExecuted);
+        $projectMetricsXML->setAttribute('classes', $projectClasses);
+        $projectMetricsXML->setAttribute('methods', $projectMethods);
+        $projectMetricsXML->setAttribute('coveredmethods', $projectCoveredMethods);
+        //$projectMetricsXML->setAttribute('conditionals', $projectConditionals);
+        //$projectMetricsXML->setAttribute('coveredconditionals', $projectCoveredConditionals);
+        $projectMetricsXML->setAttribute('statements', $projectStatements);
+        $projectMetricsXML->setAttribute('coveredstatements', $projectCoveredStatements);
+        $projectMetricsXML->setAttribute('elements', $projectConditionals + $projectStatements + $projectMethods);
+        $projectMetricsXML->setAttribute('coveredelements', $projectCoveredConditionals + $projectCoveredStatements + $projectCoveredMethods);
+        $project->appendChild($projectMetricsXML);
+
+        $this->write($document->saveXML());
+        $this->flush();
+    }
+}
+?>

Added: incubator/shindig/trunk/php/test/PHPUnit/Util/Log/Database.php
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/test/PHPUnit/Util/Log/Database.php?rev=663970&view=auto
==============================================================================
--- incubator/shindig/trunk/php/test/PHPUnit/Util/Log/Database.php (added)
+++ incubator/shindig/trunk/php/test/PHPUnit/Util/Log/Database.php Fri Jun  6 07:55:55 2008
@@ -0,0 +1,529 @@
+<?php
+/**
+ * PHPUnit
+ *
+ * Copyright (c) 2002-2008, Sebastian Bergmann <sb...@sebastian-bergmann.de>.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ *   * Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ *
+ *   * Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in
+ *     the documentation and/or other materials provided with the
+ *     distribution.
+ *
+ *   * Neither the name of Sebastian Bergmann nor the names of his
+ *     contributors may be used to endorse or promote products derived
+ *     from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * @category   Testing
+ * @package    PHPUnit
+ * @author     Sebastian Bergmann <sb...@sebastian-bergmann.de>
+ * @copyright  2002-2008 Sebastian Bergmann <sb...@sebastian-bergmann.de>
+ * @license    http://www.opensource.org/licenses/bsd-license.php  BSD License
+ * @version    SVN: $Id: Database.php 2102 2008-01-15 07:35:10Z sb $
+ * @link       http://www.phpunit.de/
+ * @since      File available since Release 3.1.0
+ */
+
+require_once '../PHPUnit/Framework.php';
+require_once '../PHPUnit/Runner/BaseTestRunner.php';
+require_once '../PHPUnit/Util/Filter.php';
+
+PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT');
+
+/**
+ * Writes test result and code coverage data to a database.
+ *
+ * @category   Testing
+ * @package    PHPUnit
+ * @author     Sebastian Bergmann <sb...@sebastian-bergmann.de>
+ * @copyright  2002-2008 Sebastian Bergmann <sb...@sebastian-bergmann.de>
+ * @license    http://www.opensource.org/licenses/bsd-license.php  BSD License
+ * @version    Release: 3.2.9
+ * @link       http://www.phpunit.de/
+ * @since      Class available since Release 3.1.0
+ */
+class PHPUnit_Util_Log_Database implements PHPUnit_Framework_TestListener
+{
+    /**
+     * @var    PHPUnit_Util_Log_Database
+     * @access protected
+     * @static
+     */
+    protected static $instance = NULL;
+
+    /**
+     * @var    integer
+     * @access protected
+     */
+    protected $currentTestId;
+
+    /**
+     * @var    integer
+     * @access protected
+     */
+    protected $runId;
+
+    /**
+     * @var    integer[]
+     * @access protected
+     */
+    protected $testSuites = array();
+
+    /**
+     * @var    boolean
+     * @access protected
+     */
+    protected $currentTestSuccess = TRUE;
+
+    /**
+     * @var    PDO
+     * @access protected
+     */
+    protected $dbh;
+
+    /**
+     * Constructor.
+     *
+     * @param  PDO     $dbh
+     * @param  integer $revision
+     * @param  string  $information
+     * @throws PDOException
+     * @throws RuntimeException
+     * @access protected
+     */
+    protected function __construct(PDO $dbh, $revision, $information = '')
+    {
+        $this->dbh = $dbh;
+
+        $stmt = $this->dbh->prepare(
+          'INSERT INTO run
+                       (timestamp, revision, information)
+                 VALUES(:timestamp, :revision, :information);'
+        );
+
+        $timestamp = time();
+
+        $stmt->bindParam(':timestamp', $timestamp, PDO::PARAM_INT);
+        $stmt->bindParam(':revision', $revision, PDO::PARAM_INT);
+        $stmt->bindParam(':information', $information, PDO::PARAM_STR);
+        $stmt->execute();
+
+        $this->runId = $this->dbh->lastInsertId();
+    }
+
+    /**
+     * @param  PDO     $dbh
+     * @param  integer $revision
+     * @param  string  $information
+     * @return PHPUnit_Util_Log_Database
+     * @throws InvalidArgumentException
+     * @throws PDOException
+     * @throws RuntimeException
+     * @access public
+     * @static
+     */
+    public static function getInstance(PDO $dbh = NULL, $revision = '', $information = '')
+    {
+        if ($dbh === NULL) {
+            if (self::$instance != NULL) {
+                return self::$instance;
+            } else {
+                return FALSE;
+            }
+        }
+
+        if (self::$instance != NULL) {
+            throw new RuntimeException;
+        }
+
+        if (empty($revision)) {
+            throw new InvalidArgumentException;
+        }
+
+        self::$instance = new PHPUnit_Util_Log_Database(
+          $dbh, $revision, $information
+        );
+
+        return self::$instance;
+    }
+
+    /**
+     * Returns the ID of the current test.
+     *
+     * @return integer
+     * @access public
+     */
+    public function getCurrentTestId()
+    {
+        return $this->currentTestId;
+    }
+
+    /**
+     * Returns the ID of this test run.
+     *
+     * @return integer
+     * @access public
+     */
+    public function getRunId()
+    {
+        return $this->runId;
+    }
+
+    /**
+     * An error occurred.
+     *
+     * @param  PHPUnit_Framework_Test $test
+     * @param  Exception              $e
+     * @param  float                  $time
+     * @access public
+     */
+    public function addError(PHPUnit_Framework_Test $test, Exception $e, $time)
+    {
+        $message = PHPUnit_Framework_TestFailure::exceptionToString($e) . "\n" .
+                   PHPUnit_Util_Filter::getFilteredStacktrace($e, FALSE);
+
+        $this->storeResult(
+          PHPUnit_Runner_BaseTestRunner::STATUS_ERROR,
+          $time,
+          $message
+        );
+
+        $this->updateParents(
+          $time, PHPUnit_Runner_BaseTestRunner::STATUS_ERROR
+        );
+
+        $this->currentTestSuccess = FALSE;
+    }
+
+    /**
+     * A failure occurred.
+     *
+     * @param  PHPUnit_Framework_Test                 $test
+     * @param  PHPUnit_Framework_AssertionFailedError $e
+     * @param  float                                  $time
+     * @access public
+     */
+    public function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time)
+    {
+        $message = PHPUnit_Framework_TestFailure::exceptionToString($e) . "\n" .
+                   PHPUnit_Util_Filter::getFilteredStacktrace($e, FALSE);
+
+        $this->storeResult(
+          PHPUnit_Runner_BaseTestRunner::STATUS_FAILURE,
+          $time,
+          $message
+        );
+
+        $this->updateParents(
+          $time, PHPUnit_Runner_BaseTestRunner::STATUS_FAILURE
+        );
+
+        $this->currentTestSuccess = FALSE;
+    }
+
+    /**
+     * Incomplete test.
+     *
+     * @param  PHPUnit_Framework_Test $test
+     * @param  Exception              $e
+     * @param  float                  $time
+     * @access public
+     */
+    public function addIncompleteTest(PHPUnit_Framework_Test $test, Exception $e, $time)
+    {
+        $message = PHPUnit_Framework_TestFailure::exceptionToString($e) . "\n" .
+                   PHPUnit_Util_Filter::getFilteredStacktrace($e, FALSE);
+
+        $this->storeResult(
+          PHPUnit_Runner_BaseTestRunner::STATUS_INCOMPLETE,
+          $time,
+          $message
+        );
+
+        $this->currentTestSuccess = FALSE;
+    }
+
+    /**
+     * Skipped test.
+     *
+     * @param  PHPUnit_Framework_Test $test
+     * @param  Exception              $e
+     * @param  float                  $time
+     * @access public
+     */
+    public function addSkippedTest(PHPUnit_Framework_Test $test, Exception $e, $time)
+    {
+        $message = PHPUnit_Framework_TestFailure::exceptionToString($e) . "\n" .
+                   PHPUnit_Util_Filter::getFilteredStacktrace($e, FALSE);
+
+        $this->storeResult(
+          PHPUnit_Runner_BaseTestRunner::STATUS_SKIPPED,
+          $time,
+          $message
+        );
+
+        $this->currentTestSuccess = FALSE;
+    }
+
+    /**
+     * A test suite started.
+     *
+     * @param  PHPUnit_Framework_TestSuite $suite
+     * @access public
+     */
+    public function startTestSuite(PHPUnit_Framework_TestSuite $suite)
+    {
+        if (empty($this->testSuites)) {
+            $testSuiteId = $this->insertRootNode($suite->getName());
+        } else {
+            $testSuiteId = $this->insertNode($suite);
+        }
+
+        $this->testSuites[] = array(
+          'id'     => $testSuiteId,
+          'result' => PHPUnit_Runner_BaseTestRunner::STATUS_PASSED
+        );
+    }
+
+    /**
+     * A test suite ended.
+     *
+     * @param  PHPUnit_Framework_TestSuite $suite
+     * @access public
+     */
+    public function endTestSuite(PHPUnit_Framework_TestSuite $suite)
+    {
+        array_pop($this->testSuites);
+    }
+
+    /**
+     * A test started.
+     *
+     * @param  PHPUnit_Framework_Test $test
+     * @access public
+     */
+    public function startTest(PHPUnit_Framework_Test $test)
+    {
+        $this->insertNode($test);
+        $this->currentTestSuccess = TRUE;
+    }
+
+    /**
+     * A test ended.
+     *
+     * @param  PHPUnit_Framework_Test $test
+     * @param  float                  $time
+     * @access public
+     */
+    public function endTest(PHPUnit_Framework_Test $test, $time)
+    {
+        if ($this->currentTestSuccess) {
+            $this->storeResult(
+              PHPUnit_Runner_BaseTestRunner::STATUS_PASSED, $time
+            );
+
+            $this->updateParents($time);
+        }
+    }
+
+    /**
+     * Inserts the root node into the tree.
+     *
+     * @param  string $name
+     * @return integer
+     * @throws PDOException
+     * @access protected
+     */
+    protected function insertRootNode($name)
+    {
+        $this->dbh->beginTransaction();
+
+        $stmt = $this->dbh->prepare(
+          'INSERT INTO test
+                       (run_id, test_name, node_left, node_right, node_is_leaf)
+                 VALUES(:runId, :testName, 1, 2, 0);'
+        );
+
+        $stmt->bindParam(':runId', $this->runId, PDO::PARAM_INT);
+        $stmt->bindParam(':testName', $name, PDO::PARAM_STR);
+        $stmt->execute();
+
+        $rootId = $this->dbh->lastInsertId();
+
+        $stmt = $this->dbh->prepare(
+          'UPDATE test
+              SET node_root = :root
+            WHERE test_id = :testId;'
+        );
+
+        $stmt->bindParam(':root', $rootId, PDO::PARAM_INT);
+        $stmt->bindParam(':testId', $rootId, PDO::PARAM_INT);
+        $stmt->execute();
+
+        $this->dbh->commit();
+
+        return $rootId;
+    }
+
+    /**
+     * Inserts a node into the tree.
+     *
+     * @param  PHPUnit_Framework_Test $test
+     * @throws PDOException
+     * @access protected
+     */
+    protected function insertNode(PHPUnit_Framework_Test $test)
+    {
+        $isLeaf = (int)!$test instanceof PHPUnit_Framework_TestSuite;
+
+        $this->dbh->beginTransaction();
+
+        $stmt = $this->dbh->prepare(
+          'SELECT node_right
+             FROM test
+            WHERE test_id = :testId;'
+        );
+
+        $stmt->bindParam(':testId', $this->testSuites[count($this->testSuites)-1]['id'], PDO::PARAM_INT);
+        $stmt->execute();
+
+        $right = (int)$stmt->fetchColumn();
+        unset($stmt);
+
+        $stmt = $this->dbh->prepare(
+          'UPDATE test
+              SET node_left = node_left + 2
+            WHERE node_root = :root
+              AND node_left > :left;'
+        );
+
+        $stmt->bindParam(':root', $this->testSuites[0]['id'], PDO::PARAM_INT);
+        $stmt->bindParam(':left', $right, PDO::PARAM_INT);
+        $stmt->execute();
+
+        $stmt = $this->dbh->prepare(
+          'UPDATE test
+              SET node_right  = node_right + 2
+            WHERE node_root   = :root
+              AND node_right >= :right;'
+        );
+
+        $stmt->bindParam(':root', $this->testSuites[0]['id'], PDO::PARAM_INT);
+        $stmt->bindParam(':right', $right, PDO::PARAM_INT);
+        $stmt->execute();
+
+        $testName = $test->getName();
+        $left     = $right;
+        $right    = $right + 1;
+
+        $stmt = $this->dbh->prepare(
+          'INSERT INTO test
+                       (run_id, test_name, test_result, test_message,
+                        test_execution_time, node_root, node_left, node_right,
+                        node_is_leaf)
+                 VALUES(:runId, :testName, 0, "", 0, :root, :left, :right,
+                        :isLeaf);'
+        );
+
+        $stmt->bindParam(':runId', $this->runId, PDO::PARAM_INT);
+        $stmt->bindParam(':testName', $testName, PDO::PARAM_STR);
+        $stmt->bindParam(':root', $this->testSuites[0]['id'], PDO::PARAM_INT);
+        $stmt->bindParam(':left', $left, PDO::PARAM_INT);
+        $stmt->bindParam(':right', $right, PDO::PARAM_INT);
+        $stmt->bindParam(':isLeaf', $isLeaf, PDO::PARAM_INT);
+        $stmt->execute();
+
+        $this->currentTestId = $this->dbh->lastInsertId();
+        $this->dbh->commit();
+
+        if (!$test instanceof PHPUnit_Framework_TestSuite) {
+            $test->__db_id = $this->currentTestId;
+        }
+
+        return $this->currentTestId;
+    }
+
+    /**
+     * Stores a test result.
+     *
+     * @param  integer $result
+     * @param  float   $time
+     * @param  string  $message
+     * @throws PDOException
+     * @access protected
+     */
+    protected function storeResult($result = PHPUnit_Runner_BaseTestRunner::STATUS_PASSED, $time = 0, $message = '')
+    {
+        $stmt = $this->dbh->prepare(
+          'UPDATE test
+              SET test_result         = :result,
+                  test_message        = :message,
+                  test_execution_time = :executionTime
+            WHERE test_id             = :testId;'
+        );
+
+        $stmt->bindParam(':result', $result, PDO::PARAM_INT);
+        $stmt->bindParam(':message', $message, PDO::PARAM_STR);
+        $stmt->bindParam(':executionTime', $time);
+        $stmt->bindParam(':testId', $this->currentTestId, PDO::PARAM_INT);
+        $stmt->execute();
+    }
+
+    /**
+     * @param  float   $time
+     * @param  integer $result
+     * @throws PDOException
+     * @access protected
+     */
+    protected function updateParents($time, $result = NULL)
+    {
+        $stmtUpdateResultAndTime = $this->dbh->prepare(
+          'UPDATE test
+              SET test_result         = :result,
+                  test_execution_time = test_execution_time + :time
+            WHERE test_id             = :testSuiteId;'
+        );
+
+        $stmtUpdateTime = $this->dbh->prepare(
+          'UPDATE test
+              SET test_execution_time = test_execution_time + :time
+            WHERE test_id             = :testSuiteId;'
+        );
+
+        foreach ($this->testSuites as &$testSuite) {
+            if ($result > $testSuite['result']) {
+                $stmtUpdateResultAndTime->bindParam(':result', $result, PDO::PARAM_INT);
+                $stmtUpdateResultAndTime->bindParam(':testSuiteId', $testSuite['id'], PDO::PARAM_INT);
+                $stmtUpdateResultAndTime->bindParam(':time', $time);
+                $stmtUpdateResultAndTime->execute();
+
+                $testSuite['result'] = $result;
+            } else {
+                $stmtUpdateTime->bindParam(':testSuiteId', $testSuite['id'], PDO::PARAM_INT);
+                $stmtUpdateTime->bindParam(':time', $time);
+                $stmtUpdateTime->execute();
+            }
+        }
+    }
+}
+?>

Added: incubator/shindig/trunk/php/test/PHPUnit/Util/Log/Database/MySQL.sql
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/test/PHPUnit/Util/Log/Database/MySQL.sql?rev=663970&view=auto
==============================================================================
--- incubator/shindig/trunk/php/test/PHPUnit/Util/Log/Database/MySQL.sql (added)
+++ incubator/shindig/trunk/php/test/PHPUnit/Util/Log/Database/MySQL.sql Fri Jun  6 07:55:55 2008
@@ -0,0 +1,205 @@
+#
+# PHPUnit
+#
+# Copyright (c) 2002-2007, Sebastian Bergmann <sb...@sebastian-bergmann.de>.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+#   * Redistributions of source code must retain the above copyright
+#     notice, this list of conditions and the following disclaimer.
+# 
+#   * Redistributions in binary form must reproduce the above copyright
+#     notice, this list of conditions and the following disclaimer in
+#     the documentation and/or other materials provided with the
+#     distribution.
+#
+#   * Neither the name of Sebastian Bergmann nor the names of his
+#     contributors may be used to endorse or promote products derived
+#     from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+# $Id: MySQL.sql 2102 2008-01-15 07:35:10Z sb $
+#
+
+CREATE TABLE IF NOT EXISTS run(
+  run_id      INTEGER UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
+  timestamp   INTEGER UNSIGNED NOT NULL,
+  revision    INTEGER UNSIGNED NOT NULL,
+  information TEXT             NOT NULL
+) ENGINE=InnoDB;
+
+CREATE TABLE IF NOT EXISTS test(
+  run_id              INTEGER UNSIGNED NOT NULL REFERENCES run.run_id,
+  test_id             INTEGER UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
+  test_name           CHAR(128)        NOT NULL,
+  test_result         TINYINT UNSIGNED NOT NULL DEFAULT 0,
+  test_message        TEXT             NOT NULL DEFAULT "",
+  test_execution_time FLOAT   UNSIGNED NOT NULL DEFAULT 0,
+  code_method_id      INTEGER UNSIGNED          REFERENCES code_method.code_method_id,
+  node_root           INTEGER UNSIGNED NOT NULL,
+  node_left           INTEGER UNSIGNED NOT NULL,
+  node_right          INTEGER UNSIGNED NOT NULL,
+  node_is_leaf        BOOLEAN          NOT NULL DEFAULT 0,
+
+  INDEX (run_id),
+  INDEX (test_result),
+  INDEX (code_method_id),
+  INDEX (node_root),
+  INDEX (node_left),
+  INDEX (node_right)
+) ENGINE=InnoDB;
+
+CREATE TABLE IF NOT EXISTS code_file(
+  code_file_id   INTEGER UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
+  code_file_name CHAR(255),
+  code_file_md5  CHAR(32),
+  revision       INTEGER UNSIGNED NOT NULL
+) ENGINE=InnoDB;
+
+CREATE TABLE IF NOT EXISTS code_function(
+  code_file_id             INTEGER UNSIGNED NOT NULL REFERENCES code_file.code_file_id,
+  code_function_id         INTEGER UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
+  code_function_name       CHAR(255),
+  code_function_start_line INTEGER UNSIGNED NOT NULL,
+  code_function_end_line   INTEGER UNSIGNED NOT NULL,
+
+  INDEX (code_file_id)
+) ENGINE=InnoDB;
+
+CREATE TABLE IF NOT EXISTS code_class(
+  code_file_id          INTEGER UNSIGNED NOT NULL REFERENCES code_file.code_file_id,
+  code_class_id         INTEGER UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
+  code_class_parent_id  INTEGER UNSIGNED REFERENCES code_class.code_class_id,
+  code_class_name       CHAR(255),
+  code_class_start_line INTEGER UNSIGNED NOT NULL,
+  code_class_end_line   INTEGER UNSIGNED NOT NULL,
+
+  INDEX (code_file_id)
+) ENGINE=InnoDB;
+
+CREATE TABLE IF NOT EXISTS code_method(
+  code_class_id          INTEGER UNSIGNED NOT NULL REFERENCES code_class.code_class_id,
+  code_method_id         INTEGER UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
+  code_method_name       CHAR(255),
+  code_method_start_line INTEGER UNSIGNED NOT NULL,
+  code_method_end_line   INTEGER UNSIGNED NOT NULL,
+
+  INDEX (code_class_id)
+) ENGINE=InnoDB;
+
+CREATE TABLE IF NOT EXISTS code_line(
+  code_file_id      INTEGER UNSIGNED NOT NULL REFERENCES code_file.code_file_id,
+  code_line_id      INTEGER UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
+  code_line_number  INTEGER UNSIGNED NOT NULL,
+  code_line         TEXT,
+  code_line_covered TINYINT UNSIGNED NOT NULL,
+
+  INDEX (code_file_id)
+) ENGINE=InnoDB;
+
+CREATE TABLE IF NOT EXISTS code_coverage(
+  test_id      INTEGER UNSIGNED NOT NULL REFERENCES test.test_id,
+  code_line_id INTEGER UNSIGNED NOT NULL REFERENCES code_line.code_line_id,
+
+  PRIMARY KEY (test_id, code_line_id)
+) ENGINE=InnoDB;
+
+CREATE TABLE IF NOT EXISTS metrics_project(
+  run_id                  INTEGER UNSIGNED NOT NULL,
+  metrics_project_cls     INTEGER UNSIGNED NOT NULL,
+  metrics_project_clsa    INTEGER UNSIGNED NOT NULL,
+  metrics_project_clsc    INTEGER UNSIGNED NOT NULL,
+  metrics_project_roots   INTEGER UNSIGNED NOT NULL,
+  metrics_project_leafs   INTEGER UNSIGNED NOT NULL,
+  metrics_project_interfs INTEGER UNSIGNED NOT NULL,
+  metrics_project_maxdit  INTEGER UNSIGNED NOT NULL,
+
+  INDEX (run_id)
+) ENGINE=InnoDB;
+
+CREATE TABLE IF NOT EXISTS metrics_file(
+  run_id                      INTEGER UNSIGNED NOT NULL,
+  code_file_id                INTEGER UNSIGNED NOT NULL REFERENCES code_file.code_file_id,
+  metrics_file_coverage       FLOAT   UNSIGNED NOT NULL,
+  metrics_file_loc            INTEGER UNSIGNED NOT NULL,
+  metrics_file_cloc           INTEGER UNSIGNED NOT NULL,
+  metrics_file_ncloc          INTEGER UNSIGNED NOT NULL,
+  metrics_file_loc_executable INTEGER UNSIGNED NOT NULL,
+  metrics_file_loc_executed   INTEGER UNSIGNED NOT NULL,
+
+  INDEX (run_id),
+  INDEX (code_file_id)
+) ENGINE=InnoDB;
+
+CREATE TABLE IF NOT EXISTS metrics_function(
+  run_id                          INTEGER UNSIGNED NOT NULL,
+  code_function_id                INTEGER UNSIGNED NOT NULL REFERENCES code_method.code_function_id,
+  metrics_function_coverage       FLOAT   UNSIGNED NOT NULL,
+  metrics_function_loc            INTEGER UNSIGNED NOT NULL,
+  metrics_function_loc_executable INTEGER UNSIGNED NOT NULL,
+  metrics_function_loc_executed   INTEGER UNSIGNED NOT NULL,
+  metrics_function_ccn            INTEGER UNSIGNED NOT NULL,
+  metrics_function_crap           FLOAT   UNSIGNED NOT NULL,
+  metrics_function_npath          INTEGER UNSIGNED NOT NULL,
+
+  INDEX (run_id),
+  INDEX (code_function_id)
+) ENGINE=InnoDB;
+
+CREATE TABLE IF NOT EXISTS metrics_class(
+  run_id                       INTEGER UNSIGNED NOT NULL,
+  code_class_id                INTEGER UNSIGNED NOT NULL REFERENCES code_class.code_class_id,
+  metrics_class_coverage       FLOAT   UNSIGNED NOT NULL,
+  metrics_class_loc            INTEGER UNSIGNED NOT NULL,
+  metrics_class_loc_executable INTEGER UNSIGNED NOT NULL,
+  metrics_class_loc_executed   INTEGER UNSIGNED NOT NULL,
+  metrics_class_aif            FLOAT   UNSIGNED NOT NULL,
+  metrics_class_ahf            FLOAT   UNSIGNED NOT NULL,
+  metrics_class_cis            INTEGER UNSIGNED NOT NULL,
+  metrics_class_csz            INTEGER UNSIGNED NOT NULL,
+  metrics_class_dit            INTEGER UNSIGNED NOT NULL,
+  metrics_class_impl           INTEGER UNSIGNED NOT NULL,
+  metrics_class_mif            FLOAT   UNSIGNED NOT NULL,
+  metrics_class_mhf            FLOAT   UNSIGNED NOT NULL,
+  metrics_class_noc            INTEGER UNSIGNED NOT NULL,
+  metrics_class_pf             FLOAT   UNSIGNED NOT NULL,
+  metrics_class_vars           INTEGER UNSIGNED NOT NULL,
+  metrics_class_varsnp         INTEGER UNSIGNED NOT NULL,
+  metrics_class_varsi          INTEGER UNSIGNED NOT NULL,
+  metrics_class_wmc            INTEGER UNSIGNED NOT NULL,
+  metrics_class_wmcnp          INTEGER UNSIGNED NOT NULL,
+  metrics_class_wmci           INTEGER UNSIGNED NOT NULL,
+
+  INDEX (run_id),
+  INDEX (code_class_id)
+) ENGINE=InnoDB;
+
+CREATE TABLE IF NOT EXISTS metrics_method(
+  run_id                        INTEGER UNSIGNED NOT NULL,
+  code_method_id                INTEGER UNSIGNED NOT NULL REFERENCES code_method.code_method_id,
+  metrics_method_coverage       FLOAT   UNSIGNED NOT NULL,
+  metrics_method_loc            INTEGER UNSIGNED NOT NULL,
+  metrics_method_loc_executable INTEGER UNSIGNED NOT NULL,
+  metrics_method_loc_executed   INTEGER UNSIGNED NOT NULL,
+  metrics_method_ccn            INTEGER UNSIGNED NOT NULL,
+  metrics_method_crap           FLOAT   UNSIGNED NOT NULL,
+  metrics_method_npath          INTEGER UNSIGNED NOT NULL,
+
+  INDEX (run_id),
+  INDEX (code_method_id)
+) ENGINE=InnoDB;

Added: incubator/shindig/trunk/php/test/PHPUnit/Util/Log/Database/SQLite3.sql
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/test/PHPUnit/Util/Log/Database/SQLite3.sql?rev=663970&view=auto
==============================================================================
--- incubator/shindig/trunk/php/test/PHPUnit/Util/Log/Database/SQLite3.sql (added)
+++ incubator/shindig/trunk/php/test/PHPUnit/Util/Log/Database/SQLite3.sql Fri Jun  6 07:55:55 2008
@@ -0,0 +1,205 @@
+--
+-- PHPUnit
+--
+-- Copyright (c) 2002-2007, Sebastian Bergmann <sb...@sebastian-bergmann.de>.
+-- All rights reserved.
+--
+-- Redistribution and use in source and binary forms, with or without
+-- modification, are permitted provided that the following conditions
+-- are met:
+--
+--   * Redistributions of source code must retain the above copyright
+--     notice, this list of conditions and the following disclaimer.
+-- 
+--   * Redistributions in binary form must reproduce the above copyright
+--     notice, this list of conditions and the following disclaimer in
+--     the documentation and/or other materials provided with the
+--     distribution.
+--
+--   * Neither the name of Sebastian Bergmann nor the names of his
+--     contributors may be used to endorse or promote products derived
+--     from this software without specific prior written permission.
+--
+-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+-- FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+-- COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+-- INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+-- BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+-- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+-- CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+-- LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+-- ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+-- POSSIBILITY OF SUCH DAMAGE.
+--
+-- $Id: SQLite3.sql 2102 2008-01-15 07:35:10Z sb $
+--
+
+CREATE TABLE IF NOT EXISTS run(
+  run_id      INTEGER PRIMARY KEY AUTOINCREMENT,
+  timestamp   INTEGER,
+  revision    INTEGER,
+  information STRING
+);
+
+CREATE TABLE IF NOT EXISTS test(
+  run_id              INTEGER,
+  test_id             INTEGER PRIMARY KEY AUTOINCREMENT,
+  test_name           TEXT,
+  test_result         INTEGER DEFAULT 0,
+  test_message        TEXT    DEFAULT "",
+  test_execution_time REAL    DEFAULT 0,
+  code_method_id      INTEGER,
+  node_root           INTEGER,
+  node_left           INTEGER,
+  node_right          INTEGER,
+  node_is_leaf        INTEGER DEFAULT 0
+);
+
+CREATE INDEX IF NOT EXISTS test_run_id         ON test (run_id);
+CREATE INDEX IF NOT EXISTS test_result         ON test (test_result);
+CREATE INDEX IF NOT EXISTS test_code_method_id ON test (code_method_id);
+CREATE INDEX IF NOT EXISTS test_node_root      ON test (node_root);
+CREATE INDEX IF NOT EXISTS test_node_left      ON test (node_left);
+CREATE INDEX IF NOT EXISTS test_node_right     ON test (node_right);
+
+CREATE TABLE IF NOT EXISTS code_file(
+  code_file_id   INTEGER PRIMARY KEY AUTOINCREMENT,
+  code_file_name TEXT,
+  code_file_md5  TEXT,
+  revision       INTEGER
+);
+
+CREATE TABLE IF NOT EXISTS code_function(
+  code_file_id             INTEGER,
+  code_function_id         INTEGER PRIMARY KEY AUTOINCREMENT,
+  code_function_name       TEXT,
+  code_function_start_line INTEGER,
+  code_function_end_line   INTEGER
+);
+
+CREATE INDEX IF NOT EXISTS code_file_id ON code_function (code_file_id);
+
+CREATE TABLE IF NOT EXISTS code_class(
+  code_file_id          INTEGER,
+  code_class_id         INTEGER PRIMARY KEY AUTOINCREMENT,
+  code_class_parent_id  INTEGER,
+  code_class_name       TEXT,
+  code_class_start_line INTEGER,
+  code_class_end_line   INTEGER
+);
+
+CREATE INDEX IF NOT EXISTS code_file_id ON code_class (code_file_id);
+
+CREATE TABLE IF NOT EXISTS code_method(
+  code_class_id          INTEGER,
+  code_method_id         INTEGER PRIMARY KEY AUTOINCREMENT,
+  code_method_name       TEXT,
+  code_method_start_line INTEGER,
+  code_method_end_line   INTEGER
+);
+
+CREATE INDEX IF NOT EXISTS code_class_id ON code_method (code_class_id);
+
+CREATE TABLE IF NOT EXISTS code_line(
+  code_file_id      INTEGER,
+  code_line_id      INTEGER PRIMARY KEY AUTOINCREMENT,
+  code_line_number  INTEGER,
+  code_line         TEXT,
+  code_line_covered INTEGER
+);
+
+CREATE INDEX IF NOT EXISTS code_line_code_file_id ON code_line (code_file_id);
+
+CREATE TABLE IF NOT EXISTS code_coverage(
+  test_id      INTEGER,
+  code_line_id INTEGER
+);
+
+CREATE UNIQUE INDEX IF NOT EXISTS code_coverage_test_id_code_line_id ON code_coverage (test_id, code_line_id);
+
+CREATE TABLE IF NOT EXISTS metrics_project(
+  run_id                  INTEGER,
+  metrics_project_cls     INTEGER,
+  metrics_project_clsa    INTEGER,
+  metrics_project_clsc    INTEGER,
+  metrics_project_roots   INTEGER,
+  metrics_project_leafs   INTEGER,
+  metrics_project_interfs INTEGER,
+  metrics_project_maxdit  INTEGER
+);
+
+CREATE INDEX IF NOT EXISTS run_id ON metrics_project (run_id);
+
+CREATE TABLE IF NOT EXISTS metrics_file(
+  run_id                      INTEGER,
+  code_file_id                INTEGER,
+  metrics_file_coverage       REAL,
+  metrics_file_loc            INTEGER,
+  metrics_file_cloc           INTEGER,
+  metrics_file_ncloc          INTEGER,
+  metrics_file_loc_executable INTEGER,
+  metrics_file_loc_executed   INTEGER
+);
+
+CREATE INDEX IF NOT EXISTS run_id ON metrics_file (run_id);
+CREATE INDEX IF NOT EXISTS code_file_id ON metrics_file (code_file_id);
+
+CREATE TABLE IF NOT EXISTS metrics_function(
+  run_id                          INTEGER,
+  code_function_id                INTEGER,
+  metrics_function_coverage       REAL,
+  metrics_function_loc            INTEGER,
+  metrics_function_loc_executable INTEGER,
+  metrics_function_loc_executed   INTEGER,
+  metrics_function_ccn            INTEGER,
+  metrics_function_crap           REAL,
+  metrics_function_npath          INTEGER
+);
+
+CREATE INDEX IF NOT EXISTS run_id ON metrics_function (run_id);
+CREATE INDEX IF NOT EXISTS code_function_id ON metrics_function (code_function_id);
+
+CREATE TABLE IF NOT EXISTS metrics_class(
+  run_id                       INTEGER,
+  code_class_id                INTEGER,
+  metrics_class_coverage       REAL,
+  metrics_class_loc            INTEGER,
+  metrics_class_loc_executable INTEGER,
+  metrics_class_loc_executed   INTEGER,
+  metrics_class_aif            REAL,
+  metrics_class_ahf            REAL,
+  metrics_class_cis            INTEGER,
+  metrics_class_csz            INTEGER,
+  metrics_class_dit            INTEGER,
+  metrics_class_impl           INTEGER,
+  metrics_class_mif            REAL,
+  metrics_class_mhf            REAL,
+  metrics_class_noc            INTEGER,
+  metrics_class_pf             REAL,
+  metrics_class_vars           INTEGER,
+  metrics_class_varsnp         INTEGER,
+  metrics_class_varsi          INTEGER,
+  metrics_class_wmc            INTEGER,
+  metrics_class_wmcnp          INTEGER,
+  metrics_class_wmci           INTEGER
+);
+
+CREATE INDEX IF NOT EXISTS run_id ON metrics_class (run_id);
+CREATE INDEX IF NOT EXISTS code_class_id ON metrics_class (code_class_id);
+
+CREATE TABLE IF NOT EXISTS metrics_method(
+  run_id                        INTEGER,
+  code_method_id                INTEGER,
+  metrics_method_coverage       REAL,
+  metrics_method_loc            INTEGER,
+  metrics_method_loc_executable INTEGER,
+  metrics_method_loc_executed   INTEGER,
+  metrics_method_ccn            INTEGER,
+  metrics_method_crap           REAL,
+  metrics_method_npath          INTEGER
+);
+
+CREATE INDEX IF NOT EXISTS run_id ON metrics_method (run_id);
+CREATE INDEX IF NOT EXISTS code_method_id ON metrics_method (code_method_id);

Added: incubator/shindig/trunk/php/test/PHPUnit/Util/Log/GraphViz.php
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/test/PHPUnit/Util/Log/GraphViz.php?rev=663970&view=auto
==============================================================================
--- incubator/shindig/trunk/php/test/PHPUnit/Util/Log/GraphViz.php (added)
+++ incubator/shindig/trunk/php/test/PHPUnit/Util/Log/GraphViz.php Fri Jun  6 07:55:55 2008
@@ -0,0 +1,309 @@
+<?php
+/**
+ * PHPUnit
+ *
+ * Copyright (c) 2002-2008, Sebastian Bergmann <sb...@sebastian-bergmann.de>.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ *   * Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ *
+ *   * Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in
+ *     the documentation and/or other materials provided with the
+ *     distribution.
+ *
+ *   * Neither the name of Sebastian Bergmann nor the names of his
+ *     contributors may be used to endorse or promote products derived
+ *     from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * @category   Testing
+ * @package    PHPUnit
+ * @author     Sebastian Bergmann <sb...@sebastian-bergmann.de>
+ * @copyright  2002-2008 Sebastian Bergmann <sb...@sebastian-bergmann.de>
+ * @license    http://www.opensource.org/licenses/bsd-license.php  BSD License
+ * @version    SVN: $Id: GraphViz.php 1985 2007-12-26 18:11:55Z sb $
+ * @link       http://www.phpunit.de/
+ * @since      File available since Release 3.0.0
+ */
+
+@include_once 'Image/GraphViz.php';
+
+require_once '../PHPUnit/Framework.php';
+require_once '../PHPUnit/Util/Filter.php';
+require_once '../PHPUnit/Util/Filesystem.php';
+require_once '../PHPUnit/Util/Printer.php';
+require_once '../PHPUnit/Util/Test.php';
+
+PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT');
+
+/**
+ * A TestListener that generates maps of the executed tests
+ * in GraphViz markup.
+ *
+ * @category   Testing
+ * @package    PHPUnit
+ * @author     Sebastian Bergmann <sb...@sebastian-bergmann.de>
+ * @copyright  2002-2008 Sebastian Bergmann <sb...@sebastian-bergmann.de>
+ * @license    http://www.opensource.org/licenses/bsd-license.php  BSD License
+ * @version    Release: 3.2.9
+ * @link       http://www.phpunit.de/
+ * @since      Class available since Release 3.0.0
+ */
+class PHPUnit_Util_Log_GraphViz extends PHPUnit_Util_Printer implements PHPUnit_Framework_TestListener
+{
+    /**
+     * @var    Image_GraphViz
+     * @access protected
+     */
+    protected $graph;
+
+    /**
+     * @var    boolean
+     * @access protected
+     */
+    protected $currentTestSuccess = TRUE;
+
+    /**
+     * @var    string[]
+     * @access protected
+     */
+    protected $testSuites = array();
+
+    /**
+     * @var    integer
+     * @access protected
+     */
+    protected $testSuiteLevel = 0;
+
+    /**
+     * @var    integer[]
+     * @access protected
+     */
+    protected $testSuiteFailureOrErrorCount = array(0);
+
+    /**
+     * @var    integer[]
+     * @access protected
+     */
+    protected $testSuiteIncompleteOrSkippedCount = array(0);
+
+    /**
+     * Constructor.
+     *
+     * @param  mixed $out
+     * @access public
+     */
+    public function __construct($out = NULL)
+    {
+        $this->graph = new Image_GraphViz(
+          TRUE,
+          array(
+            'overlap'  => 'scale',
+            'splines'  => 'true',
+            'sep'      => '.1',
+            'fontsize' => '8'
+          )
+        );
+
+        parent::__construct($out);
+    }
+
+    /**
+     * Flush buffer and close output.
+     *
+     * @access public
+     */
+    public function flush()
+    {
+        $this->write($this->graph->parse());
+
+        parent::flush();
+    }
+
+    /**
+     * An error occurred.
+     *
+     * @param  PHPUnit_Framework_Test $test
+     * @param  Exception              $e
+     * @param  float                  $time
+     * @access public
+     */
+    public function addError(PHPUnit_Framework_Test $test, Exception $e, $time)
+    {
+        $this->addTestNode($test, 'red');
+        $this->testSuiteFailureOrErrorCount[$this->testSuiteLevel]++;
+
+        $this->currentTestSuccess = FALSE;
+    }
+
+    /**
+     * A failure occurred.
+     *
+     * @param  PHPUnit_Framework_Test                 $test
+     * @param  PHPUnit_Framework_AssertionFailedError $e
+     * @param  float                                  $time
+     * @access public
+     */
+    public function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time)
+    {
+        $this->addTestNode($test, 'red');
+        $this->testSuiteFailureOrErrorCount[$this->testSuiteLevel]++;
+
+        $this->currentTestSuccess = FALSE;
+    }
+
+    /**
+     * Incomplete test.
+     *
+     * @param  PHPUnit_Framework_Test $test
+     * @param  Exception              $e
+     * @param  float                  $time
+     * @access public
+     */
+    public function addIncompleteTest(PHPUnit_Framework_Test $test, Exception $e, $time)
+    {
+        $this->addTestNode($test, 'yellow');
+        $this->testSuiteIncompleteOrSkippedCount[$this->testSuiteLevel]++;
+
+        $this->currentTestSuccess = FALSE;
+    }
+
+    /**
+     * Skipped test.
+     *
+     * @param  PHPUnit_Framework_Test $test
+     * @param  Exception              $e
+     * @param  float                  $time
+     * @access public
+     */
+    public function addSkippedTest(PHPUnit_Framework_Test $test, Exception $e, $time)
+    {
+        $this->addTestNode($test, 'yellow');
+        $this->testSuiteIncompleteOrSkippedCount[$this->testSuiteLevel]++;
+
+        $this->currentTestSuccess = FALSE;
+    }
+
+    /**
+     * A testsuite started.
+     *
+     * @param  PHPUnit_Framework_TestSuite $suite
+     * @access public
+     */
+    public function startTestSuite(PHPUnit_Framework_TestSuite $suite)
+    {
+        $this->graph->addNode($suite->getName());
+
+        if ($this->testSuiteLevel > 0) {
+            $this->graph->addEdge(
+              array(
+                $this->testSuites[$this->testSuiteLevel] => $suite->getName()
+              )
+            );
+        }
+
+        $this->testSuiteLevel++;
+        $this->testSuites[$this->testSuiteLevel]                        = $suite->getName();
+        $this->testSuiteFailureOrErrorCount[$this->testSuiteLevel]      = 0;
+        $this->testSuiteIncompleteOrSkippedCount[$this->testSuiteLevel] = 0;
+    }
+
+    /**
+     * A testsuite ended.
+     *
+     * @param  PHPUnit_Framework_TestSuite $suite
+     * @access public
+     */
+    public function endTestSuite(PHPUnit_Framework_TestSuite $suite)
+    {
+        $color = 'red';
+
+        if ($this->testSuiteFailureOrErrorCount[$this->testSuiteLevel] == 0 &&
+            $this->testSuiteIncompleteOrSkippedCount[$this->testSuiteLevel] == 0) {
+            $color = 'green';
+        }
+
+        else if ($this->testSuiteFailureOrErrorCount[$this->testSuiteLevel] == 0 &&
+                 $this->testSuiteIncompleteOrSkippedCount[$this->testSuiteLevel] > 0) {
+            $color = 'yellow';
+        }
+
+        $this->graph->addNode(
+          $this->testSuites[$this->testSuiteLevel],
+          array('color' => $color)
+        );
+
+        if ($this->testSuiteLevel > 1) {
+            $this->testSuiteFailureOrErrorCount[$this->testSuiteLevel - 1]      += $this->testSuiteFailureOrErrorCount[$this->testSuiteLevel];
+            $this->testSuiteIncompleteOrSkippedCount[$this->testSuiteLevel - 1] += $this->testSuiteIncompleteOrSkippedCount[$this->testSuiteLevel];
+        }
+
+        $this->testSuiteLevel--;
+    }
+
+    /**
+     * A test started.
+     *
+     * @param  PHPUnit_Framework_Test $test
+     * @access public
+     */
+    public function startTest(PHPUnit_Framework_Test $test)
+    {
+        $this->currentTestSuccess = TRUE;
+    }
+
+    /**
+     * A test ended.
+     *
+     * @param  PHPUnit_Framework_Test $test
+     * @param  float                  $time
+     * @access public
+     */
+    public function endTest(PHPUnit_Framework_Test $test, $time)
+    {
+        if ($this->currentTestSuccess) {
+            $this->addTestNode($test, 'green');
+        }
+    }
+
+    /**
+     * @param  PHPUnit_Framework_Test $test
+     * @param  string                  $color
+     * @access protected
+     */
+    protected function addTestNode(PHPUnit_Framework_Test $test, $color)
+    {
+        $name = PHPUnit_Util_Test::describe($test, FALSE);
+
+        $this->graph->addNode(
+          $name[1],
+          array('color' => $color),
+          $this->testSuites[$this->testSuiteLevel]
+        );
+
+        $this->graph->addEdge(
+          array(
+            $this->testSuites[$this->testSuiteLevel] => $name[1]
+          )
+        );
+    }
+}
+?>