The PHPStan 1.10.3 release shipped with a new
@not-deprecated annotation! This is a great utility, and I am very thankful to stof for contributing this to PHPStan. This annotation fixes an issue I reported in June 2022 during our massive Drupal 10 readiness initiative.
Drupal core deprecated assertion methods in PHPUnit test classes. A handful of modules decided to replace the method under the same name. PHPStan would find the method, detect the original method was deprecated, and report errors on that method's usage. There was no way to say: "Wait, trust me, this isn't deprecated. I know what I'm doing!" The only approach was to use an inline comment or add the error message to the ignored error setting.
If you scan the Address module, you'll get an error like the following:
It would be cumbersome to go through and annotate all of the calls for this with a preceding
$this->assertSession()->fieldValueEquals($field_name . '[address][locality]', $address['locality']); // @phpstan-ignore-next-line $this->assertOptionSelected($field_name . '[address][administrative_area]', $address['administrative_area']); $this->assertSession()->fieldValueEquals($field_name . '[address][postal_code]', $address['postal_code']); // @phpstan-ignore-next-line $this->assertOptionSelected($field_name . '[address][country_code]', $country_code);
I have opened a merge request for the Address module to add this annotation.
I don't know if Drupal will have another round of deprecated helper methods like this again, but it will be easier to avoid false-positive deprecation warnings!