]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - tests/PHPUnit/Util/Log/CodeCoverage/Database.php
Added unit tests.
[Github/sugarcrm.git] / tests / PHPUnit / Util / Log / CodeCoverage / Database.php
1 <?php
2 /**
3  * PHPUnit
4  *
5  * Copyright (c) 2002-2009, Sebastian Bergmann <sb@sebastian-bergmann.de>.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  *   * Redistributions of source code must retain the above copyright
13  *     notice, this list of conditions and the following disclaimer.
14  *
15  *   * Redistributions in binary form must reproduce the above copyright
16  *     notice, this list of conditions and the following disclaimer in
17  *     the documentation and/or other materials provided with the
18  *     distribution.
19  *
20  *   * Neither the name of Sebastian Bergmann nor the names of his
21  *     contributors may be used to endorse or promote products derived
22  *     from this software without specific prior written permission.
23  *
24  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35  * POSSIBILITY OF SUCH DAMAGE.
36  *
37  * @category   Testing
38  * @package    PHPUnit
39  * @author     Sebastian Bergmann <sb@sebastian-bergmann.de>
40  * @copyright  2002-2009 Sebastian Bergmann <sb@sebastian-bergmann.de>
41  * @license    http://www.opensource.org/licenses/bsd-license.php  BSD License
42
43  * @link       http://www.phpunit.de/
44  * @since      File available since Release 3.1.4
45  */
46
47 require_once 'PHPUnit/Framework.php';
48 require_once 'PHPUnit/Util/Metrics/Project.php';
49 require_once 'PHPUnit/Util/Class.php';
50 require_once 'PHPUnit/Util/CodeCoverage.php';
51 require_once 'PHPUnit/Util/Filesystem.php';
52 require_once 'PHPUnit/Util/Filter.php';
53
54 PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT');
55
56 /**
57  *
58  *
59  * @category   Testing
60  * @package    PHPUnit
61  * @author     Sebastian Bergmann <sb@sebastian-bergmann.de>
62  * @copyright  2002-2009 Sebastian Bergmann <sb@sebastian-bergmann.de>
63  * @license    http://www.opensource.org/licenses/bsd-license.php  BSD License
64  * @version    Release: 3.3.17
65  * @link       http://www.phpunit.de/
66  * @since      Class available since Release 3.1.4
67  */
68 class PHPUnit_Util_Log_CodeCoverage_Database
69 {
70     /**
71      * @var    PDO
72      */
73     protected $dbh;
74
75     /**
76      * Constructor.
77      *
78      * @param  PDO $dbh
79      * @throws PDOException
80      */
81     public function __construct(PDO $dbh)
82     {
83         $this->dbh = $dbh;
84     }
85
86     /**
87      * Stores code coverage information.
88      *
89      * @param  PHPUnit_Framework_TestResult $result
90      * @param  integer                      $runId
91      * @param  integer                      $revision
92      * @param  string                       $commonPath
93      */
94     public function storeCodeCoverage(PHPUnit_Framework_TestResult $result, $runId, $revision, $commonPath = '')
95     {
96         $codeCoverage   = $result->getCodeCoverageInformation(FALSE);
97         $summary        = PHPUnit_Util_CodeCoverage::getSummary($codeCoverage);
98         $files          = array_keys($summary);
99         $projectMetrics = new PHPUnit_Util_Metrics_Project($files, $summary);
100         $storedClasses  = array();
101
102         if (empty($commonPath)) {
103             $commonPath = PHPUnit_Util_Filesystem::getCommonPath($files);
104         }
105
106         $this->dbh->beginTransaction();
107
108         foreach ($files as $file) {
109             $filename    = str_replace($commonPath, '', $file);
110             $fileId      = FALSE;
111             $fileMetrics = $projectMetrics->getFile($file);
112             $lines       = $fileMetrics->getLines();
113             $hash        = md5_file($file);
114
115             $stmt = $this->dbh->prepare(
116               'SELECT code_file_id
117                  FROM code_file
118                 WHERE code_file_name = :filename
119                   AND revision       = :revision;'
120             );
121
122             $stmt->bindParam(':filename', $filename, PDO::PARAM_STR);
123             $stmt->bindParam(':revision', $revision, PDO::PARAM_INT);
124             $stmt->execute();
125
126             if ($stmt) {
127                 $fileId = (int)$stmt->fetchColumn();
128             }
129
130             unset($stmt);
131
132             if ($fileId == 0) {
133                 $stmt = $this->dbh->prepare(
134                   'INSERT INTO code_file
135                                (code_file_name, code_file_md5, revision)
136                          VALUES(:filename, :hash, :revision);'
137                 );
138
139                 $stmt->bindParam(':filename', $filename, PDO::PARAM_STR);
140                 $stmt->bindParam(':hash', $hash, PDO::PARAM_STR);
141                 $stmt->bindParam(':revision', $revision, PDO::PARAM_INT);
142                 $stmt->execute();
143
144                 $fileId  = $this->dbh->lastInsertId();
145
146                 $stmt = $this->dbh->prepare(
147                   'INSERT INTO code_class
148                                (code_file_id, code_class_name,
149                                 code_class_start_line, code_class_end_line)
150                          VALUES(:fileId, :className, :startLine, :endLine);'
151                 );
152
153                 foreach ($fileMetrics->getClasses() as $classMetrics) {
154                     $className      = $classMetrics->getClass()->getName();
155                     $classStartLine = $classMetrics->getClass()->getStartLine();
156                     $classEndLine   = $classMetrics->getClass()->getEndLine();
157
158                     $stmt->bindParam(':fileId', $fileId, PDO::PARAM_INT);
159                     $stmt->bindParam(':className', $className, PDO::PARAM_STR);
160                     $stmt->bindParam(':startLine', $classStartLine, PDO::PARAM_INT);
161                     $stmt->bindParam(':endLine', $classEndLine, PDO::PARAM_INT);
162                     $stmt->execute();
163
164                     $classId                   = $this->dbh->lastInsertId();
165                     $storedClasses[$className] = $classId;
166
167                     $stmt2 = $this->dbh->prepare(
168                       'INSERT INTO code_method
169                                    (code_class_id, code_method_name,
170                                     code_method_start_line, code_method_end_line)
171                              VALUES(:classId, :methodName, :startLine, :endLine);'
172                     );
173
174                     foreach ($classMetrics->getMethods() as $methodMetrics) {
175                         $methodName       = $methodMetrics->getMethod()->getName();
176                         $methodStartLine  = $methodMetrics->getMethod()->getStartLine();
177                         $methodEndLine    = $methodMetrics->getMethod()->getEndLine();
178
179                         $stmt2->bindParam(':classId', $classId, PDO::PARAM_INT);
180                         $stmt2->bindParam(':methodName', $methodName, PDO::PARAM_STR);
181                         $stmt2->bindParam(':startLine', $methodStartLine, PDO::PARAM_INT);
182                         $stmt2->bindParam(':endLine', $methodEndLine, PDO::PARAM_INT);
183                         $stmt2->execute();
184                     }
185
186                     unset($stmt2);
187                 }
188
189                 $stmt = $this->dbh->prepare(
190                   'INSERT INTO code_line
191                                (code_file_id, code_line_number, code_line,
192                                 code_line_covered)
193                          VALUES(:fileId, :lineNumber, :line, :covered);'
194                 );
195
196                 $i = 1;
197
198                 foreach ($lines as $line) {
199                     $covered = 0;
200
201                     if (isset($summary[$file][$i])) {
202                         if (is_int($summary[$file][$i])) {
203                             $covered = $summary[$file][$i];
204                         } else {
205                             $covered = 1;
206                         }
207                     }
208
209                     $stmt->bindParam(':fileId', $fileId, PDO::PARAM_INT);
210                     $stmt->bindParam(':lineNumber', $i, PDO::PARAM_INT);
211                     $stmt->bindParam(':line', $line, PDO::PARAM_STR);
212                     $stmt->bindParam(':covered', $covered, PDO::PARAM_INT);
213                     $stmt->execute();
214
215                     $i++;
216                 }
217             }
218
219             $stmt = $this->dbh->prepare(
220               'INSERT INTO metrics_file
221                            (run_id, code_file_id, metrics_file_coverage,
222                            metrics_file_loc, metrics_file_cloc, metrics_file_ncloc,
223                            metrics_file_loc_executable, metrics_file_loc_executed)
224                      VALUES(:runId, :fileId, :coverage, :loc, :cloc, :ncloc,
225                             :locExecutable, :locExecuted);'
226             );
227
228             $fileCoverage      = $fileMetrics->getCoverage();
229             $fileLoc           = $fileMetrics->getLoc();
230             $fileCloc          = $fileMetrics->getCloc();
231             $fileNcloc         = $fileMetrics->getNcloc();
232             $fileLocExecutable = $fileMetrics->getLocExecutable();
233             $fileLocExecuted   = $fileMetrics->getLocExecuted();
234
235             $stmt->bindParam(':runId', $runId, PDO::PARAM_INT);
236             $stmt->bindParam(':fileId', $fileId, PDO::PARAM_INT);
237             $stmt->bindParam(':coverage', $fileCoverage);
238             $stmt->bindParam(':loc', $fileLoc, PDO::PARAM_INT);
239             $stmt->bindParam(':cloc', $fileCloc, PDO::PARAM_INT);
240             $stmt->bindParam(':ncloc', $fileNcloc, PDO::PARAM_INT);
241             $stmt->bindParam(':locExecutable', $fileLocExecutable, PDO::PARAM_INT);
242             $stmt->bindParam(':locExecuted', $fileLocExecuted, PDO::PARAM_INT);
243             $stmt->execute();
244
245             $stmtSelectFunctionId = $this->dbh->prepare(
246               'SELECT code_function_id
247                  FROM code_file, code_function
248                 WHERE code_function.code_file_id       = code_file.code_file_id
249                   AND code_file.revision               = :revision
250                   AND code_function.code_function_name = :functionName;'
251             );
252
253             $stmtInsertFunction = $this->dbh->prepare(
254               'INSERT INTO metrics_function
255                            (run_id, code_function_id, metrics_function_coverage,
256                            metrics_function_loc, metrics_function_loc_executable, metrics_function_loc_executed,
257                            metrics_function_ccn, metrics_function_crap, metrics_function_npath)
258                      VALUES(:runId, :functionId, :coverage, :loc,
259                             :locExecutable, :locExecuted, :ccn, :crap, :npath);'
260             );
261
262             $stmtSelectClassId = $this->dbh->prepare(
263               'SELECT code_class_id
264                  FROM code_file, code_class
265                 WHERE code_class.code_file_id    = code_file.code_file_id
266                   AND code_file.revision         = :revision
267                   AND code_class.code_class_name = :className;'
268             );
269
270             $stmtInsertClass = $this->dbh->prepare(
271               'INSERT INTO metrics_class
272                            (run_id, code_class_id, metrics_class_coverage,
273                            metrics_class_loc, metrics_class_loc_executable, metrics_class_loc_executed,
274                            metrics_class_aif, metrics_class_ahf,
275                            metrics_class_cis, metrics_class_csz, metrics_class_dit,
276                            metrics_class_impl, metrics_class_mif, metrics_class_mhf,
277                            metrics_class_noc, metrics_class_pf, metrics_class_vars,
278                            metrics_class_varsnp, metrics_class_varsi,
279                            metrics_class_wmc, metrics_class_wmcnp, metrics_class_wmci)
280                      VALUES(:runId, :classId, :coverage, :loc, :locExecutable,
281                             :locExecuted, :aif, :ahf, :cis, :csz, :dit, :impl,
282                             :mif, :mhf, :noc, :pf, :vars, :varsnp, :varsi,
283                             :wmc, :wmcnp, :wmci);'
284             );
285
286             $stmtSelectMethodId = $this->dbh->prepare(
287               'SELECT code_method_id
288                  FROM code_file, code_class, code_method
289                 WHERE code_class.code_file_id      = code_file.code_file_id
290                   AND code_class.code_class_id     = code_method.code_class_id
291                   AND code_file.revision           = :revision
292                   AND code_class.code_class_name   = :className
293                   AND code_method.code_method_name = :methodName;'
294             );
295
296             $stmtInsertMethod = $this->dbh->prepare(
297               'INSERT INTO metrics_method
298                            (run_id, code_method_id, metrics_method_coverage,
299                            metrics_method_loc, metrics_method_loc_executable, metrics_method_loc_executed,
300                            metrics_method_ccn, metrics_method_crap, metrics_method_npath)
301                      VALUES(:runId, :methodId, :coverage, :loc,
302                             :locExecutable, :locExecuted, :ccn, :crap, :npath);'
303             );
304
305             foreach ($fileMetrics->getFunctions() as $functionMetrics) {
306                 $functionName = $functionMetrics->getFunction()->getName();
307
308                 $stmtSelectFunctionId->bindParam(':functionName', $functionName, PDO::PARAM_STR);
309                 $stmtSelectFunctionId->bindParam(':revision', $revision, PDO::PARAM_INT);
310                 $stmtSelectFunctionId->execute();
311
312                 $functionId    = (int)$stmtSelectFunctionId->fetchColumn();
313                 $stmtSelectFunctionId->closeCursor();
314
315                 $functionCoverage      = $functionMetrics->getCoverage();
316                 $functionLoc           = $functionMetrics->getLoc();
317                 $functionLocExecutable = $functionMetrics->getLocExecutable();
318                 $functionLocExecuted   = $functionMetrics->getLocExecuted();
319                 $functionCcn           = $functionMetrics->getCCN();
320                 $functionCrap          = $functionMetrics->getCrapIndex();
321                 $functionNpath         = $functionMetrics->getNPath();
322
323                 $stmtInsertFunction->bindParam(':runId', $runId, PDO::PARAM_INT);
324                 $stmtInsertFunction->bindParam(':functionId', $functionId, PDO::PARAM_INT);
325                 $stmtInsertFunction->bindParam(':coverage', $functionCoverage);
326                 $stmtInsertFunction->bindParam(':loc', $functionLoc, PDO::PARAM_INT);
327                 $stmtInsertFunction->bindParam(':locExecutable', $functionLocExecutable, PDO::PARAM_INT);
328                 $stmtInsertFunction->bindParam(':locExecuted', $functionLocExecuted, PDO::PARAM_INT);
329                 $stmtInsertFunction->bindParam(':ccn', $functionCcn, PDO::PARAM_INT);
330                 $stmtInsertFunction->bindParam(':crap', $functionCrap);
331                 $stmtInsertFunction->bindParam(':npath', $functionNpath, PDO::PARAM_INT);
332                 $stmtInsertFunction->execute();
333             }
334
335             foreach ($fileMetrics->getClasses() as $classMetrics) {
336                 $className = $classMetrics->getClass()->getName();
337
338                 $stmtSelectClassId->bindParam(':className', $className, PDO::PARAM_STR);
339                 $stmtSelectClassId->bindParam(':revision', $revision, PDO::PARAM_INT);
340                 $stmtSelectClassId->execute();
341
342                 $classId       = (int)$stmtSelectClassId->fetchColumn();
343                 $stmtSelectClassId->closeCursor();
344
345                 $classCoverage      = $classMetrics->getCoverage();
346                 $classLoc           = $classMetrics->getLoc();
347                 $classLocExecutable = $classMetrics->getLocExecutable();
348                 $classLocExecuted   = $classMetrics->getLocExecuted();
349                 $classAif           = $classMetrics->getAIF();
350                 $classAhf           = $classMetrics->getAHF();
351                 $classCis           = $classMetrics->getCIS();
352                 $classCsz           = $classMetrics->getCSZ();
353                 $classDit           = $classMetrics->getDIT();
354                 $classImpl          = $classMetrics->getIMPL();
355                 $classMif           = $classMetrics->getMIF();
356                 $classMhf           = $classMetrics->getMHF();
357                 $classNoc           = $classMetrics->getNOC();
358                 $classPf            = $classMetrics->getPF();
359                 $classVars          = $classMetrics->getVARS();
360                 $classVarsnp        = $classMetrics->getVARSnp();
361                 $classVarsi         = $classMetrics->getVARSi();
362                 $classWmc           = $classMetrics->getWMC();
363                 $classWmcnp         = $classMetrics->getWMCnp();
364                 $classWmci          = $classMetrics->getWMCi();
365
366                 $stmtInsertClass->bindParam(':runId', $runId, PDO::PARAM_INT);
367                 $stmtInsertClass->bindParam(':classId', $classId, PDO::PARAM_INT);
368                 $stmtInsertClass->bindParam(':coverage', $classCoverage);
369                 $stmtInsertClass->bindParam(':loc', $classLoc, PDO::PARAM_INT);
370                 $stmtInsertClass->bindParam(':locExecutable', $classLocExecutable, PDO::PARAM_INT);
371                 $stmtInsertClass->bindParam(':locExecuted', $classLocExecuted, PDO::PARAM_INT);
372                 $stmtInsertClass->bindParam(':aif', $classAif);
373                 $stmtInsertClass->bindParam(':ahf', $classAhf);
374                 $stmtInsertClass->bindParam(':cis', $classCis, PDO::PARAM_INT);
375                 $stmtInsertClass->bindParam(':csz', $classCsz, PDO::PARAM_INT);
376                 $stmtInsertClass->bindParam(':dit', $classDit, PDO::PARAM_INT);
377                 $stmtInsertClass->bindParam(':impl', $classImpl, PDO::PARAM_INT);
378                 $stmtInsertClass->bindParam(':mif', $classMif);
379                 $stmtInsertClass->bindParam(':mhf', $classMhf);
380                 $stmtInsertClass->bindParam(':noc', $classNoc, PDO::PARAM_INT);
381                 $stmtInsertClass->bindParam(':pf', $classPf);
382                 $stmtInsertClass->bindParam(':vars', $classVars, PDO::PARAM_INT);
383                 $stmtInsertClass->bindParam(':varsnp', $classVarsnp, PDO::PARAM_INT);
384                 $stmtInsertClass->bindParam(':varsi', $classVarsi, PDO::PARAM_INT);
385                 $stmtInsertClass->bindParam(':wmc', $classWmc, PDO::PARAM_INT);
386                 $stmtInsertClass->bindParam(':wmcnp', $classWmcnp, PDO::PARAM_INT);
387                 $stmtInsertClass->bindParam(':wmci', $classWmci, PDO::PARAM_INT);
388                 $stmtInsertClass->execute();
389
390                 foreach ($classMetrics->getMethods() as $methodMetrics) {
391                     $methodName = $methodMetrics->getMethod()->getName();
392
393                     $stmtSelectMethodId->bindParam(':className', $className, PDO::PARAM_STR);
394                     $stmtSelectMethodId->bindParam(':methodName', $methodName, PDO::PARAM_STR);
395                     $stmtSelectMethodId->bindParam(':revision', $revision, PDO::PARAM_INT);
396                     $stmtSelectMethodId->execute();
397
398                     $methodId      = (int)$stmtSelectMethodId->fetchColumn();
399                     $stmtSelectMethodId->closeCursor();
400
401                     $methodCoverage      = $methodMetrics->getCoverage();
402                     $methodLoc           = $methodMetrics->getLoc();
403                     $methodLocExecutable = $methodMetrics->getLocExecutable();
404                     $methodLocExecuted   = $methodMetrics->getLocExecuted();
405                     $methodCcn           = $methodMetrics->getCCN();
406                     $methodCrap          = $methodMetrics->getCrapIndex();
407                     $methodNpath         = $methodMetrics->getNPath();
408
409                     $stmtInsertMethod->bindParam(':runId', $runId, PDO::PARAM_INT);
410                     $stmtInsertMethod->bindParam(':methodId', $methodId, PDO::PARAM_INT);
411                     $stmtInsertMethod->bindParam(':coverage', $methodCoverage);
412                     $stmtInsertMethod->bindParam(':loc', $methodLoc, PDO::PARAM_INT);
413                     $stmtInsertMethod->bindParam(':locExecutable', $methodLocExecutable, PDO::PARAM_INT);
414                     $stmtInsertMethod->bindParam(':locExecuted', $methodLocExecuted, PDO::PARAM_INT);
415                     $stmtInsertMethod->bindParam(':ccn', $methodCcn, PDO::PARAM_INT);
416                     $stmtInsertMethod->bindParam(':crap', $methodCrap);
417                     $stmtInsertMethod->bindParam(':npath', $methodNpath, PDO::PARAM_INT);
418                     $stmtInsertMethod->execute();
419                 }
420             }
421
422             unset($stmtSelectFunctionId);
423             unset($stmtInsertFunction);
424             unset($stmtSelectClassId);
425             unset($stmtInsertClass);
426             unset($stmtSelectMethodId);
427             unset($stmtInsertMethod);
428
429             $stmt = $this->dbh->prepare(
430               'SELECT code_line_id, code_line_covered
431                  FROM code_line
432                 WHERE code_file_id     = :fileId
433                   AND code_line_number = :lineNumber;'
434             );
435
436             $stmt2 = $this->dbh->prepare(
437               'UPDATE code_line
438                   SET code_line_covered = :lineCovered
439                 WHERE code_line_id      = :lineId;'
440             );
441
442             $stmt3 = $this->dbh->prepare(
443               'INSERT INTO code_coverage
444                       (test_id, code_line_id)
445                 VALUES(:testId, :lineId);'
446             );
447
448             for ($lineNumber = 1; $lineNumber <= $fileLoc; $lineNumber++) {
449                 $coveringTests = PHPUnit_Util_CodeCoverage::getCoveringTests(
450                   $codeCoverage, $file, $lineNumber
451                 );
452
453                 if (is_array($coveringTests)) {
454                     $stmt->bindParam(':fileId', $fileId, PDO::PARAM_INT);
455                     $stmt->bindParam(':lineNumber', $lineNumber, PDO::PARAM_INT);
456                     $stmt->execute();
457
458                     $codeLineId      = (int)$stmt->fetchColumn(0);
459                     $oldCoverageFlag = (int)$stmt->fetchColumn(1);
460                     $newCoverageFlag = isset($summary[$file][$lineNumber]) ? 1 : 0;
461
462                     if (($oldCoverageFlag == 0 && $newCoverageFlag != 0) ||
463                         ($oldCoverageFlag <  0 && $newCoverageFlag >  0)) {
464                         $stmt2->bindParam(':lineCovered', $newCoverageFlag, PDO::PARAM_INT);
465                         $stmt2->bindParam(':lineId', $codeLineId, PDO::PARAM_INT);
466                         $stmt2->execute();
467                     }
468
469                     foreach ($coveringTests as $test) {
470                         $stmt3->bindParam(':testId', $test->__db_id, PDO::PARAM_INT);
471                         $stmt3->bindParam(':lineId', $codeLineId, PDO::PARAM_INT);
472                         $stmt3->execute();
473                     }
474                 }
475             }
476         }
477
478         unset($stmt);
479         unset($stmt2);
480         unset($stmt3);
481
482         $stmt = $this->dbh->prepare(
483           'SELECT code_method.code_method_id
484              FROM code_class, code_method
485             WHERE code_class.code_class_id     = code_method.code_class_id
486               AND code_class.code_class_name   = :className
487               AND code_method.code_method_name = :methodName;'
488         );
489
490         $stmt2 = $this->dbh->prepare(
491           'UPDATE test
492               SET code_method_id = :methodId
493             WHERE test_id = :testId;'
494         );
495
496         foreach ($result->topTestSuite() as $test) {
497             if ($test instanceof PHPUnit_Framework_TestCase) {
498                 $className  = get_class($test);
499                 $methodName = $test->getName();
500
501                 $stmt->bindParam(':className', $className, PDO::PARAM_STR);
502                 $stmt->bindParam(':methodName', $methodName, PDO::PARAM_STR);
503                 $stmt->execute();
504
505                 $methodId = (int)$stmt->fetchColumn();
506                 $stmt->closeCursor();
507
508                 $stmt2->bindParam(':methodId', $methodId, PDO::PARAM_INT);
509                 $stmt2->bindParam(':testId', $test->__db_id, PDO::PARAM_INT);
510                 $stmt2->execute();
511             }
512         }
513
514         unset($stmt);
515         unset($stmt2);
516
517         $stmt = $this->dbh->prepare(
518           'INSERT INTO metrics_project
519                        (run_id, metrics_project_cls, metrics_project_clsa,
520                        metrics_project_clsc, metrics_project_roots,
521                        metrics_project_leafs, metrics_project_interfs,
522                        metrics_project_maxdit)
523                  VALUES(:runId, :cls, :clsa, :clsc, :roots, :leafs,
524                         :interfs, :maxdit);'
525         );
526
527         $cls     = $projectMetrics->getCLS();
528         $clsa    = $projectMetrics->getCLSa();
529         $clsc    = $projectMetrics->getCLSc();
530         $interfs = $projectMetrics->getInterfs();
531         $roots   = $projectMetrics->getRoots();
532         $leafs   = $projectMetrics->getLeafs();
533         $maxDit  = $projectMetrics->getMaxDit();
534
535         $stmt->bindParam(':runId', $runId, PDO::PARAM_INT);
536         $stmt->bindParam(':cls', $cls, PDO::PARAM_INT);
537         $stmt->bindParam(':clsa', $clsa, PDO::PARAM_INT);
538         $stmt->bindParam(':clsc', $clsc, PDO::PARAM_INT);
539         $stmt->bindParam(':roots', $roots, PDO::PARAM_INT);
540         $stmt->bindParam(':leafs', $leafs, PDO::PARAM_INT);
541         $stmt->bindParam(':interfs', $interfs, PDO::PARAM_INT);
542         $stmt->bindParam(':maxdit', $maxDit, PDO::PARAM_INT);
543         $stmt->execute();
544
545         unset($stmt);
546
547         $stmt = $this->dbh->prepare(
548           'UPDATE code_class
549               SET code_class_parent_id = :parentClassId
550             WHERE code_class_id = :classId;'
551         );
552
553         $stmt2 = $this->dbh->prepare(
554           'SELECT code_class.code_class_id as code_class_id
555              FROM code_class, code_file
556             WHERE code_class.code_file_id    = code_file.code_file_id
557               AND code_file.revision         = :revision
558               AND code_class.code_class_name = :parentClassName;'
559         );
560
561         foreach ($storedClasses as $className => $classId) {
562             $class       = new ReflectionClass($className);
563             $parentClass = $class->getParentClass();
564
565             if ($parentClass !== FALSE) {
566                 $parentClassName = $parentClass->getName();
567                 $parentClassId   = 0;
568
569                 if (isset($storedClasses[$parentClassName])) {
570                     $parentClassId = $storedClasses[$parentClassName];
571                 } else {
572                     $stmt2->bindParam(':parentClassName', $parentClassName, PDO::PARAM_STR);
573                     $stmt2->bindParam(':revision', $revision, PDO::PARAM_INT);
574                     $stmt2->execute();
575
576                     $parentClassId = (int)$stmt2->fetchColumn();
577                     $stmt2->closeCursor();
578                 }
579
580                 if ($parentClassId > 0) {
581                     $stmt->bindParam(':classId', $classId, PDO::PARAM_INT);
582                     $stmt->bindParam(':parentClassId', $parentClassId, PDO::PARAM_INT);
583                     $stmt->execute();
584                 }
585             }
586         }
587
588         unset($stmt);
589         unset($stmt2);
590
591         $this->dbh->commit();
592     }
593 }
594 ?>