RuleTestCase: enable gathering analyser errors without assert#1728
Merged
ondrejmirtes merged 1 commit intophpstan:1.8.xfrom Oct 17, 2022
Merged
Conversation
Contributor
|
Interesting, fyi @matthiasnoback also recently started a discussion related to RuleTestCase: phpstan/phpstan#8006 |
Contributor
Author
|
@herndlm Thanks for the context. In fact I used something quite similar (at least as far as I can tell from having a brief look) before this. Here is my previous test case and an input file. However, both of these approaches only solve the issue with line numbers (and only partially). I'd also want to avoid writing down the error messages myself. At the very least I'd want to call a parametrized method to generate the error message (so I can at least fix typos etc easily). However, generating the whole thing automatically and then just checking it seems even better (even if some hacks are required). |
Member
|
Thank you. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I want to propose extracting the part of
RuleTestCase::analysethat gathers the actual errors into its own public method so that the child test can do the comparison in a different way when necessary.The use-case I have for this is that I want to use golden tests (i.e. gather the errors once, save them into a file, check them manually and then test against this saved sample in the future) instead of writing down the expected errors manually. This should make it possible to change the error messages easily, as well as edit the analysed file without having to worry about line numbers etc.
Unfortunately, the current interface of the
RuleTestCasedoes not allow me to do this easily. For now, I'm using this workaround but as I'm relying on things not covered by BC promise, it could break easily in the future.