PHPUnit: Difference between revisions

No edit summary
Add PHPUnit 9 and 10 recommendations from Adreas Möller
Line 23: Line 23:
{{#ev:youtube|https://www.youtube.com/watch?v=KtbuEoLWRqQ}}
{{#ev:youtube|https://www.youtube.com/watch?v=KtbuEoLWRqQ}}


== Recommendations ==
''- summary from Andreas Möller's [https://localheinz.com/articles/2023/02/22/documenting-the-system-under-test-in-phpunit/ '''Documenting the system under test'''] (Mar 2023)''
If you use <code>phpunit/phpunit:'''9.0.0'''</code> and below, use <code>@covers</code> '''[https://localheinz.com/articles/2023/02/22/documenting-the-system-under-test-in-phpunit/#content-covers-annotation annotations]''' to document the system under test on the class level. If there is no clear system under test, use the <code>@coversNothing annotation</code> annotation on the class level. Do not document the system under test on the method level, and do not bother with documenting individual methods - this functionality is not present in <code>phpunit/phpunit:10.0.0</code>. Set the <code>[https://docs.phpunit.de/en/9.6/configuration.html#the-forcecoversannotation-attribute forceCoversAnnotation]</code> attribute to <code>true</code> in <code>phpunit.xml</code>.
If you use <code>phpunit/phpunit:'''10.0.0'''</code> and above, use <code>CoversClass</code> '''[https://localheinz.com/articles/2023/02/22/documenting-the-system-under-test-in-phpunit/#content-coversclass-attribute attributes]''' to document the system under test on the class level. If there is no clear system under test, use the <code>CoversNothing</code> attribute on the class level. Set the <code>[https://docs.phpunit.de/en/10.0/configuration.html#the-requirecoveragemetadata-attribute requireCoverageMetadata]</code> attribute to <code>true</code> in <code>phpunit.xml</code>.
If you use <code>@covers</code> annotations in <code>phpunit/phpunit</code> and <code>friendsofphp/php-cs-fixer</code>, enable the <code>[https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/v3.14.4/doc/rules/php_unit/php_unit_test_class_requires_covers.rst php_unit_test_class_requires_covers]</code> fixer.


== Stash ==
== Stash ==
I'm just writing this because my IDE crashed and I need to stash it.
I'm just writing this because my IDE crashed and I need to stash it.