1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Fesor\RequestObject\Tests\DependencyInjection; |
4
|
|
|
|
5
|
|
|
use Fesor\RequestObject\DependeyInjection\CollectMappersCompilePass; |
6
|
|
|
use Fesor\RequestObject\DependeyInjection\RequestObjectExtension; |
7
|
|
|
use Fesor\RequestObject\Tests\Fixtures\ExampleRequestMapper; |
8
|
|
|
use Fesor\RequestObject\Tests\Fixtures\ExampleRequestObject; |
9
|
|
|
use PHPUnit\Framework\TestCase; |
10
|
|
|
use Prophecy\Argument; |
11
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
12
|
|
|
use Symfony\Component\DependencyInjection\Definition; |
13
|
|
|
use Symfony\Component\HttpFoundation\Request; |
14
|
|
|
|
15
|
|
|
class CollectMappersCompilePassTest extends TestCase |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* @var CollectMappersCompilePass |
19
|
|
|
*/ |
20
|
|
|
private $compilePass; |
21
|
|
|
private $containerMock; |
22
|
|
|
private $definitionMock; |
23
|
|
|
|
24
|
|
|
protected function setUp() |
25
|
|
|
{ |
26
|
|
|
$this->containerMock = $this->prophesize(ContainerBuilder::class); |
27
|
|
|
$this->definitionMock = $this->prophesize(Definition::class); |
28
|
|
|
|
29
|
|
|
$this->containerMock |
30
|
|
|
->getDefinition(RequestObjectExtension::REQUEST_MAPPER_ID) |
31
|
|
|
->willReturn($this->definitionMock->reveal()); |
32
|
|
|
$this->compilePass = new CollectMappersCompilePass(); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function testRegisterBindings() |
36
|
|
|
{ |
37
|
|
|
$this->stubTaggedServices([ |
38
|
|
|
'test.mapper' => ExampleRequestMapper::class |
39
|
|
|
]); |
40
|
|
|
|
41
|
|
|
$this->expectBindings([ |
42
|
|
|
ExampleRequestObject::class => ['test.mapper', 'exampleMapper'], |
43
|
|
|
]); |
44
|
|
|
|
45
|
|
|
$this->compilePass->process($this->containerMock->reveal()); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
private function stubTaggedServices($services) |
49
|
|
|
{ |
50
|
|
|
$this->containerMock |
51
|
|
|
->findTaggedServiceIds(RequestObjectExtension::MAPPER_TAG) |
52
|
|
|
->willReturn(array_keys($services)) |
53
|
|
|
->shouldBeCalled(); |
54
|
|
|
|
55
|
|
|
foreach ($services as $id => $service) { |
56
|
|
|
|
57
|
|
|
$definition = new Definition($service); |
58
|
|
|
|
59
|
|
|
$this->containerMock |
60
|
|
|
->getDefinition($id) |
61
|
|
|
->willReturn($definition); |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
private function expectBindings(array $bindings) |
66
|
|
|
{ |
67
|
|
|
$this->definitionMock->addMethodCall('registerBindings', [$bindings])->shouldBeCalled(); |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|