public function testSimpleEngineIncremental() { // old errors are not reported in incremental mode, // even if the line numbers are changed $lint_engine = new XRef_LintEngine_Simple($this->xref, false); $file_provider1 = new XRef_FileProvider_InMemory(array('fileA.php' => '<?php echo $bar;')); $file_provider2 = new XRef_FileProvider_InMemory(array('fileA.php' => '<?php echo $bar;')); $report = $lint_engine->getIncrementalReport($file_provider1, $file_provider2, array("fileA.php")); $this->assertTrue(count($report) == 0); // new errors in the same file are reported $lint_engine = new XRef_LintEngine_Simple($this->xref, false); $file_provider1 = new XRef_FileProvider_InMemory(array('fileA.php' => '<?php echo $bar;')); $file_provider2 = new XRef_FileProvider_InMemory(array('fileA.php' => '<?php echo $bar; // not reported echo $foo; // new error ')); $report = $lint_engine->getIncrementalReport($file_provider1, $file_provider2, array("fileA.php")); $this->assertTrue(count($report) == 1); $this->assertTrue(isset($report["fileA.php"])); $this->assertTrue(count($report["fileA.php"]) == 1); $this->assertTrue($report["fileA.php"][0]->tokenText == '$foo'); // all errors in new files are reported $lint_engine = new XRef_LintEngine_Simple($this->xref, false); $file_provider1 = new XRef_FileProvider_InMemory(array('fileA.php' => '<?php echo $bar;')); $file_provider2 = new XRef_FileProvider_InMemory(array('fileA.php' => '<?php echo $bar; // not reported echo $foo; // new error ', 'fileB.php' => '<?php echo $qux;')); $report = $lint_engine->getIncrementalReport($file_provider1, $file_provider2, array("fileA.php", 'fileB.php')); $this->assertTrue(count($report) == 2); $this->assertTrue(isset($report["fileA.php"])); $this->assertTrue(isset($report["fileB.php"])); $this->assertTrue(count($report["fileA.php"]) == 1); $this->assertTrue(count($report["fileB.php"]) == 1); $this->assertTrue($report["fileA.php"][0]->tokenText == '$foo'); $this->assertTrue($report["fileB.php"][0]->tokenText == '$qux'); }
protected function checkPhpCode($php_code, $expected_defects) { $pf = $this->xref->getParsedFile("filename.php", $php_code); $lint_engine = new XRef_LintEngine_Simple($this->xref, false); $lint_engine->addParsedFile($pf); $pf->release(); $report = $lint_engine->collectReport(); $errors = isset($report["filename.php"]) ? $report["filename.php"] : array(); $count_found = count($errors); $count_expected = count($expected_defects); if ($count_found != $count_expected) { print_r($report); $this->fail("Wrong number of errors: found={$count_found}, expected={$count_expected}"); } else { $this->assertTrue($count_found == $count_expected, "Expected number of defects"); } for ($i = 0; $i < count($errors); ++$i) { $found_defect = $errors[$i]; list($token_text, $line_number, $severity) = $expected_defects[$i]; $this->checkFoundDefect($found_defect, $token_text, $line_number, $severity); } }
/** optimized method for incremental mode */ public function getIncrementalReport(XRef_IFileProvider $from, XRef_IFileProvider $to, $list_of_modified_files) { $this->loadFilesMap($from); $files = $this->xref->filterFiles($list_of_modified_files); // collect file errors & slices for modified files foreach ($files as $filename) { $this->report[$filename] = $this->getFileReportCached($from, $filename); $this->slices[$filename] = $this->getFileSlicesCached($from, $filename); } // collect slices for all other files $from_files = $this->xref->filterFiles($from->getFiles()); foreach ($from_files as $filename) { if (!isset($this->slices[$filename])) { $this->slices[$filename] = $this->getFileSlicesCached($from, $filename); } } $old_report = $this->collectReport(); // update reports, slices and filesmap for modified files $this->projectDatabase = new XRef_ProjectDatabase(); $this->report = array(); foreach ($files as $filename) { unset($this->filesMap[$filename]); $this->report[$filename] = $this->getFileReportCached($to, $filename); $this->slices[$filename] = $this->getFileSlicesCached($to, $filename); } $new_report = $this->collectReport(); $this->releaseParsedFile(); $this->saveFilesMap($to); return XRef_LintEngine_Simple::getNewProjectErrors($old_report, $new_report); }