public function testSimpleEngine() { // usage with parsed file $lint_engine = new XRef_LintEngine_Simple($this->xref, false); $pf = $this->xref->getParsedFile("fileA.php", '<?php echo $foo;'); $lint_engine->addParsedFile($pf); $report = $lint_engine->collectReport(); $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'); // usage with file provider $lint_engine = new XRef_LintEngine_Simple($this->xref, false); $file_provider = new XRef_FileProvider_InMemory(array('fileA.php' => '<?php echo $bar;')); $report = $lint_engine->getReport($file_provider); $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 == '$bar'); // only the php files are checked $lint_engine = new XRef_LintEngine_Simple($this->xref, false); $file_provider = new XRef_FileProvider_InMemory(array('fileA.php' => '<?php echo $baz;', 'fileB.txt' => 'some text with $foo', 'fileC.txt' => '<?php looks like php')); $report = $lint_engine->getReport($file_provider); $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 == '$baz'); // no project integrity is checked $lint_engine = new XRef_LintEngine_Simple($this->xref, false); $file_provider = new XRef_FileProvider_InMemory(array('fileA.php' => '<?php class A { const FOO = 1; }', 'fileB.php' => '<?php echo A::BAR; ')); $report = $lint_engine->getReport($file_provider); $this->assertTrue(count($report) == 0); }
public function collectReport() { $report = parent::collectReport(); // fill the database foreach ($this->slices as $filename => $slices) { if ($slices) { $this->projectDatabase->addFileSlice($filename, $slices["_db"]); } } $this->projectDatabase->finalize(); // run each plugin for each slice foreach ($this->projectCheckPlugins as $plugin_id => $plugin) { $plugin->startLintCheck($this->projectDatabase); foreach ($this->slices as $filename => $slice) { if ($slice) { $plugin->checkFileSlice($this->projectDatabase, $filename, $slice[$plugin_id]); } } $plugin_report = $plugin->getProjectReport($this->projectDatabase); foreach ($plugin_report as $filename => $errors_list) { foreach ($errors_list as $e) { $code = $e['code']; if (!isset($this->errorMap[$code])) { error_log("No descriptions for error code '{$code}'"); continue; } $description = $this->errorMap[$code]; if (!isset($description["severity"]) || !isset($description["message"])) { error_log("Invalid description for error code '{$code}'"); continue; } $code_defect = XRef_CodeDefect::fromTokenText($e['text'], $code, $description['severity'], $description["message"], $e['params']); $code_defect->fileName = $e['location'][0]; $code_defect->lineNumber = $e['location'][1]; $report[$filename][] = $code_defect; } } } return $this->xref->sortAndFilterReport($report); }
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); } }