1
0
Fork 0

start adding validation tests

pull/357/head
Sara Itani 2017-03-15 14:10:29 -07:00
parent 4324530389
commit 0824e6d9b8
6 changed files with 89 additions and 1 deletions

9
.gitmodules vendored Normal file
View File

@ -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

View File

@ -6,7 +6,7 @@ use Microsoft\PhpParser as Tolerant;
use LanguageServer\Index\ReadableIndex; use LanguageServer\Index\ReadableIndex;
class ParserResourceFactory { class ParserResourceFactory {
const PARSER_KIND = ParserKind::DIAGNOSTIC_TOLERANT_PHP_PARSER; const PARSER_KIND = ParserKind::TOLERANT_PHP_PARSER;
public static function getParser() { public static function getParser() {
if (self::PARSER_KIND === ParserKind::PHP_PARSER) { if (self::PARSER_KIND === ParserKind::PHP_PARSER) {

View File

@ -0,0 +1,76 @@
<?php
declare(strict_types = 1);
namespace LanguageServer\Tests;
use Exception;
use LanguageServer\Index\Index;
use LanguageServer\ParserResourceFactory;
use LanguageServer\PhpDocument;
use phpDocumentor\Reflection\DocBlockFactory;
use PHPUnit\Framework\TestCase;
use LanguageServer\ClientHandler;
use LanguageServer\Protocol\Message;
use AdvancedJsonRpc;
use RecursiveDirectoryIterator;
use RecursiveIteratorIterator;
use Sabre\Event\Loop;
class ValidationTest extends TestCase
{
public function frameworkErrorProvider() {
$totalSize = 0;
$frameworks = glob(__DIR__ . "/../../validation/frameworks/*", GLOB_ONLYDIR);
$testProviderArray = array();
foreach ($frameworks as $frameworkDir) {
$frameworkName = basename($frameworkDir);
$iterator = new RecursiveDirectoryIterator(__DIR__ . "/../../validation/frameworks/" . $frameworkName);
foreach (new RecursiveIteratorIterator($iterator) as $file) {
if (strpos((string)$file, ".php") !== false) {
$totalSize += $file->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));
}
}

@ -0,0 +1 @@
Subproject commit ac7313dda0644f35031428ff954b6d9e6f90e857

@ -0,0 +1 @@
Subproject commit 546660f957623b2cdc179fe107b28581d60ba190

@ -0,0 +1 @@
Subproject commit afdef17903c52c15642be01169495e08a08b04a7