Closed thekid closed 1 year ago
Note: fn
expressions inside eval arguments will be rewritten to function() { ... }
in order to work with all PHP 7 versions.
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;
}
}
Will be fully implemented in https://github.com/xp-framework/test
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')]