From 5256703431c048c5a10c047be92315f9e10cf006 Mon Sep 17 00:00:00 2001 From: Tyson Andre Date: Tue, 19 Sep 2017 20:21:22 -0700 Subject: [PATCH 1/2] Stop including non-php files in validation tests. Noticed test failures for pgsql.phpunit.xml in the drupal project's test files. (contains the substring ".php") Also, do the matching on the path name, not on the object to string conversion. --- tests/ParserFrameworkValidationTests.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/tests/ParserFrameworkValidationTests.php b/tests/ParserFrameworkValidationTests.php index 08dbbe03..4079f58b 100644 --- a/tests/ParserFrameworkValidationTests.php +++ b/tests/ParserFrameworkValidationTests.php @@ -18,9 +18,11 @@ public function frameworkErrorProvider() { $iterator = new RecursiveDirectoryIterator(__DIR__ . "/../validation/frameworks/" . $frameworkName); foreach (new RecursiveIteratorIterator($iterator) as $file) { - if (strpos($file, ".php") !== false) { + $pathName = $file->getPathname(); + if (preg_match('@\.php$@', $pathName) > 0) { + // Include files ending in ".php", but don't include XML(foo.phpunit.xml) or binary files (foo.php.gz) $totalSize += $file->getSize(); - $testProviderArray[$frameworkName . "::" . $file->getBasename()] = [$file->getPathname(), $frameworkName]; + $testProviderArray[$frameworkName . "::" . $file->getBasename()] = [$pathName, $frameworkName]; } } } @@ -33,7 +35,7 @@ public function frameworkErrorProvider() { /** * @dataProvider frameworkErrorProvider */ - public function testFramworkErrors($testCaseFile, $frameworkName) { + public function testFrameworkErrors($testCaseFile, $frameworkName) { $fileContents = file_get_contents($testCaseFile); $parser = new \Microsoft\PhpParser\Parser(); $sourceFile = $parser->parseSourceFile($fileContents); @@ -51,8 +53,8 @@ public function testFramworkErrors($testCaseFile, $frameworkName) { foreach ($sourceFile->getDescendantNodesAndTokens() as $child) { if ($child instanceof Token) { $this->assertNotEquals(\Microsoft\PhpParser\TokenKind::Unknown, $child->kind, "input: $testCaseFile\r\nexpected: "); - $this->assertNotTrue($child instanceof \Microsoft\PhpParser\SkippedToken, "input: $testCaseFile\r\nexpected: "); - $this->assertNotTrue($child instanceof \Microsoft\PhpParser\MissingToken, "input: $testCaseFile\r\nexpected: "); + $this->assertNotInstanceOf(\Microsoft\PhpParser\SkippedToken::class, $child, "input: $testCaseFile\r\nexpected: "); + $this->assertNotInstanceOf(\Microsoft\PhpParser\MissingToken::class, $child, "input: $testCaseFile\r\nexpected: "); } } From d58538447d2c1c2a6e1fadada86d5fe0aaa34521 Mon Sep 17 00:00:00 2001 From: Tyson Andre Date: Wed, 20 Sep 2017 09:53:09 -0700 Subject: [PATCH 2/2] Use slashes --- tests/ParserFrameworkValidationTests.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ParserFrameworkValidationTests.php b/tests/ParserFrameworkValidationTests.php index 4079f58b..d73efc84 100644 --- a/tests/ParserFrameworkValidationTests.php +++ b/tests/ParserFrameworkValidationTests.php @@ -19,7 +19,7 @@ public function frameworkErrorProvider() { foreach (new RecursiveIteratorIterator($iterator) as $file) { $pathName = $file->getPathname(); - if (preg_match('@\.php$@', $pathName) > 0) { + if (preg_match('/\.php$/', $pathName) > 0) { // Include files ending in ".php", but don't include XML(foo.phpunit.xml) or binary files (foo.php.gz) $totalSize += $file->getSize(); $testProviderArray[$frameworkName . "::" . $file->getBasename()] = [$pathName, $frameworkName];