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); }
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); } }
/** methods to use when parsed files are already available */ public function addParsedFile(XRef_IParsedFile $pf) { parent::addParsedFile($pf); $slices = $this->getFileSlices($pf); $this->slices[$pf->getFileName()] = $slices; }