1
1
<?php namespace lang \ast \unittest \emit ;
2
2
3
3
use lang \IllegalArgumentException ;
4
- use unittest \{Assert , Expect , Test , Values };
4
+ use unittest \{Assert , Test , Values };
5
5
6
6
/**
7
7
* Initialize parameters and properties with arbitrary expressions
8
8
*
9
9
* @see https://github.com/xp-framework/compiler/pull/104
10
10
* @see https://wiki.php.net/rfc/new_in_initializers
11
+ * @see https://wiki.php.net/rfc/calls_in_constant_expressions
11
12
*/
12
13
class InitializeWithExpressionsTest extends EmittingTest {
13
14
14
15
/** @return iterable */
15
16
private function expressions () {
16
17
yield ['"test" ' , 'test ' ];
17
18
yield ['[1, 2, 3] ' , [1 , 2 , 3 ]];
19
+ yield ['1 << 2 ' , 1 << 2 ];
20
+ yield ['strlen("Test") ' , strlen ('Test ' )];
18
21
yield ['MODIFIER_PUBLIC ' , MODIFIER_PUBLIC ];
19
22
yield ['self::INITIAL ' , 'initial ' ];
20
23
yield ['Handle::$DEFAULT ' , Handle::$ DEFAULT ];
@@ -34,6 +37,18 @@ public function run() {
34
37
} ' , $ code )));
35
38
}
36
39
40
+ #[Test]
41
+ public function using_functions () {
42
+ $ r = $ this ->run ('class <T> {
43
+ private $h= fn($arg) => $arg->redirect(1);
44
+
45
+ public function run() {
46
+ return $this->h;
47
+ }
48
+ } ' );
49
+ Assert::equals (new Handle (1 ), $ r (new Handle (0 )));
50
+ }
51
+
37
52
#[Test]
38
53
public function property_initialization_accessible_inside_constructor () {
39
54
$ r = $ this ->run ('use lang\ast\unittest\emit\Handle; class <T> {
0 commit comments