PHPUnit: Difference between revisions
No edit summary |
m tagged |
||
| (11 intermediate revisions by 2 users not shown) | |||
| Line 1: | Line 1: | ||
'''PHPUnit 11''' is the one which is still receiving support and bug fixes in 2025 | |||
The new<ref>PHPUnit 10 was released in Feb 2023 | |||
PHPUnit 11 was released in Feb 2024 | |||
https://phpunit.de/supported-versions.html</ref> '''PHPUnit 10''' is full of new features and changes. See the [https://github.com/sebastianbergmann/phpunit/blob/10.0.0/ChangeLog-10.0.md#1000---2023-02-03 CHANGELOG] and also the overview [https://phpunit.de/announcements/phpunit-10.html Release Announcement] The videos below go into more depth. | |||
{{#ev:youtube|https://www.youtube.com/watch?v=TVHDYpYxBHQ}} | {{#ev:youtube|https://www.youtube.com/watch?v=TVHDYpYxBHQ}} | ||
| Line 7: | Line 16: | ||
[https://2023.phpday.it/ phpday 2023] happened in Verona, Italy on 18th and 19th May 2023 | [https://2023.phpday.it/ phpday 2023] happened in Verona, Italy on 18th and 19th May 2023 | ||
== Event based == | |||
PHPUnit 10 takes a whole new approach by using an event system - which replaces the old (bad) Listener and Hook system. You can read about it at https://github.com/sebastianbergmann/phpunit/issues/4676 | |||
{{#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. | ||
| Line 63: | Line 84: | ||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
{{Subpages|}} | |||
{{References}} | |||
[[Category:Testing]] | [[Category:Testing]] | ||
[[Category:QA]] | [[Category:QA]] | ||
[[Category:Wiki]] | |||
[[Category:MediaWiki]] | |||
[[Category:Development]] | |||
[[Category:Static Analysis]] | |||
[[Category:Tools]] | |||
[[Category:Continuous Integration]] | |||
[[Category:PHP]] | |||