-
Notifications
You must be signed in to change notification settings - Fork 477
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
Add support for result cache meta extensions #3765
Add support for result cache meta extensions #3765
Conversation
This comment was marked as outdated.
This comment was marked as outdated.
No need to do that. First we need to agree how it should work here, then merge it, then you can require |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really nice! You almost nailed it :)
If you wanted to add a test, it'd make sense to do an E2E test similar to what we do here:
phpstan-src/.github/workflows/e2e-tests.yml
Lines 128 to 137 in b614f70
- script: | | |
cd e2e/bug-9622-trait | |
echo -n > phpstan-baseline.neon | |
../../bin/phpstan -vvv | |
patch -b src/Foo.php < patch-1.patch | |
cat baseline-1.neon > phpstan-baseline.neon | |
../../bin/phpstan -vvv | |
mv src/Foo.php.orig src/Foo.php | |
echo -n > phpstan-baseline.neon | |
../../bin/phpstan -vvv |
- Create an example project under
e2e
directory - Create some sample result cache meta extension there that would return different hash based on something we'll change later
- Run PHPStan, Run PHPStan again with
--fail-without-result-cache
- should exit with 0 - Change the thing that will change the hash. Can be some txt file within the project.
- Run PHPStan again with
--fail-without-result-cache
, should error. You can assert the output with bashunit similarly to herephpstan-src/.github/workflows/e2e-tests.yml
Lines 172 to 176 in b614f70
OUTPUT=$(../bashunit -a exit_code "1" "../../bin/phpstan analyze --no-progress --level 8 --error-format raw data/") echo "$OUTPUT" ../bashunit -a line_count 2 "$OUTPUT" ../bashunit -a matches "Note: Using configuration file .+phpstan.neon." "$OUTPUT" ../bashunit -a contains 'Method class@anonymous/TestClassUsingTrait.php:20::doBar() should return stdClass but returns Exception.' "$OUTPUT"
This introduces contract for extending the way how result cache metadata is calculated, so PHPStan extensions can take part into deciding whether analysis should be re-run or its result can be re-use from cache.
Did not think that new version of PHPStan invalidates result cache anyway.
23a4300
to
2584564
Compare
2584564
to
041f6d0
Compare
@ondrejmirtes rebased on top of |
Thank you. Now you can send the portion in phpstan-symfony while requiring PHPStan |
Docs: phpstan/phpstan@3fa1a7c |
@ondrejmirtes is 2.1.2 going to be tagged soon? I would like to start working on Symfony extension 🙂. |
You can put that requirement in composer.json in the extension now and it's going to download the current dev version. |
Yeah, I just did it and was surprised it worked ( |
Yeah, probably something like that. |
Important
This feature was brought to you thanks to GetResponse - Marketing Software for Professional Email Marketing, which paid for my work on this.
This introduces contract for extending the way how result cache metadata is calculated, so PHPStan extensions can take part into deciding whether analysis should be re-run or its result can be re-use from cache.
It is a base for phpstan/phpstan-symfony#255, which needs separate PR that introduces
ResultCacheMetaExtension
for Symfony DI container. It will be done when this gets merged (and released?).@ondrejmirtes I need some help / your decisions:
ResultCacheManager
. Please point me how/if I should test this extension point. Just runmake build
and verified everything passes.phpstanExtensions
entry to the array with metadata but I am not 100% satisfied with it. Maybe it should bemetaExtensions
ormetaFromPhpstanExtensions
or something different. Or maybe it shouldn't be nested, but merged with the main array? Let me know.ConditionalTagsExtension
because after code analysis and seeing how e.g.DiagnoseExtension
is implemented I've encountered such usage and thoughtResultCacheManager
should be there too. But it's a wild guess only, please let me know if I should keep it there.ResultCacheManager::getMeta()
items be converted to an extension? That could act as e2e test, but also could require some hacks in order to keep backward compatibility with existing result caches (depending on the scheme of the array with metadata).