ray-di /
Ray.TestDouble
| 1 | <?php |
||
| 2 | |||
| 3 | declare(strict_types=1); |
||
| 4 | |||
| 5 | namespace Ray\TestDouble; |
||
| 6 | |||
| 7 | use Ray\Aop\Bind; |
||
| 8 | use Ray\Aop\Weaver; |
||
| 9 | |||
| 10 | use function sys_get_temp_dir; |
||
| 11 | |||
| 12 | final class Spy |
||
| 13 | { |
||
| 14 | private string $tmpDir; |
||
| 15 | |||
| 16 | public function __construct(string|null $tmpDir = null) |
||
| 17 | { |
||
| 18 | $this->tmpDir = $tmpDir ?? sys_get_temp_dir(); |
||
| 19 | } |
||
| 20 | |||
| 21 | /** |
||
| 22 | * @param class-string<T> $class |
||
|
0 ignored issues
–
show
Documentation
Bug
introduced
by
Loading history...
|
|||
| 23 | * |
||
| 24 | * @return T |
||
| 25 | * |
||
| 26 | * @template T of object |
||
| 27 | */ |
||
| 28 | public function newInstance(string $class, string $method, Logger $spyLog): object |
||
| 29 | { |
||
| 30 | $bind = (new Bind())->bindInterceptors($method, [new SpyInterceptor($spyLog)]); |
||
| 31 | $compiler = new Weaver($bind, $this->tmpDir); |
||
| 32 | |||
| 33 | return $compiler->newInstance($class, []); |
||
| 34 | } |
||
| 35 | } |
||
| 36 |