Testing the error identifier for a custom rule #11058
Replies: 1 comment
-
Great question, it's not currently possible. What I did instead was extracting identifiers programatically for generating this page: https://phpstan.org/error-identifiers The logic makes sure that the identifiers are "static enough" meaning PHPStan's type inference can always resolve them to ConstantStringType. Which forces me to write simple-enough logic so that it doesn't have to be tested IMHO. But RuleTestCase::analyse() is due for a rewrite, the "asserted errors in an array" is really creaky. Similarly to Rule interface deprecating returning plain strings (in favour of RuleErrorBuilder), perhaps we could also support RuleErrorBuilder in the asserted array, making it possible to test everything the rules can return. |
Beta Was this translation helpful? Give feedback.
-
Is it possible to test that a custom rule is using the correct error identifier?
I'm guessing that
RuleTestCase
would have to be updated, maybe the identifier would optionally be added to this line if we wanted to add in to the test?Or is there another way to test this?
Beta Was this translation helpful? Give feedback.
All reactions