diff --git a/tests/ParserFrameworkValidationTests.php b/tests/ParserFrameworkValidationTests.php index 74ca07a2..b696a8df 100644 --- a/tests/ParserFrameworkValidationTests.php +++ b/tests/ParserFrameworkValidationTests.php @@ -40,25 +40,33 @@ public function testFrameworkErrors($testCaseFile, $frameworkName) { $parser = new \Microsoft\PhpParser\Parser(); $sourceFile = $parser->parseSourceFile($fileContents); - $directory = __DIR__ . "/output/$frameworkName/"; - if (!file_exists($dir = __DIR__ . "/output")) { - mkdir($dir); - } - if (!file_exists($directory)) { - mkdir($directory); - } - $outFile = $directory . basename($testCaseFile); - file_put_contents($outFile, $fileContents); - - foreach ($sourceFile->getDescendantNodesAndTokens() as $child) { - if ($child instanceof Token) { - $this->assertNotEquals(\Microsoft\PhpParser\TokenKind::Unknown, $child->kind, "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: "); + try { + foreach ($sourceFile->getDescendantNodesAndTokens() as $child) { + if ($child instanceof Token) { + if (get_class($child) === Token::class && $child->kind !== \Microsoft\PhpParser\TokenKind::Unknown) { + // NOTE: This parsing many tokens each from 10000+ files - the PHPUnit assert method calls are slow and + // Without this optimization, the test suite takes 93 seconds. + // With this optimization, the method takes 30 seconds. + continue; + } + $this->assertNotEquals(\Microsoft\PhpParser\TokenKind::Unknown, $child->kind, "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: "); + } + } + } catch (Throwable $e) { + $directory = __DIR__ . "/output/$frameworkName/"; + if (!file_exists($dir = __DIR__ . "/output")) { + mkdir($dir); + } + if (!file_exists($directory)) { + mkdir($directory); } + $outFile = $directory . basename($testCaseFile); + file_put_contents($outFile, $fileContents); + throw $e; } - unlink($outFile); // echo json_encode($parser->getErrors($sourceFile)); } }