From 0824e6d9b8f11b80eb07813224c3755f2a5a1708 Mon Sep 17 00:00:00 2001 From: Sara Itani Date: Wed, 15 Mar 2017 14:10:29 -0700 Subject: [PATCH] start adding validation tests --- .gitmodules | 9 +++ src/ParserResourceFactory.php | 2 +- tests/Validation/ValidationTest.php | 76 +++++++++++++++++++++++ validation/frameworks/drupal | 1 + validation/frameworks/php-language-server | 1 + validation/frameworks/wordpress | 1 + 6 files changed, 89 insertions(+), 1 deletion(-) create mode 100644 .gitmodules create mode 100644 tests/Validation/ValidationTest.php create mode 160000 validation/frameworks/drupal create mode 160000 validation/frameworks/php-language-server create mode 160000 validation/frameworks/wordpress diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..3f59547 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,9 @@ +[submodule "validation/frameworks/php-language-server"] + path = validation/frameworks/php-language-server + url = https://github.com/felixfbecker/php-language-server +[submodule "validation/frameworks/wordpress"] + path = validation/frameworks/wordpress + url = https://github.com/wordpress/wordpress +[submodule "validation/frameworks/drupal"] + path = validation/frameworks/drupal + url = https://github.com/drupal/drupal diff --git a/src/ParserResourceFactory.php b/src/ParserResourceFactory.php index 02cd174..0861522 100644 --- a/src/ParserResourceFactory.php +++ b/src/ParserResourceFactory.php @@ -6,7 +6,7 @@ use Microsoft\PhpParser as Tolerant; use LanguageServer\Index\ReadableIndex; class ParserResourceFactory { - const PARSER_KIND = ParserKind::DIAGNOSTIC_TOLERANT_PHP_PARSER; + const PARSER_KIND = ParserKind::TOLERANT_PHP_PARSER; public static function getParser() { if (self::PARSER_KIND === ParserKind::PHP_PARSER) { diff --git a/tests/Validation/ValidationTest.php b/tests/Validation/ValidationTest.php new file mode 100644 index 0000000..79ca6c8 --- /dev/null +++ b/tests/Validation/ValidationTest.php @@ -0,0 +1,76 @@ +getSize(); + $testProviderArray[$frameworkName . "::" . $file->getBasename()] = [$file->getPathname(), $frameworkName]; + } + } + } + if (count($testProviderArray) === 0) { + throw new Exception("ERROR: Validation testsuite frameworks not found - run `git submodule update --init --recursive` to download."); + } + return $testProviderArray; + } + + /** + * @dataProvider frameworkErrorProvider + */ + public function testFramworkErrors($testCaseFile, $frameworkName) { + $fileContents = file_get_contents($testCaseFile); + + $parser = ParserResourceFactory::getParser(); + $docBlockFactory = DocBlockFactory::createInstance(); + $index = new Index; + $definitionResolver = ParserResourceFactory::getDefinitionResolver($index); + + $directory = __DIR__ . "/output/$frameworkName/"; + $outFile = $directory . basename($testCaseFile); + + try { + $document = new PhpDocument($testCaseFile, $fileContents, $index, $parser, $docBlockFactory, $definitionResolver); + } catch (\Exception $e) { + if (!file_exists($dir = __DIR__ . "/output")) { + mkdir($dir); + } + if (!file_exists($directory)) { + mkdir($directory); + } + file_put_contents($outFile, $fileContents); + $this->fail((string)$e); + } + + if (file_exists($outFile)) { + unlink($outFile); + } + // echo json_encode($parser->getErrors($sourceFile)); + } +} \ No newline at end of file diff --git a/validation/frameworks/drupal b/validation/frameworks/drupal new file mode 160000 index 0000000..ac7313d --- /dev/null +++ b/validation/frameworks/drupal @@ -0,0 +1 @@ +Subproject commit ac7313dda0644f35031428ff954b6d9e6f90e857 diff --git a/validation/frameworks/php-language-server b/validation/frameworks/php-language-server new file mode 160000 index 0000000..546660f --- /dev/null +++ b/validation/frameworks/php-language-server @@ -0,0 +1 @@ +Subproject commit 546660f957623b2cdc179fe107b28581d60ba190 diff --git a/validation/frameworks/wordpress b/validation/frameworks/wordpress new file mode 160000 index 0000000..afdef17 --- /dev/null +++ b/validation/frameworks/wordpress @@ -0,0 +1 @@ +Subproject commit afdef17903c52c15642be01169495e08a08b04a7