Search code examples
phpunitphpstorm

How to make PhpStorm recognize the #[Test]-Attribute?


I am running PhpStorm 2022.1.1 with Build #PS-221.5591.58.

As I wanted to use attributes I updated to PHPUnit 10.0.14, which contains the ability to use the attribute #[Test] to signal that a method is supposed to be a test.

Unfortunately it seems that PhpStorm does not recognize such a method as test if it is not prefixed with test. No run button is shown beside the method and running the test-class in itself will not run tests that are not prefixed with test.

Is it possible yet to make this work, so the test-prefix is not necessary?


Solution

  • This will be supported in the next major PhpStorm 2023.1 version.

    This is the corresponding ticket: https://youtrack.jetbrains.com/issue/WI-71455 . As you may see it is marked as Verified on 20 Feb 2023 (less than 2 weeks ago) but still has no "Available in" info filled in yet (so it's not clear in which EAP build this can be tested).

    But you can check EAP builds yourself as they get released (once a week usually; the latest one is EAP 6 from 2nd of March) and see if it's already included: https://www.jetbrains.com/phpstorm/nextversion/

    Just in case: 1) EAP builds for major versions are free as they come with their own 30 days licence. 2) You can install it in parallel to your current IDE version (each major version uses a different folder for IDE-wide configs). 3) Just do not open the same project in both versions at the same time (so it does not mess up with project settings). 4) If you want to be super sure: backup your project_root/.idea subfolder (that's where project settings are stored) before opening it in the EAP build and restore it back after that.