Skip to content

Commit 5256703

Browse files
committed
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.
1 parent 7acdeeb commit 5256703

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

tests/ParserFrameworkValidationTests.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@ public function frameworkErrorProvider() {
1818
$iterator = new RecursiveDirectoryIterator(__DIR__ . "/../validation/frameworks/" . $frameworkName);
1919

2020
foreach (new RecursiveIteratorIterator($iterator) as $file) {
21-
if (strpos($file, ".php") !== false) {
21+
$pathName = $file->getPathname();
22+
if (preg_match('@\.php$@', $pathName) > 0) {
23+
// Include files ending in ".php", but don't include XML(foo.phpunit.xml) or binary files (foo.php.gz)
2224
$totalSize += $file->getSize();
23-
$testProviderArray[$frameworkName . "::" . $file->getBasename()] = [$file->getPathname(), $frameworkName];
25+
$testProviderArray[$frameworkName . "::" . $file->getBasename()] = [$pathName, $frameworkName];
2426
}
2527
}
2628
}
@@ -33,7 +35,7 @@ public function frameworkErrorProvider() {
3335
/**
3436
* @dataProvider frameworkErrorProvider
3537
*/
36-
public function testFramworkErrors($testCaseFile, $frameworkName) {
38+
public function testFrameworkErrors($testCaseFile, $frameworkName) {
3739
$fileContents = file_get_contents($testCaseFile);
3840
$parser = new \Microsoft\PhpParser\Parser();
3941
$sourceFile = $parser->parseSourceFile($fileContents);
@@ -51,8 +53,8 @@ public function testFramworkErrors($testCaseFile, $frameworkName) {
5153
foreach ($sourceFile->getDescendantNodesAndTokens() as $child) {
5254
if ($child instanceof Token) {
5355
$this->assertNotEquals(\Microsoft\PhpParser\TokenKind::Unknown, $child->kind, "input: $testCaseFile\r\nexpected: ");
54-
$this->assertNotTrue($child instanceof \Microsoft\PhpParser\SkippedToken, "input: $testCaseFile\r\nexpected: ");
55-
$this->assertNotTrue($child instanceof \Microsoft\PhpParser\MissingToken, "input: $testCaseFile\r\nexpected: ");
56+
$this->assertNotInstanceOf(\Microsoft\PhpParser\SkippedToken::class, $child, "input: $testCaseFile\r\nexpected: ");
57+
$this->assertNotInstanceOf(\Microsoft\PhpParser\MissingToken::class, $child, "input: $testCaseFile\r\nexpected: ");
5658
}
5759
}
5860

0 commit comments

Comments
 (0)