lucatume / function-mocker

A Patchwork powered function mocker.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cache directory is causing issues with some IDE's code inspection

andreasciamanna opened this issue · comments

I've noticed that in the most recent version of the library, a vendor\lucatume\function-mocker\cache\ folder is created and some cached code is saved there.

This is causing two issues:

  • Our IDE (PhpStorm/IntelliJ) sees this code and causes some code inspection issues (e.g. seeing multiple definitions of a symbol)
  • The cache does not reflect the actual code until tests are executed
  • Sometimes, the cached code is not updated, even if the original has been changed

Is it possible to make the library cache these files outside the project (e.g. in the default "temp" directory)?

A solution which requires an environment variable (so it can fall back to the current vendor\lucatume\function-mocker\cache\ if the variable is missing) would be also fine.

That's Patchwork cache folder; since this seems to be an IDE specific issue I'm not a fan of caching outside of the project: what about excluding that folder?
exclude-folder-from-inspection

Another approach is to define the cache folder explicitly when initializing FunctionMocker

// in your tests bootstrap file
FunctionMocker::init(['cache-path' => '/temp']);

With 7+ plugins in the same project, it's a bit hard to set all the exclusions.

I've tried the last approach using something like \tad\FunctionMocker\FunctionMocker::init( ['cache-path' => '/tmp'] );.

I've also tried different ways to pass a temporary directory, such as reading the TMPDIR environment variable, setting my own path and using sys_get_temp_dir().

All these solutions lead to the same result:

Warning: Composer\Autoload\includeFile(/Users/andreasciamanna/Local Sites/wpml-development/app/public/wp-content/plugins/sitepress-multilingual-cms/vendor/phpunit/phpunit/src/Framework/TestSuite.php): failed to open stream: "Patchwork\CodeManipulation\Stream::stream_open" call failed in /Users/andreasciamanna/.composer/vendor/composer/ClassLoader.php on line 444

Call Stack:
    0.0002     360888   1. {main}() /Users/andreasciamanna/.composer/vendor/phpunit/phpunit/phpunit:0
    0.0038     985656   2. PHPUnit_TextUI_Command::main() /Users/andreasciamanna/.composer/vendor/phpunit/phpunit/phpunit:52
    0.0038     985768   3. PHPUnit_TextUI_Command->run() /Users/andreasciamanna/.composer/vendor/phpunit/phpunit/src/TextUI/Command.php:116
    0.0038     985768   4. PHPUnit_TextUI_Command->handleArguments() /Users/andreasciamanna/.composer/vendor/phpunit/phpunit/src/TextUI/Command.php:127
    0.0201    3421216   5. PHPUnit_Util_Configuration->getTestSuiteConfiguration() /Users/andreasciamanna/.composer/vendor/phpunit/phpunit/src/TextUI/Command.php:784
PHP Warning:  Composer\Autoload\includeFile(/Users/andreasciamanna/Local Sites/wpml-development/app/public/wp-content/plugins/sitepress-multilingual-cms/vendor/phpunit/phpunit/src/Framework/TestSuite.php): failed to open stream: "Patchwork\CodeManipulation\Stream::stream_open" call failed in /Users/andreasciamanna/.composer/vendor/composer/ClassLoader.php on line 444
    0.0202    3421800   6. PHPUnit_Util_Configuration->getTestSuite() /Users/andreasciamanna/.composer/vendor/phpunit/phpunit/src/Util/Configuration.php:843
PHP Stack trace:
    0.0202    3421800   7. spl_autoload_call() /Users/andreasciamanna/.composer/vendor/phpunit/phpunit/src/Util/Configuration.php:883
PHP   1. {main}() /Users/andreasciamanna/.composer/vendor/phpunit/phpunit/phpunit:0
PHP   2. PHPUnit_TextUI_Command::main() /Users/andreasciamanna/.composer/vendor/phpunit/phpunit/phpunit:52
    0.0202    3421936   8. Composer\Autoload\ClassLoader->loadClass() /Users/andreasciamanna/.composer/vendor/phpunit/phpunit/src/Util/Configuration.php:883
PHP   3. PHPUnit_TextUI_Command->run() /Users/andreasciamanna/.composer/vendor/phpunit/phpunit/src/TextUI/Command.php:116
    0.0202    3421936   9. Composer\Autoload\includeFile() /Users/andreasciamanna/.composer/vendor/composer/ClassLoader.php:322

I don't see where Patchwork or FunctionMocker are involved in the stack trace, but going back to FunctionMocker::init(); causes no issues to the tests.

I can reproduce the issue on dev-master too, looking into it.

Further investigation led me to believe this is something Function Mocker inherits from Patchwork; I will look more to make sure and document my findings.

+1. I have the same problem on PHPStorm, I have a number of plugins in my project and I suffer from inspection issues, too many definitions. When can we expect something?