/
ParamInjectorTest.php
45 lines (37 loc) · 1.39 KB
/
ParamInjectorTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php
declare(strict_types=1);
namespace Ray\MediaQuery;
use DateTimeImmutable;
use DateTimeInterface;
use PHPUnit\Framework\TestCase;
use Ray\Aop\ReflectiveMethodInvocation;
use Ray\Di\AbstractModule;
use Ray\Di\Injector;
class ParamInjectorTest extends TestCase
{
private ParamInjector $injector;
protected function setUp(): void
{
$this->injector = new ParamInjector(new Injector(new class extends AbstractModule{
protected function configure(): void
{
$this->bind(DateTimeInterface::class)->toInstance(new DateTimeImmutable('1989-9-1'));
}
}));
}
public function testNoInjection(): void
{
$namedArgs = $this->injector->getArgumentes(new ReflectiveMethodInvocation(new FakeParamInjectMethod(), 'noInject', [1]));
$this->assertSame(['a' => 1], $namedArgs);
}
public function testGetArgumentes(): void
{
$namedArgs = $this->injector->getArgumentes(new ReflectiveMethodInvocation(new FakeParamInjectMethod(), 'paramInject', [null]));
$this->assertInstanceOf(DateTimeImmutable::class, $namedArgs['dateTime']);
}
public function testDefaultValue(): void
{
$namedArgs = $this->injector->getArgumentes(new ReflectiveMethodInvocation(new FakeParamInjectMethod(), 'defaultValue', []));
$this->assertSame(['int' => 1, 'bool' => true], $namedArgs);
}
}