Skip to content

Commit a32e859

Browse files
committed
Add HigherOrderTapProxy
1 parent 5575db8 commit a32e859

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

src/HigherOrderTapProxy.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,14 @@ public function __construct($target)
2525
/**
2626
* Dynamically pass method calls to the target.
2727
*
28-
* @param callable $callback
28+
* @param string $method
29+
* @param array $parameters
2930
* @return mixed
3031
*/
31-
public function __invoke($callback)
32+
public function __call($method, $parameters)
3233
{
33-
return $callback($this->target);
34+
$this->target->{$method}(...$parameters);
35+
36+
return $this->target;
3437
}
3538
}

tests/HigherOrderTapProxyTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
use Farzai\Support\HigherOrderTapProxy;
4+
5+
it('calls the method on the target', function () {
6+
$target = new class {
7+
public $called = false;
8+
9+
public function foo()
10+
{
11+
$this->called = true;
12+
}
13+
};
14+
15+
$proxy = new HigherOrderTapProxy($target);
16+
17+
$proxy->foo();
18+
19+
expect($target->called)->toBeTrue();
20+
});

0 commit comments

Comments
 (0)