Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
andreasciamanna opened this issue Aug 16, 2017 · 6 comments
Assignees

Comments

@andreasciamanna
Copy link

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.

@lucatume
Copy link
Owner

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

@lucatume
Copy link
Owner

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

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

@andreasciamanna
Copy link
Author

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.

@lucatume
Copy link
Owner

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

@lucatume lucatume self-assigned this Aug 16, 2017
@lucatume
Copy link
Owner

lucatume commented Aug 16, 2017

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.

@adrianosferreira
Copy link

+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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants