Skip to content

Commit c247e5f

Browse files
committed
Test PFAs work with __invoke() and __call()
1 parent eef8baf commit c247e5f

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

src/test/php/lang/ast/unittest/emit/CallableSyntaxTest.class.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,39 @@ public function run() {
361361
Assert::equals('ok.', $f('test.'));
362362
}
363363

364+
#[Test]
365+
public function partial_function_application_invoke_interceptor() {
366+
$f= $this->run('use lang\ast\unittest\emit\Handle; class %T {
367+
public function run() {
368+
$add= new class() {
369+
public function __invoke(int $a, int $b) {
370+
return $a + $b;
371+
}
372+
};
373+
return $add(1, ?);
374+
}
375+
}');
376+
Assert::equals(3, $f(2));
377+
}
378+
379+
#[Test]
380+
public function partial_function_application_call_interceptor() {
381+
$f= $this->run('use lang\ast\unittest\emit\Handle; class %T {
382+
public function run() {
383+
$calc= new class() {
384+
public function __call($name, $args) {
385+
return match ($name) {
386+
"add" => array_sum($args),
387+
// TBI
388+
};
389+
}
390+
};
391+
return $calc->add(1, ...);
392+
}
393+
}');
394+
Assert::equals(6, $f(2, 3));
395+
}
396+
364397
#[Test, Runtime(php: '>=8.0.0')]
365398
public function partial_function_application_named_arguments_out_of_order() {
366399
$f= $this->run('class %T {

0 commit comments

Comments
 (0)