-
-
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 PHP 8 attributes for adding metadata to test classes and test methods as well as tested code units #4502
Comments
sebastianbergmann
added
the
type/enhancement
A new idea that should be implemented
label
Oct 30, 2020
sebastianbergmann
added a commit
that referenced
this issue
Oct 30, 2020
sebastianbergmann
added a commit
that referenced
this issue
Nov 3, 2020
sebastianbergmann
added a commit
that referenced
this issue
Nov 7, 2020
sebastianbergmann
added a commit
that referenced
this issue
Nov 9, 2020
sebastianbergmann
added a commit
that referenced
this issue
Nov 16, 2020
sebastianbergmann
added a commit
that referenced
this issue
Nov 16, 2020
This reverts commit 212f9e1.
sebastianbergmann
added a commit
that referenced
this issue
Dec 5, 2020
This reverts commit 212f9e1.
sebastianbergmann
added a commit
that referenced
this issue
Dec 21, 2020
This reverts commit 212f9e1.
sebastianbergmann
added a commit
that referenced
this issue
Dec 21, 2020
This reverts commit 212f9e1.
sebastianbergmann
added a commit
that referenced
this issue
Dec 22, 2020
This reverts commit 212f9e1.
sebastianbergmann
added a commit
that referenced
this issue
Dec 22, 2020
This reverts commit 212f9e1.
sebastianbergmann
added a commit
that referenced
this issue
Dec 26, 2020
This reverts commit 212f9e1.
sebastianbergmann
added a commit
that referenced
this issue
Dec 26, 2020
This reverts commit 212f9e1.
sebastianbergmann
added a commit
that referenced
this issue
Dec 28, 2020
This reverts commit 212f9e1.
sebastianbergmann
added a commit
that referenced
this issue
Dec 30, 2020
This reverts commit 212f9e1.
sebastianbergmann
added a commit
that referenced
this issue
Jan 1, 2021
This reverts commit 212f9e1.
sebastianbergmann
added a commit
that referenced
this issue
Jan 2, 2021
This reverts commit 212f9e1.
sebastianbergmann
added a commit
that referenced
this issue
Jan 3, 2021
This reverts commit 212f9e1.
sebastianbergmann
added a commit
that referenced
this issue
Jan 22, 2021
This reverts commit 212f9e1.
sebastianbergmann
added a commit
that referenced
this issue
Jan 23, 2021
This reverts commit 212f9e1.
sebastianbergmann
added a commit
that referenced
this issue
Jan 23, 2021
This reverts commit 212f9e1.
sebastianbergmann
added a commit
that referenced
this issue
Jan 24, 2021
This reverts commit 212f9e1.
sebastianbergmann
added a commit
that referenced
this issue
Feb 6, 2021
This reverts commit 212f9e1.
sebastianbergmann
added a commit
that referenced
this issue
Mar 28, 2021
This reverts commit 212f9e1.
sebastianbergmann
added a commit
that referenced
this issue
Apr 20, 2021
This reverts commit 212f9e1.
sebastianbergmann
added a commit
that referenced
this issue
Apr 24, 2021
This reverts commit 212f9e1.
This was referenced Jun 3, 2021
This was referenced Aug 18, 2021
5 tasks
This was referenced Dec 8, 2022
brettmc
added a commit
to brettmc/phpunit-global-state
that referenced
this issue
May 2, 2024
PHPUnit 11 emits a deprecation warning when using annotations (@after), and they will not work in PHPUnit 12. Changing this means that the "after" functionality will not work in phpunit versions < 10, but it also should not cause an error. Users directly calling "restoreEnvironmentVariables()" would be fine, I think. See sebastianbergmann/phpunit#4502
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
PHPUnit currently supports the following annotations in special PHP comments ("DocBlocks", "doc-comments"):
@after
@afterClass
@backupGlobals enabled
and@backupGlobals disabled
@backupStaticAttributes enabled
and@backupStaticAttributes disabled
@before
@beforeClass
@codeCoverageIgnore
@covers ::functionName
@covers ClassName
@covers ClassName::methodName
(not recommended because too fine-grained)@covers ClassName<extended>
(deprecated; will be removed in PHPUnit 10)@covers ClassName::<public>
(deprecated; will be removed in PHPUnit 10)@covers ClassName::<protected>
(deprecated; will be removed in PHPUnit 10)@covers ClassName::<private>
(deprecated; will be removed in PHPUnit 10)@covers ClassName::<!public>
(deprecated; will be removed in PHPUnit 10)@covers ClassName::<!protected>
(deprecated; will be removed in PHPUnit 10)@covers ClassName::<!private>
(deprecated; will be removed in PHPUnit 10)@coversDefaultClass ClassName
@coversNothing
@dataProvider methodName
@dataProvider ClassName::methodName
@depends methodName
@depends clone methodName
@depends shallowClone methodName
@depends ClassName::methodName
@depends clone ClassName::methodName
@depends !clone ClassName::methodName
@depends shallowClone ClassName::methodName
@depends !shallowClone ClassName::methodName
@depends ClassName::class
@depends clone ClassName::class
@depends !clone ClassName::class
@depends shallowClone ClassName::class
@depends !shallowClone ClassName::class
@doesNotPerformAssertions
@group string
@small
(as alias for@group small
)@medium
(as alias for@group medium
)@large
(as alias for@group large
)@author string
(as alias for@group <string>
)@ticket string
(as alias for@group <string>
)@preCondition
@postCondition
@preserveGlobalState enabled
and@preserveGlobalState disabled
@requires PHPUnit <version requirement>
@requires PHP <version requirement>
@requires extension <extension> <version requirement>
(where<version requirement>
is optional)@requires function <function>
(where<function>
is passed tofunction_exists()
)@requires function <class>::<method>
(where<class>
and<method>
are passed tomethod_exists()
)@requires setting <setting> <value>
(where<setting>
is a configuration setting that can be queried withini_set()
for comparison with<value>
)@requires OS <os>
(where<os>
is a regular expression that is applied toPHP_OS
)@requires OSFAMILY <family>
(where<family>
is compared toPHP_OS_FAMILY
)@runTestsInSeparateProcesses
@runInSeparateProcess
@test
@testdox string
@testWith string
@uses ::functionName
@uses ClassName
@uses ClassName::methodName
(not recommended because too fine-grained)PHP 8 introduced attributes as
Support for attributes in PHPUnit will be implemented like so:
The following annotations will not be implemented as attributes:
@author string
(as alias for@group <string>
) because it always only had questionable value@coversDefaultClass ClassName
because the workaround it provides is no longer needed as attributes are real syntaxFurthermore, any annotation listed above that is deprecated or not recommended will not be implemented as attributes.
Let us start simple with attributes that do not need parameters:
@after
will be implemented asPHPUnit\Framework\Attributes\After
(only allowed on methods;@after
was allowed on classes but did not have an effect there)@afterClass
will be implemented asPHPUnit\Framework\Attributes\AfterClass
(only allowed on methods;@afterClass
was allowed on classes but did not have an effect there)@before
will be implemented asPHPUnit\Framework\Attributes\Before
(only allowed on methods;@before
was allowed on classes but did not have an effect there)@beforeClass
will be implemented asPHPUnit\Framework\Attributes\BeforeClass
(only allowed on methods;@beforeClass
was allowed on classes but did not have an effect there)@codeCoverageIgnore
will be implemented asPHPUnit\Framework\Attributes\CodeCoverageIgnore
(allowed on classes and methods)@coversNothing
will be implemented asPHPUnit\Framework\Attributes\CoversNothing
(allowed on classes and methods)@doesNotPerformAssertions
will be implemented asPHPUnit\Framework\Attributes\DoesNotPerformAssertions
(allowed on classes and methods)@runTestsInSeparateProcesses
will be implemented asPHPUnit\Framework\Attributes\RunTestsInSeparateProcesses
(only allowed on classes;@runTestsInSeparateProcesses
was allowed on methods but did not have an effect there)@runInSeparateProcess
will be implemented asPHPUnit\Framework\Attributes\RunInSeparateProcess
(only allowed on methods;@runInSeparateProcess
was allowed on classes but did not have an effect there)@test
will be implemented asPHPUnit\Framework\Attributes\Test
(only allowed on methods;@test
was allowed on classes but did not have an effect there)@small
will be implemented asPHPUnit\Framework\Attributes\Small
(only allowed on classes;@small
was allowed on methods but it does not make sense to mix tests of different sizes in a test case class)@medium
will be implemented asPHPUnit\Framework\Attributes\Medium
(only allowed on classes;@medium
was allowed on methods but it does not make sense to mix tests of different sizes in a test case class)@large
will be implemented asPHPUnit\Framework\Attributes\Large
(only allowed on classes;@large
was allowed on methods but it does not make sense to mix tests of different sizes in a test case class)@preCondition
will be implemented asPHPUnit\Framework\Attributes\PreCondition
(only allowed on methods;@preCondition
was allowed on classes but did not have an effect there)@postCondition
will be implemented asPHPUnit\Framework\Attributes\PostCondition
(only allowed on methods;@postCondition
was allowed on classes but did not have an effect there)Here is an example:
And now for the attributes that need parameters:
@backupGlobals enabled
will be implemented asPHPUnit\Framework\Attributes\BackupGlobals(true)
(allowed on classes and methods)@backupGlobals disabled
will be implemented asPHPUnit\Framework\Attributes\BackupGlobals(false)
(allowed on classes and methods)@backupStaticAttributes enabled
will be implemented asPHPUnit\Framework\Attributes\BackupStaticProperties(true)
(allowed on classes and methods)@backupStaticAttributes disabled
will be implemented asPHPUnit\Framework\Attributes\BackupStaticProperties(false)
(allowed on classes and methods)@covers ClassName
will be implemented asPHPUnit\Framework\Attributes\CoversClass(string $className)
(only allowed on classes;@covers
was allowed on methods but it does not make sense to mix different coverage targets in a test case class)@covers ::functionName
will be implemented asPHPUnit\Framework\Attributes\CoversFunction(string $functionName)
(only allowed on classes;@covers
was allowed on methods but it does not make sense to mix different coverage targets in a test case class)@dataProvider methodName
will be implemented asPHPUnit\Framework\Attributes\DataProvider(string $methodName)
(only allowed on methods;@dataProvider
was allowed on classes but did not have an effect there)@dataProvider ClassName::methodName
will be implemented asPHPUnit\Framework\Attributes\DataProviderExternal(string $className, string $methodName)
(only allowed on methods;@dataProvider
was allowed on classes but did not have an effect there)@depends methodName
will be implemented asPHPUnit\Framework\Attributes\Depends(string $methodName)
(allowed on methods)@depends clone methodName
will be implemented asPHPUnit\Framework\Attributes\DependsUsingDeepClone(string $methodName)
(allowed on methods)@depends shallowClone methodName
will be implemented asPHPUnit\Framework\Attributes\DependsUsingShallowClone(string $methodName)
(allowed on methods)@depends ClassName::methodName
will be implemented asPHPUnit\Framework\Attributes\DependsExternal(string $className, string $methodName)
(allowed on methods)@depends clone ClassName::methodName
will be implemented asPHPUnit\Framework\Attributes\DependsExternalUsingDeepClone(string $className, string $methodName)
(allowed on methods)@depends shallowClone ClassName::methodName
will be implemented asPHPUnit\Framework\Attributes\DependsExternalUsingShallowClone(string $className, string $methodName)
(allowed on methods)@depends ClassName::class
will be implemented asPHPUnit\Framework\Attributes\DependsOnClass(string $className)
(allowed on methods)@depends clone ClassName::class
will be implemented asPHPUnit\Framework\Attributes\DependsOnClassUsingDeepClone(string $className)
(allowed on methods)@depends shallowClone ClassName::class
will be implemented asPHPUnit\Framework\Attributes\DependsOnClassUsingShallowClone(string $className)
(allowed on methods)@group string
will be implemented asPHPUnit\Framework\Attributes\Group(string)
(allowed on classes and methods)@preserveGlobalState enabled
will be implemented asPHPUnit\Framework\Attributes\PreserveGlobalState(true)
(allowed on classes and methods)@preserveGlobalState disabled
will be implemented asPHPUnit\Framework\Attributes\PreserveGlobalState(false)
(allowed on classes and methods)@requires PHP <version requirement>
will be implemented asPHPUnit\Framework\Attributes\RequiresPhp(string $versionRequirement)
(allowed on classes and methods)@requires extension <extension> <operator> <version requirement>
will be implemented asPHPUnit\Framework\Attributes\RequiresPhpExtension(string $extension, ?string $versionRequirement = null)
(allowed on classes and methods)@requires function <function>
will be implemented asPHPUnit\Framework\Attributes\RequiresFunction(string $function)
(allowed on classes and methods)@requires function<class>::<method>
will be implemented asPHPUnit\Framework\Attributes\RequiresMethod(string $className, string $methodName)
(allowed on classes and methods)@requires PHPUnit <version requirement>
will be implemented asPHPUnit\Framework\Attributes\RequiresPhpunit(string $versionRequirement)
(allowed on classes and methods)@requires OS <os>
will be implemented asPHPUnit\Framework\Attributes\RequiresOperatingSystem(string $regularExpression)
(allowed on classes and methods)@requires OSFAMILY <family>
will be implemented asPHPUnit\Framework\Attributes\RequiresOperatingSystemFamily(string $operatingSystemFamily)
(allowed on classes and methods)@requires setting <setting> <value>
will be implemented asPHPUnit\Framework\Attributes\RequiresSetting(string $setting, string $value)
(allowed on classes and methods)@testdox string
will be implemented asPHPUnit\Framework\Attributes\TestDox(string)
(allowed on classes and methods)@testWith string
will be implemented asPHPUnit\Framework\Attributes\TestWith(array)
(only allowed on methods;@testWith
was allowed on classes but did not have an effect there)@ticket string
will be implemented asPHPUnit\Framework\Attributes\Ticket(string)
(allowed on classes and methods)@uses ClassName
will be implemented asPHPUnit\Framework\Attributes\UsesClass(string)
(only allowed on classes;@uses
was allowed on methods but it does not make sense to mix different coverage targets in a test case class)@uses ::functionName
will be implemented asPHPUnit\Framework\Attributes\UsesFunction(string)
(only allowed on classes;@uses
was allowed on methods but it does not make sense to mix different coverage targets in a test case class)Here is an example:
The text was updated successfully, but these errors were encountered: