Photo by Luca Bravo on Unsplash
Metadata found in doc-comment Metadata in doc-comments is deprecated and will no longer be supported in PHPUnit 12.
After updating the PHPUnit package, the message Metadata found in doc-comment Metadata in doc-comments is deprecated and will no longer be supported in PHPUnit 12.
kept appearing. Although the tests still ran successfully, seeing these messages was somewhat annoying.
PHPUnit 11.2.1 by Sebastian Bergmann and contributors.
Runtime: PHP 8.2.20
Configuration: /var/www/html/kj_app/phpunit.xml
. 1 / 1 (100%)
Time: 00:00.522, Memory: 32.00 MB
There was 1 PHPUnit test runner deprecation:
1) Metadata found in doc-comment for method \Scenario\Feature\FeatureScenarioTest::test_user_sign_up(). Metadata in doc-comments is deprecated and will no longer be supported in PHPUnit 12. Update your test code to use attributes instead.
OK, but there were issues!
Tests: 1, Assertions: 1, Deprecations: 1.
Original Issue
The message did not specify which part had the problem, only that PHPUnit 12
would not support it in the future. The issue lies in the PHPUnit
settings written in the comments, which will no longer be supported. My original test code that caused the error looked like this:
/**
* @group scenario_user
* @group test_group_3
*/
public function test_user_sign_up(){
}
Solution
No need to prefix function names with test anymore
// Before
public function test_user_sign_up(){
}
Instead, use an attribute object Test
as an annotation before the function. This way, each function does not need to start with the test_
prefix.
use PHPUnit\Framework\Attributes\Test;
// Aftesr
#[Test]
public function user_sign_up(){
}
Grouping using the Group attribute
// Before
/**
* @group scenario_user
* @group test_group_3
*/
public function test_user_sign_up(){
}
Use the Group
attribute and pass your group names as parameters.
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\Attributes\Group;
// Aftesr
#[Group('scenario_user')]
#[Group('test_group_3')]
#[Test]
public function user_sign_up(){
}
This resolves the issue of PHPUnit
repeatedly showing warning messages and prevents potential problems when upgrading to PHPUnit 12
in the future.
Reference
Donate KJ 贊助作者喝咖啡
如果這篇文章對你有幫助的話,可以透過下面支付方式贊助作者喝咖啡,如果有什麼建議或想說的話可以贊助並留言給我
If this article has been helpful to you, you can support the author by treating them to a coffee through the payment options below. If you have any suggestions or comments, feel free to sponsor and leave a message for me!
方式 Method | 贊助 Donate |
PayPal | https://paypal.me/kejyun |
綠界 ECPay | https://p.ecpay.com.tw/AC218F1 |
歐付寶 OPay | https://payment.opay.tw/Broadcaster/Donate/BD2BD896029F2155041C8C8FAED3A6F8 |