1
0
Fork 0

add definition comparison to validation tests

pull/357/head
Sara Itani 2017-04-10 12:30:46 -07:00
parent fa52aef28a
commit 651e6be08a
1 changed files with 45 additions and 1 deletions

View File

@ -6,6 +6,7 @@ namespace LanguageServer\Tests;
use Exception;
use LanguageServer\Index\Index;
use LanguageServer\ParserKind;
use LanguageServer\ParserResourceFactory;
use LanguageServer\PhpDocument;
use phpDocumentor\Reflection\DocBlockFactory;
@ -16,6 +17,7 @@ use AdvancedJsonRpc;
use RecursiveDirectoryIterator;
use RecursiveIteratorIterator;
use Sabre\Event\Loop;
use Microsoft\PhpParser as Tolerant;
class ValidationTest extends TestCase
{
@ -29,7 +31,7 @@ class ValidationTest extends TestCase
$iterator = new RecursiveDirectoryIterator(__DIR__ . "/../../validation/frameworks/" . $frameworkName);
foreach (new RecursiveIteratorIterator($iterator) as $file) {
if (strpos((string)$file, ".php") !== false) {
if (strpos((string)$file, ".php") !== false && strpos((string)$file, "drupal") === false) {
if ($file->getSize() < 100000) {
$testProviderArray[$frameworkName . "::" . $file->getBasename()] = [$file->getPathname(), $frameworkName];
}
@ -76,4 +78,46 @@ class ValidationTest extends TestCase
}
// echo json_encode($parser->getErrors($sourceFile));
}
/**
* @dataProvider frameworkErrorProvider
*/
public function testDefinitionErrors($testCaseFile, $frameworkName) {
$fileContents = file_get_contents($testCaseFile);
echo "$testCaseFile\n";
$parserKinds = [ParserKind::DIAGNOSTIC_PHP_PARSER, ParserKind::DIAGNOSTIC_TOLERANT_PHP_PARSER];
$maxRecursion = [];
$definitions = [];
foreach ($parserKinds as $kind) {
global $parserKind;
$parserKind = $kind;
$index = new Index;
$docBlockFactory = DocBlockFactory::createInstance();
$definitionResolver = ParserResourceFactory::getDefinitionResolver($index);
$parser = ParserResourceFactory::getParser();
try {
$document = new PhpDocument($testCaseFile, $fileContents, $index, $parser, $docBlockFactory, $definitionResolver);
} catch (\Exception $e) {
continue;
}
$fqns = [];
foreach ($document->getDefinitions() as $defn) {
$fqns[] = $defn->fqn;
}
if (isset($definitions[$testCaseFile])) {
var_dump($definitions[$testCaseFile]);
$this->assertEquals($definitions[$testCaseFile], $fqns);
}
$definitions[$testCaseFile] = $fqns;
$maxRecursion[$testCaseFile] = $definitionResolver::$maxRecursion;
}
}
}