This repository has been archived by the owner on Nov 19, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
PHP 8 attributes #40
Comments
Note: |
diff --git a/src/main/php/unittest/TestGroup.class.php b/src/main/php/unittest/TestGroup.class.php
index 8606b05..d528771 100755
--- a/src/main/php/unittest/TestGroup.class.php
+++ b/src/main/php/unittest/TestGroup.class.php
@@ -18,15 +18,24 @@ abstract class TestGroup {
* @return iterable
*/
protected function actionsFor($annotated, $kind) {
- if (null === ($annotation= $annotated->annotation('action'))) return;
- $action= $annotation->argument(0);
- if (is_array($action)) {
- foreach ($action as $a) {
- if ($a instanceof $kind) yield $a;
+ // XP: [@action(new RuntimeVersion(...))]
+ if ($annotation= $annotated->annotation(Action::class)) {
+ $action= $annotation->argument(0);
+ if (is_array($action)) {
+ foreach ($action as $a) {
+ if ($a instanceof $kind) yield $a;
+ }
+ } else {
+ if ($action instanceof $kind) yield $action;
+ }
+ }
+
+ // PHP: [RuntimeVersion(<const>), VerifyThat(eval: '<expr>')]
+ foreach ($annotated->annotations() as $type => $annotation) {
+ if ($annotation->is($kind)) {
+ yield Reflect::of($type)->newInstance(...$annotation->arguments());
}
- } else {
- if ($action instanceof $kind) yield $action;
}
} |
thekid
added a commit
that referenced
this issue
Dec 12, 2020
thekid
added a commit
that referenced
this issue
Dec 13, 2020
Will be fully implemented in https://github.com/xp-framework/test |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
With the introduction of attributes in PHP 8, XP annotations can be changed over to PHP attributes. Aiding this transition will be the introduction of a new library for reflection (see xp-framework/rfc#336), which will work with both PHP 7 and PHP 8 (given that we don't use multiline attributes nor attributes on the same line as the values they're decoration, both of which will cause parsing errors). However, the new syntax also offers a couple of possibilities we can take advantage of.
#[@test]
#[Test]
#[@before]
#[Before]
#[@after]
#[After]
#[@beforeClass]
#[BeforeClass]
#[@afterClass]
#[AfterClass]
#[@ignore('Reason')]
#[Ignore('Reason')]
#[@expect(Throwable::class)]
#[Expect(Throwable::class)]
#[@expect(['class' => E::class])]
#[Expect(class: E::class)]
#[@limit(['time' => 1)]
#[Limit(time: 1)]
#[@values('provider')]
#[Values('provider')]]
#[@values([1, 2, 3])]
#[Values([1, 2, 3])]]
#[@values([self::$TYPE])]
#[Values(eval: '[self::$TYPE]')]]
#[@action(new Version('>=7.0'))]
#[Version('>=7.0')]
The text was updated successfully, but these errors were encountered: