Skip to content

Commit

Permalink
Try to prevent error with PHP-Parser 5 when running PHPUnit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Jan 8, 2024
1 parent 5c50118 commit 9dac90d
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Internal/DirectoryCreator.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ public static function ensureDirectoryExists(
bool $recursive = true,
): void
{
if (is_dir($directory)) {
return;
}

if (@mkdir($directory, $mode, $recursive)) {
return;
}
Expand Down

1 comment on commit 9dac90d

@ondrejmirtes
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is needed because:

  1. PHPUnit invokes ErrorHandler when the @-suppressed mkdir call triggers "File exists" error.
  2. PHPUnit's ErrorHandler invokes its ExcludeList class which autoloads PHP-Parser's 5.0 Parser class to look for its directory location.
  3. When PHPStan's loads its own PHP-Parser (4.18), there's an error like:
PHP Fatal error:  Class PHPStan\Parser\PhpParserDecorator contains 1 abstract method and must therefore be declared abstract or implement the remaining methods (PhpParser\Parser::getTokens) in phar:///Users/ondrej/Downloads/tadsan-phpstan-rules/vendor/phpstan/phpstan/phpstan.phar/src/Parser/PhpParserDecorator.php on line

Please sign in to comment.