@@ -320,7 +320,7 @@ public function un_annotated_parameter_annotations_are_empty() {
320
320
$ this ->assertEquals ([], $ this ->method ('public function fixture($param) { } ' )->getParameter (0 )->getAnnotations ());
321
321
}
322
322
323
- #[Test, Expect([ ' class ' => ElementNotFoundException::class, ' withMessage ' => 'Annotation "test" does not exist ' ] )]
323
+ #[Test, Expect(class: ElementNotFoundException::class, withMessage: 'Annotation "test" does not exist ' )]
324
324
public function cannot_get_test_annotation_for_un_annotated_parameter () {
325
325
$ this ->method ('public function fixture($param) { } ' )->getParameter (0 )->getAnnotation ('test ' );
326
326
}
@@ -335,7 +335,7 @@ public function optional_parameter() {
335
335
$ this ->assertTrue ($ this ->method ('public function fixture($param= true) { } ' )->getParameter (0 )->isOptional ());
336
336
}
337
337
338
- #[Test, Expect([ ' class ' => IllegalStateException::class, ' withMessage ' => 'Parameter "param" has no default value ' ] )]
338
+ #[Test, Expect(class: IllegalStateException::class, withMessage: 'Parameter "param" has no default value ' )]
339
339
public function required_parameter_does_not_have_default_value () {
340
340
$ this ->method ('public function fixture($param) { } ' )->getParameter (0 )->getDefaultValue ();
341
341
}
@@ -345,6 +345,19 @@ public function optional_parameters_default_value() {
345
345
$ this ->assertEquals (true , $ this ->method ('public function fixture($param= true) { } ' )->getParameter (0 )->getDefaultValue ());
346
346
}
347
347
348
+ #[Test]
349
+ public function default_annotation_may_supply_default_value () {
350
+ $ method = $ this ->method ('public function fixture($param= null) { } ' );
351
+
352
+ // Directly modify meta information for this test's purpose
353
+ // See https://github.com/xp-framework/compiler/pull/104#issuecomment-791924395
354
+ \xp::$ meta [$ method ->getDeclaringClass ()->getName ()][1 ][$ method ->getName ()]= [
355
+ DETAIL_TARGET_ANNO => ['$param ' => ['default ' => $ this ]]
356
+ ];
357
+
358
+ $ this ->assertEquals ($ this , $ method ->getParameter (0 )->getDefaultValue ());
359
+ }
360
+
348
361
#[Test]
349
362
public function vararg_parameters_default_value () {
350
363
$ this ->assertEquals (null , $ this ->method ('public function fixture(... $param) { } ' )->getParameter (0 )->getDefaultValue ());
0 commit comments