From 651e6be08ad3009c95db1c09fdaa8c3b9d4f6f67 Mon Sep 17 00:00:00 2001 From: Sara Itani Date: Mon, 10 Apr 2017 12:30:46 -0700 Subject: [PATCH] add definition comparison to validation tests --- tests/Validation/ValidationTest.php | 46 ++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/tests/Validation/ValidationTest.php b/tests/Validation/ValidationTest.php index b3f829e..dd4e4da 100644 --- a/tests/Validation/ValidationTest.php +++ b/tests/Validation/ValidationTest.php @@ -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; + } + } } \ No newline at end of file