-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for defining hook methods with both attribute and annotation without getting a deprecation #5695
Comments
Note that the proposal might involve backporting it to PHPunit 10.x as well to avoid getting double registration of hook methods there, in case this is the result of having both the attribute and the annotation (I haven't tried this yet) |
PHPUnit 10 supports metadata in annotations and attributes. If an attribute is found on a unit of code, annotations on that unit of code are ignored. Now PHPUnit 11 deprecated support for annotations, but still supports them in the same way PHPUnit 10 does. PHPUnit 12 will no longer support metadata in annotation, which means that all code related to parsing annotations can be removed. I do not think the additional complexity that would be required to not emit the deprecation for an annotation when the respective attribute is also present is worth it. I am sorry, but you will need different versions of a package such as prophecy-phpunit for different major versions of PHPUnit. |
FYI:
<?php declare(strict_types=1);
use PHPUnit\Framework\Attributes\Before;
use PHPUnit\Framework\TestCase;
final class ExampleTest extends TestCase
{
/**
* @before
*/
#[Before]
protected function beforeMethod(): void
{
}
public function testOne(): void
{
$this->assertTrue(true);
}
}
When both |
great. this is exactly the behavior I was hoping for. |
It's also exactly the behavior I wanted when I implemented this :-) I'm sorry for not immediately understanding what you were asking for. I'm all the more happy that what you were asking for was already there. |
For packages wanting to support multiple major versions of PHPUnit (from 9 to latest in the case of prophecy-phpunit), it would be great to be able to define hook methods in a way supported in all versions without getting deprecations. See phpspec/prophecy-phpunit#60 for the discussion.
My suggestion would be supporting to define both the attribute and the annotation on the test method. Such cases should ignore the annotation entirely (making the corresponding attribute provide the configuration) without reporting a deprecation in PHPUnit 11 about the annotation being deprecated.
What do you think about this proposal ?
The text was updated successfully, but these errors were encountered: