@@ -40,25 +40,33 @@ public function testFrameworkErrors($testCaseFile, $frameworkName) {
4040 $ parser = new \Microsoft \PhpParser \Parser ();
4141 $ sourceFile = $ parser ->parseSourceFile ($ fileContents );
4242
43- $ directory = __DIR__ . "/output/ $ frameworkName/ " ;
44- if (!file_exists ($ dir = __DIR__ . "/output " )) {
45- mkdir ($ dir );
46- }
47- if (!file_exists ($ directory )) {
48- mkdir ($ directory );
49- }
50- $ outFile = $ directory . basename ($ testCaseFile );
51- file_put_contents ($ outFile , $ fileContents );
52-
53- foreach ($ sourceFile ->getDescendantNodesAndTokens () as $ child ) {
54- if ($ child instanceof Token) {
55- $ this ->assertNotEquals (\Microsoft \PhpParser \TokenKind::Unknown, $ child ->kind , "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: " );
43+ try {
44+ foreach ($ sourceFile ->getDescendantNodesAndTokens () as $ child ) {
45+ if ($ child instanceof Token) {
46+ if (get_class ($ child ) === Token::class && $ child ->kind !== \Microsoft \PhpParser \TokenKind::Unknown) {
47+ // NOTE: This parsing many tokens each from 10000+ files - the PHPUnit assert method calls are slow and
48+ // Without this optimization, the test suite takes 93 seconds.
49+ // With this optimization, the method takes 30 seconds.
50+ continue ;
51+ }
52+ $ this ->assertNotEquals (\Microsoft \PhpParser \TokenKind::Unknown, $ child ->kind , "input: $ testCaseFile \r\nexpected: " );
53+ $ this ->assertNotInstanceOf (\Microsoft \PhpParser \SkippedToken::class, $ child , "input: $ testCaseFile \r\nexpected: " );
54+ $ this ->assertNotInstanceOf (\Microsoft \PhpParser \MissingToken::class, $ child , "input: $ testCaseFile \r\nexpected: " );
55+ }
56+ }
57+ } catch (Throwable $ e ) {
58+ $ directory = __DIR__ . "/output/ $ frameworkName/ " ;
59+ if (!file_exists ($ dir = __DIR__ . "/output " )) {
60+ mkdir ($ dir );
61+ }
62+ if (!file_exists ($ directory )) {
63+ mkdir ($ directory );
5864 }
65+ $ outFile = $ directory . basename ($ testCaseFile );
66+ file_put_contents ($ outFile , $ fileContents );
67+ throw $ e ;
5968 }
6069
61- unlink ($ outFile );
6270 // echo json_encode($parser->getErrors($sourceFile));
6371 }
6472}
0 commit comments