0

We already have the reverse convention where in a phpUnit test docblock it is normal to use the @covers annotation.

If you are looking at a piece of code it is often helpful to look at tests that exercise that logic to understand what the code is supposed to do. In PHP, is there a convention to document in your code where to find the tests that was written to exercise the function? If not, we plan to adopt our own convention and are considering one of these options:

  • use the phpDocumentor @internal annotation
  • use a completely custom annotation like @spec
  • just a free comment in the docblock, but styled in a quick recognisable pattern
  • don't document but find out where it is tested by commenting out the code, run the test suite and see which tests fail.

Are there any warnings against using any of these?

Jannie Theunissen
  • 28,256
  • 21
  • 100
  • 127

1 Answers1

0

The question is why do You need this for? Is anybody going to read those annotations? You should run all your tests as often as it is possible, and if you will run them with test coverage option, you will see what is covered by tests and what is not.

If You want to use this only to navigate in your IDE, maybe you can use keyboard shortcut to achieve this. I.e. I work on OSX with PHPStorm and I'm Using CMD+SHIFT+T to navigate between tests and a tested code.

Rafal Kozlowski
  • 720
  • 5
  • 12